From: Ondřej Surý Date: Tue, 4 Dec 2018 12:51:59 +0000 (+0100) Subject: Make the start.pl and stop.pl more Cygwin friendly X-Git-Tag: v9.13.5~13^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=835bad2c5cf7f1b44bf4ab0c906320a675de6063;p=thirdparty%2Fbind9.git Make the start.pl and stop.pl more Cygwin friendly --- diff --git a/bin/tests/system/start.pl b/bin/tests/system/start.pl index 49a6665d2ff..30139c7ac39 100755 --- a/bin/tests/system/start.pl +++ b/bin/tests/system/start.pl @@ -193,7 +193,7 @@ sub start_server { # start the server my $child = `$command`; - $child =~ s/\s+$//; + chomp($child); # wait up to 14 seconds for the server to start and to write the # pid file otherwise kill this server and any others that have @@ -373,7 +373,7 @@ sub verify_ns_server { if (open(my $fh, "<", $runfile)) { # the two non-whitespace blobs should be the date and time # but we don't care about them really, only that they are there - if (grep /^\S+ \S+ running$/, <$fh>) { + if (grep /^\S+ \S+ running\R/, <$fh>) { last; } } diff --git a/bin/tests/system/stop.pl b/bin/tests/system/stop.pl index a0ebc95d7dd..a7ece3dc380 100644 --- a/bin/tests/system/stop.pl +++ b/bin/tests/system/stop.pl @@ -134,21 +134,20 @@ sub server_pid_file { # Read a PID. sub read_pid { - my ( $server ) = @_; - - my $pid_file = server_pid_file($server); + my ( $pid_file ) = @_; return unless -f $pid_file; - - local *FH; - my $result = open FH, "< $pid_file"; - if (!$result) { + # we don't really care about the race condition here + my $result = open(my $fh, "<", $pid_file); + if (!defined($result)) { print "I:$test:$pid_file: $!\n"; unlink $pid_file; return; } - my $pid = ; + my $pid = <$fh>; + return unless defined($pid); + chomp($pid); return $pid; } @@ -172,37 +171,72 @@ sub stop_rndc { return; } -# Stop a server by sending a signal to it. -sub stop_signal { - my($server, $signal) = @_; +sub server_died { + my ( $server, $signal ) = @_; - my $pid = read_pid($server); - return unless defined($pid); + print "I:$test:$server died before a SIG$signal was sent\n"; + $errors = 1; - my $result; my $pid_file = server_pid_file($server); + unlink($pid_file); + + return; +} + +sub send_signal { + my ( $signal, $pid ) = @_; + + my $result = 0; if ($^O eq 'cygwin') { - $result = !system("/bin/kill -f -$signal $pid"); + my $killout = `/bin/kill -f -$signal $pid 2>&1`; + chomp($killout); + $result = 1 if ($killout eq ''); } else { $result = kill $signal, $pid; } + return $result; +} - if (!$result) { - print "I:$test:$server died before a SIG$signal was sent\n"; - $errors = 1; - unlink $pid_file; +# Stop a server by sending a signal to it. +sub stop_signal { + my ( $server, $signal ) = @_; + + my $pid_file = server_pid_file($server); + my $pid = read_pid($pid_file); + + return unless defined($pid); + + # Send signal to the server, and bail out if signal can't be sent + if (send_signal($signal, $pid) != 1) { + server_died($server, $signal); + return; } return; } +sub clean_pid_file { + my ( $server ) = @_; + + my $pid_file = server_pid_file($server); + my $pid = read_pid($pid_file); + + return unless defined($pid); + + return if (send_signal(0, $pid) == 0); + + return $server; +} + sub wait_for_servers { - my($timeout, @servers) = @_; + my ( $timeout, @servers ) = @_; while ($timeout > 0 && @servers > 0) { - @servers = grep { -f server_pid_file($_) } @servers; sleep 1 if (@servers > 0); + @servers = + grep { defined($_) } + map { clean_pid_file($_) } @servers; $timeout--; }