selftest: Rework child process cleanup
authorAndrew Bartlett <abartlet@samba.org>
Wed, 30 Nov 2016 01:18:46 +0000 (14:18 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 1 Dec 2016 04:54:21 +0000 (05:54 +0100)
We now:
 - call gdb_backtrace on the stuck pid to determine why it is stuck
 - cleanup faster as we catch the process exit
   (by not waiting until 1 second after the exit for waitpid() to return -1)

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
selftest/target/Samba4.pm

index 40cca9451ec01af230ef9dc2ff35280d4d0ac044..caf46b26c86c1e6512678ce63fbbe4953909ac78 100755 (executable)
@@ -1879,7 +1879,7 @@ sub provision_chgdcpass($$)
        return $ret;
 }
 
-sub teardown_env($$)
+sub teardown_env_terminate($$)
 {
        my ($self, $envvars) = @_;
        my $pid;
@@ -1892,28 +1892,50 @@ sub teardown_env($$)
        my $childpid;
 
        # This should give it time to write out the gcov data
+       until ($count > 15) {
+           if (Samba::cleanup_child($pid, "samba") != 0) {
+               return;
+           }
+           sleep(1);
+           $count++;
+       }
+
+       # After 15 Seconds, work out why this thing is still alive
+       warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
+       system("$self->{srcdir}/selftest/gdb_backtrace $pid");
+
        until ($count > 30) {
-           if (Samba::cleanup_child($pid, "samba") == -1) {
-               last;
+           if (Samba::cleanup_child($pid, "samba") != 0) {
+               return;
            }
            sleep(1);
            $count++;
        }
 
-       if ($count > 30 || kill(0, $pid)) {
+       if (kill(0, $pid)) {
+           warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
            kill "TERM", $pid;
+       }
 
-           until ($count > 40) {
-               if (Samba::cleanup_child($pid, "samba") == -1) {
-                   last;
-               }
-               sleep(1);
-               $count++;
+       until ($count > 40) {
+           if (Samba::cleanup_child($pid, "samba") != 0) {
+               return;
            }
-           # If it is still around, kill it
-           warn "server process $pid took more than $count seconds to exit, killing\n";
+           sleep(1);
+           $count++;
+       }
+       # If it is still around, kill it
+       if (kill(0, $pid)) {
+           warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
            kill 9, $pid;
        }
+       return;
+}
+
+sub teardown_env($$)
+{
+       my ($self, $envvars) = @_;
+       teardown_env_terminate($self, $envvars);
 
        $self->slapd_stop($envvars) if ($self->{ldap});