selftest: Rework Samba3.pm process termination
authorAndrew Bartlett <abartlet@samba.org>
Sun, 4 Mar 2012 07:34:34 +0000 (18:34 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 4 Mar 2012 10:51:12 +0000 (11:51 +0100)
We now store the timelimit child PID in memory, and confirm that the child has exited
with both waitpid() and kill(0, $pid).

By calling Samba::cleanup_child() we get exit status information.

Andrew Bartlett

Autobuild-User: Andrew Bartlett <abartlet@samba.org>
Autobuild-Date: Sun Mar  4 11:51:12 CET 2012 on sn-devel-104

selftest/target/Samba3.pm

index a5ae8a1bb08e0e51123180b6c36f7e30833ef6f1..87763aadec119675ec705e590b9fcc009e4ad97d 100755 (executable)
@@ -48,19 +48,22 @@ sub teardown_env($$)
        # This should cause smbd to terminate gracefully
        close($envvars->{STDIN_PIPE});
 
-       my $smbdpid = read_pid($envvars, "smbd");
-       my $nmbdpid = read_pid($envvars, "nmbd");
-       my $winbinddpid = read_pid($envvars, "winbindd");
-
-       until (kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
-           my $childpid = waitpid(-1, WNOHANG);
-           # This should give it time to write out the gcov data
+       my $smbdpid = $envvars->{SMBD_TL_PID};
+       my $nmbdpid = $envvars->{NMBD_TL_PID};
+       my $winbinddpid = $envvars->{WINBINDD_TL_PID};
+
+       # This should give it time to write out the gcov data
+       until ($count > 20) {
+           if (Samba::cleanup_child($smbdpid, "smbd") == -1
+               && Samba::cleanup_child($nmbdpid, "nmbd") == -1
+               && Samba::cleanup_child($winbinddpid, "winbindd") == -1) {
+               last;
+           }
            sleep(1);
            $count++;
-           last if $childpid == -1 or $count > 20;
        }
 
-       if ($count <= 20) {
+       if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
            return;
        }
 
@@ -69,15 +72,17 @@ sub teardown_env($$)
        $self->stop_sig_term($winbinddpid);
 
        $count = 0;
-       until (kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
-           # if no process sucessfully signalled, then we are done
-           my $childpid = waitpid(-1, WNOHANG);
+       until ($count > 10) {
+           if (Samba::cleanup_child($smbdpid, "smbd") == -1
+               && Samba::cleanup_child($nmbdpid, "nmbd") == -1
+               && Samba::cleanup_child($winbinddpid, "winbindd") == -1) {
+               last;
+           }
            sleep(1);
            $count++;
-           last if $childpid == -1 or $count > 20;
        }
-       
-       if ($count <= 10) {
+
+       if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
            return;
        }
 
@@ -591,6 +596,7 @@ sub check_or_start($$$$$) {
 
                exec(@preargs, Samba::bindir_path($self, "nmbd"), "-F", "--no-process-group", "--log-stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
        }
+       $env_vars->{NMBD_TL_PID} = $pid;
        write_pid($env_vars, "nmbd", $pid);
        print "DONE\n";
 
@@ -642,6 +648,7 @@ sub check_or_start($$$$$) {
 
                exec(@preargs, Samba::bindir_path($self, "winbindd"), "-F", "--no-process-group", "--stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
        }
+       $env_vars->{WINBINDD_TL_PID} = $pid;
        write_pid($env_vars, "winbindd", $pid);
        print "DONE\n";
 
@@ -689,6 +696,7 @@ sub check_or_start($$$$$) {
 
                exec(@preargs, Samba::bindir_path($self, "smbd"), "-F", "--no-process-group", "--log-stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
        }
+       $env_vars->{SMBD_TL_PID} = $pid;
        write_pid($env_vars, "smbd", $pid);
        print "DONE\n";