[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 164/264: tests: add Windows compatible pidwait like pidkill and
From: |
gnunet |
Subject: |
[gnurl] 164/264: tests: add Windows compatible pidwait like pidkill and pidterm |
Date: |
Thu, 30 Apr 2020 16:07:47 +0200 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 2a93021750b4979f32dd445c3366453c33390ea0
Author: Marc Hoersken <address@hidden>
AuthorDate: Fri Apr 10 21:25:55 2020 +0200
tests: add Windows compatible pidwait like pidkill and pidterm
Related to #5188
---
tests/ftp.pm | 40 +++++++++++++++++++++++++++++++---------
tests/ftpserver.pl | 2 +-
tests/runtests.pl | 2 +-
3 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/tests/ftp.pm b/tests/ftp.pm
index a29fad14f..971be199f 100644
--- a/tests/ftp.pm
+++ b/tests/ftp.pm
@@ -51,7 +51,7 @@ use pathhelp qw(
# to the classic approach of using select(undef, undef, undef, ...).
# even though that one is not portable due to being implemented using
# select on Windows: https://perldoc.perl.org/perlport.html#select
-# On Windows it also just uses full-second sleep for waits >1 second.
+# Therefore it uses Win32::Sleep on Windows systems instead.
#
sub portable_sleep {
my ($seconds) = @_;
@@ -143,7 +143,7 @@ sub pidterm {
}
#######################################################################
-# pidkill kills the process with a given pid mercilessly andforcefully.
+# pidkill kills the process with a given pid mercilessly and forcefully.
#
sub pidkill {
my $pid = $_[0];
@@ -169,6 +169,28 @@ sub pidkill {
}
}
+#######################################################################
+# pidwait waits for the process with a given pid to be terminated.
+#
+sub pidwait {
+ my $pid = $_[0];
+ my $flags = $_[1];
+
+ # check if the process exists
+ if ($pid > 65536 && os_is_win()) {
+ if($flags == &WNOHANG) {
+ return pidexists($pid)?0:$pid;
+ }
+ while(pidexists($pid)) {
+ portable_sleep(0.01);
+ }
+ return $pid;
+ }
+
+ # wait on the process to terminate
+ return waitpid($pid, $flags);
+}
+
#######################################################################
# processexists checks if a process with the pid stored in the given
# pidfile exists and is alive. This will return 0 on any file related
@@ -193,7 +215,7 @@ sub processexists {
# get rid of the certainly invalid pidfile
unlink($pidfile) if($pid == pidfromfile($pidfile));
# reap its dead children, if not done yet
- waitpid($pid, &WNOHANG);
+ pidwait($pid, &WNOHANG);
# negative return value means dead process
return -$pid;
}
@@ -243,7 +265,7 @@ sub killpid {
print("RUN: Process with pid $pid already dead\n")
if($verbose);
# if possible reap its dead children
- waitpid($pid, &WNOHANG);
+ pidwait($pid, &WNOHANG);
push @reapchild, $pid;
}
}
@@ -261,7 +283,7 @@ sub killpid {
if($verbose);
splice @signalled, $i, 1;
# if possible reap its dead children
- waitpid($pid, &WNOHANG);
+ pidwait($pid, &WNOHANG);
push @reapchild, $pid;
}
}
@@ -278,7 +300,7 @@ sub killpid {
if($verbose);
pidkill($pid);
# if possible reap its dead children
- waitpid($pid, &WNOHANG);
+ pidwait($pid, &WNOHANG);
push @reapchild, $pid;
}
}
@@ -288,7 +310,7 @@ sub killpid {
if(@reapchild) {
foreach my $pid (@reapchild) {
if($pid > 0) {
- waitpid($pid, 0);
+ pidwait($pid, 0);
}
}
}
@@ -317,7 +339,7 @@ sub killsockfilters {
printf("* kill pid for %s-%s => %d\n", $server,
($proto eq 'ftp')?'ctrl':'filt', $pid) if($verbose);
pidkill($pid);
- waitpid($pid, 0);
+ pidwait($pid, 0);
}
unlink($pidfile) if(-f $pidfile);
}
@@ -331,7 +353,7 @@ sub killsockfilters {
printf("* kill pid for %s-data => %d\n", $server,
$pid) if($verbose);
pidkill($pid);
- waitpid($pid, 0);
+ pidwait($pid, 0);
}
unlink($pidfile) if(-f $pidfile);
}
diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl
index 62e423b44..718920fd0 100755
--- a/tests/ftpserver.pl
+++ b/tests/ftpserver.pl
@@ -703,7 +703,7 @@ sub close_dataconn {
logmsg "DATA sockfilt for $datasockf_mode data channel quits ".
"(pid $datapid)\n";
print DWRITE "QUIT\n";
- waitpid($datapid, 0);
+ pidwait($datapid, 0);
unlink($datasockf_pidfile) if(-f $datasockf_pidfile);
logmsg "DATA sockfilt for $datasockf_mode data channel quit ".
"(pid $datapid)\n";
diff --git a/tests/runtests.pl b/tests/runtests.pl
index 36f39a7b7..6b1410e4d 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -441,7 +441,7 @@ sub checkdied {
if((not defined $pid) || $pid <= 0) {
return 0;
}
- my $rc = waitpid($pid, &WNOHANG);
+ my $rc = pidwait($pid, &WNOHANG);
return ($rc == $pid)?1:0;
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [gnurl] 236/264: gnutls: bump lowest supported version to 3.1.10, (continued)
- [gnurl] 236/264: gnutls: bump lowest supported version to 3.1.10, gnunet, 2020/04/30
- [gnurl] 137/264: configure: remove use of -vec-report0 from CFLAGS with icc, gnunet, 2020/04/30
- [gnurl] 117/264: sockfilt: fix handling of ready closed sockets on Windows, gnunet, 2020/04/30
- [gnurl] 124/264: KNOWN_BUGS: fixed "USE_UNIX_SOCKETS on Windows", gnunet, 2020/04/30
- [gnurl] 154/264: CI/macos: convert CRLF to LF and align indentation, gnunet, 2020/04/30
- [gnurl] 152/264: server/resolve: remove AI_CANONNAME to make macos tell the truth, gnunet, 2020/04/30
- [gnurl] 213/264: tests/FILEFORMAT: converted to markdown and extended, gnunet, 2020/04/30
- [gnurl] 259/264: doh: Constify some input pointers, gnunet, 2020/04/30
- [gnurl] 161/264: release-notes.pl: detect the start of the references in cleanup mode, gnunet, 2020/04/30
- [gnurl] 214/264: mime: properly check Content-Type even if it has parameters, gnunet, 2020/04/30
- [gnurl] 164/264: tests: add Windows compatible pidwait like pidkill and pidterm,
gnunet <=
- [gnurl] 166/264: tests/server/util.c: use curl_off_t instead of long for pid, gnunet, 2020/04/30
- [gnurl] 167/264: compressed.d: stress that the headers are not modified, gnunet, 2020/04/30
- [gnurl] 165/264: tests: use Cygwin/msys PIDs for stunnel and sshd on Windows, gnunet, 2020/04/30
- [gnurl] 264/264: make gnurl-aux, gnunet, 2020/04/30
- [gnurl] 177/264: cirrus: no longer ignore test 504 which is working again, gnunet, 2020/04/30
- [gnurl] 180/264: tool: do not declare functions with Curl_ prefix, gnunet, 2020/04/30
- [gnurl] 229/264: http: free memory when Alt-Used header creation fails due to OOM, gnunet, 2020/04/30
- [gnurl] 162/264: RELEASE-NOTES: synced, gnunet, 2020/04/30
- [gnurl] 157/264: sshserver.pl: use cached Win32 environment check variable, gnunet, 2020/04/30
- [gnurl] 175/264: test1908: avoid using fixed port number in test data, gnunet, 2020/04/30