summaryrefslogtreecommitdiff
path: root/selftest
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-03-02 18:20:45 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-03-02 12:30:05 +0100
commit5d4144a82674467bccbfe30f42382ed0905026d0 (patch)
tree963b9d0017112adb9f6f682435157f66ad8a5b4e /selftest
parent0d94d681c4a829b2a0bdadf5800c11c05edd2fa4 (diff)
downloadsamba-5d4144a82674467bccbfe30f42382ed0905026d0.tar.gz
samba-5d4144a82674467bccbfe30f42382ed0905026d0.tar.bz2
samba-5d4144a82674467bccbfe30f42382ed0905026d0.zip
selftest: close stdin and wait with waitpid() for a safer exit
This avoids timelimit sending kill -9 after 1 second, which may disrupt the writing of gcov data. Andrew Bartlett
Diffstat (limited to 'selftest')
-rwxr-xr-xselftest/target/Samba3.pm32
-rw-r--r--selftest/target/Samba4.pm6
2 files changed, 36 insertions, 2 deletions
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 0ea63db8c4..c9ad7d31fe 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -43,17 +43,45 @@ sub new($$) {
sub teardown_env($$)
{
my ($self, $envvars) = @_;
+ my $count = 0;
+
+ # 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
+ sleep(1);
+ $count++;
+ last if $childpid == 0 or $count > 20;
+ }
+
+ if ($count <= 20) {
+ return;
+ }
+
$self->stop_sig_term($smbdpid);
$self->stop_sig_term($nmbdpid);
$self->stop_sig_term($winbinddpid);
- sleep(2);
+ $count = 0;
+ until (kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
+ # if no process sucessfully signalled, then we are done
+ my $childpid = waitpid(-1, WNOHANG);
+ sleep(1);
+ $count++;
+ last if $childpid == 0 or $count > 20;
+ }
+
+ if ($count <= 10) {
+ return;
+ }
+ warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
$self->stop_sig_kill($smbdpid);
$self->stop_sig_kill($nmbdpid);
$self->stop_sig_kill($winbinddpid);
@@ -98,6 +126,8 @@ sub check_env($$)
{
my ($self, $envvars) = @_;
+ my $childpid = waitpid(-1, WNOHANG);
+
# TODO ...
return 1;
}
diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index 361152b928..b79e29fad6 100644
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -1363,10 +1363,12 @@ sub teardown_env($$)
my $count = 0;
until (kill(0, $pid) == 0) {
+ my $childpid = waitpid(-1, WNOHANG);
+
# This should give it time to write out the gcov data
sleep(1);
$count++;
- last if $count > 20;
+ last if $childpid == 0 or $count > 20;
}
# If it is still around, kill it
@@ -1409,6 +1411,8 @@ sub check_env($$)
{
my ($self, $envvars) = @_;
+ my $childpid = waitpid(-1, WNOHANG);
+
return (-p $envvars->{SAMBA_TEST_FIFO});
}