mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 09:21:50 -05:00
tests: fix conflict between Cygwin/msys and Windows PIDs
Add 65536 to Windows PIDs to allow Windows specific treatment by having disjunct ranges for Cygwin/msys and Windows PIDs. See also: - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵ h=b5e1003722cb14235c4f166be72c09acdffc62ea - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵ h=448cf5aa4b429d5a9cebf92a0da4ab4b5b6d23fe Replaces #5178 Closes #5188
This commit is contained in:
parent
6d13ef5325
commit
3f60a9e995
@ -51,8 +51,11 @@ def dictserver(options):
|
|||||||
"""
|
"""
|
||||||
if options.pidfile:
|
if options.pidfile:
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
|
# see tests/server/util.c function write_pidfile
|
||||||
|
if os.name == "nt":
|
||||||
|
pid += 65536
|
||||||
with open(options.pidfile, "w") as f:
|
with open(options.pidfile, "w") as f:
|
||||||
f.write("{0}".format(pid))
|
f.write(str(pid))
|
||||||
|
|
||||||
local_bind = (options.host, options.port)
|
local_bind = (options.host, options.port)
|
||||||
log.info("[DICT] Listening on %s", local_bind)
|
log.info("[DICT] Listening on %s", local_bind)
|
||||||
@ -85,7 +88,11 @@ class DictHandler(socketserver.BaseRequestHandler):
|
|||||||
if VERIFIED_REQ in data:
|
if VERIFIED_REQ in data:
|
||||||
log.debug("[DICT] Received verification request from test "
|
log.debug("[DICT] Received verification request from test "
|
||||||
"framework")
|
"framework")
|
||||||
response_data = VERIFIED_RSP.format(pid=os.getpid())
|
pid = os.getpid()
|
||||||
|
# see tests/server/util.c function write_pidfile
|
||||||
|
if os.name == "nt":
|
||||||
|
pid += 65536
|
||||||
|
response_data = VERIFIED_RSP.format(pid=pid)
|
||||||
else:
|
else:
|
||||||
log.debug("[DICT] Received normal request")
|
log.debug("[DICT] Received normal request")
|
||||||
response_data = "No matches"
|
response_data = "No matches"
|
||||||
|
72
tests/ftp.pm
72
tests/ftp.pm
@ -42,6 +42,10 @@ use serverhelp qw(
|
|||||||
datasockf_pidfilename
|
datasockf_pidfilename
|
||||||
);
|
);
|
||||||
|
|
||||||
|
use pathhelp qw(
|
||||||
|
os_is_win
|
||||||
|
);
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
# portable_sleep uses Time::HiRes::sleep if available and falls back
|
# portable_sleep uses Time::HiRes::sleep if available and falls back
|
||||||
# to the classic approach of using select(undef, undef, undef, ...).
|
# to the classic approach of using select(undef, undef, undef, ...).
|
||||||
@ -55,7 +59,7 @@ sub portable_sleep {
|
|||||||
if($Time::HiRes::VERSION) {
|
if($Time::HiRes::VERSION) {
|
||||||
Time::HiRes::sleep($seconds);
|
Time::HiRes::sleep($seconds);
|
||||||
}
|
}
|
||||||
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
|
elsif (os_is_win()) {
|
||||||
Win32::Sleep($seconds*1000);
|
Win32::Sleep($seconds*1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -91,19 +95,23 @@ sub pidexists {
|
|||||||
my $pid = $_[0];
|
my $pid = $_[0];
|
||||||
|
|
||||||
if($pid > 0) {
|
if($pid > 0) {
|
||||||
|
# verify if currently existing Windows process
|
||||||
|
if ($pid > 65536 && os_is_win()) {
|
||||||
|
$pid -= 65536;
|
||||||
|
if($^O ne 'MSWin32') {
|
||||||
|
my $filter = "PID eq $pid";
|
||||||
|
my $result = `tasklist -fi \"$filter\" 2>nul`;
|
||||||
|
if(index($result, "$pid") != -1) {
|
||||||
|
return -$pid;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# verify if currently existing and alive
|
# verify if currently existing and alive
|
||||||
if(kill(0, $pid)) {
|
if(kill(0, $pid)) {
|
||||||
return $pid;
|
return $pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
# verify if currently existing Windows process
|
|
||||||
if($^O eq "msys") {
|
|
||||||
my $filter = "PID eq $pid";
|
|
||||||
my $result = `tasklist -fi \"$filter\" 2>nul`;
|
|
||||||
if(index($result, "$pid") != -1) {
|
|
||||||
return -$pid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -116,17 +124,21 @@ sub pidterm {
|
|||||||
my $pid = $_[0];
|
my $pid = $_[0];
|
||||||
|
|
||||||
if($pid > 0) {
|
if($pid > 0) {
|
||||||
# signal the process to terminate
|
|
||||||
kill("TERM", $pid);
|
|
||||||
|
|
||||||
# request the process to quit
|
# request the process to quit
|
||||||
if($^O eq "msys") {
|
if ($pid > 65536 && os_is_win()) {
|
||||||
my $filter = "PID eq $pid";
|
$pid -= 65536;
|
||||||
my $result = `tasklist -fi \"$filter\" 2>nul`;
|
if($^O ne 'MSWin32') {
|
||||||
if(index($result, "$pid") != -1) {
|
my $filter = "PID eq $pid";
|
||||||
system("taskkill -fi \"$filter\" >nul 2>&1");
|
my $result = `tasklist -fi \"$filter\" 2>nul`;
|
||||||
|
if(index($result, "$pid") != -1) {
|
||||||
|
system("taskkill -fi \"$filter\" >nul 2>&1");
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# signal the process to terminate
|
||||||
|
kill("TERM", $pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,19 +149,23 @@ sub pidkill {
|
|||||||
my $pid = $_[0];
|
my $pid = $_[0];
|
||||||
|
|
||||||
if($pid > 0) {
|
if($pid > 0) {
|
||||||
# signal the process to terminate
|
|
||||||
kill("KILL", $pid);
|
|
||||||
|
|
||||||
# request the process to quit
|
# request the process to quit
|
||||||
if($^O eq "msys") {
|
if ($pid > 65536 && os_is_win()) {
|
||||||
my $filter = "PID eq $pid";
|
$pid -= 65536;
|
||||||
my $result = `tasklist -fi \"$filter\" 2>nul`;
|
if($^O ne 'MSWin32') {
|
||||||
if(index($result, "$pid") != -1) {
|
my $filter = "PID eq $pid";
|
||||||
system("taskkill -f -fi \"$filter\" >nul 2>&1");
|
my $result = `tasklist -fi \"$filter\" 2>nul`;
|
||||||
# Windows XP Home compatibility
|
if(index($result, "$pid") != -1) {
|
||||||
system("tskill $pid >nul 2>&1");
|
system("taskkill -f -fi \"$filter\" >nul 2>&1");
|
||||||
|
# Windows XP Home compatibility
|
||||||
|
system("tskill $pid >nul 2>&1");
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# signal the process to terminate
|
||||||
|
kill("KILL", $pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,9 @@ def telnetserver(options):
|
|||||||
"""
|
"""
|
||||||
if options.pidfile:
|
if options.pidfile:
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
|
# see tests/server/util.c function write_pidfile
|
||||||
|
if os.name == "nt":
|
||||||
|
pid += 65536
|
||||||
with open(options.pidfile, "w") as f:
|
with open(options.pidfile, "w") as f:
|
||||||
f.write(str(pid))
|
f.write(str(pid))
|
||||||
|
|
||||||
@ -86,7 +89,11 @@ class NegotiatingTelnetHandler(socketserver.BaseRequestHandler):
|
|||||||
|
|
||||||
if VERIFIED_REQ.encode('utf-8') in data:
|
if VERIFIED_REQ.encode('utf-8') in data:
|
||||||
log.debug("Received verification request from test framework")
|
log.debug("Received verification request from test framework")
|
||||||
response = VERIFIED_RSP.format(pid=os.getpid())
|
pid = os.getpid()
|
||||||
|
# see tests/server/util.c function write_pidfile
|
||||||
|
if os.name == "nt":
|
||||||
|
pid += 65536
|
||||||
|
response = VERIFIED_RSP.format(pid=pid)
|
||||||
response_data = response.encode('utf-8')
|
response_data = response.encode('utf-8')
|
||||||
else:
|
else:
|
||||||
log.debug("Received normal request - echoing back")
|
log.debug("Received normal request - echoing back")
|
||||||
|
@ -269,6 +269,15 @@ int write_pidfile(const char *filename)
|
|||||||
logmsg("Couldn't write pid file: %s %s", filename, strerror(errno));
|
logmsg("Couldn't write pid file: %s %s", filename, strerror(errno));
|
||||||
return 0; /* fail */
|
return 0; /* fail */
|
||||||
}
|
}
|
||||||
|
#if defined(WIN32) || defined(_WIN32)
|
||||||
|
/* store pid + 65536 to avoid conflict with Cygwin/msys PIDs, see also:
|
||||||
|
* - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵
|
||||||
|
* h=b5e1003722cb14235c4f166be72c09acdffc62ea
|
||||||
|
* - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵
|
||||||
|
* h=448cf5aa4b429d5a9cebf92a0da4ab4b5b6d23fe
|
||||||
|
*/
|
||||||
|
pid += 65536;
|
||||||
|
#endif
|
||||||
fprintf(pidfile, "%ld\n", pid);
|
fprintf(pidfile, "%ld\n", pid);
|
||||||
fclose(pidfile);
|
fclose(pidfile);
|
||||||
logmsg("Wrote pid %ld to %s", pid, filename);
|
logmsg("Wrote pid %ld to %s", pid, filename);
|
||||||
|
@ -61,8 +61,11 @@ def smbserver(options):
|
|||||||
"""
|
"""
|
||||||
if options.pidfile:
|
if options.pidfile:
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
|
# see tests/server/util.c function write_pidfile
|
||||||
|
if os.name == "nt":
|
||||||
|
pid += 65536
|
||||||
with open(options.pidfile, "w") as f:
|
with open(options.pidfile, "w") as f:
|
||||||
f.write("{0}".format(pid))
|
f.write(str(pid))
|
||||||
|
|
||||||
# Here we write a mini config for the server
|
# Here we write a mini config for the server
|
||||||
smb_config = configparser.ConfigParser()
|
smb_config = configparser.ConfigParser()
|
||||||
@ -267,7 +270,11 @@ class TestSmbServer(imp_smbserver.SMBSERVER):
|
|||||||
|
|
||||||
if requested_filename == VERIFIED_REQ:
|
if requested_filename == VERIFIED_REQ:
|
||||||
log.debug("[SMB] Verifying server is alive")
|
log.debug("[SMB] Verifying server is alive")
|
||||||
contents = VERIFIED_RSP.format(pid=os.getpid()).encode('utf-8')
|
pid = os.getpid()
|
||||||
|
# see tests/server/util.c function write_pidfile
|
||||||
|
if os.name == "nt":
|
||||||
|
pid += 65536
|
||||||
|
contents = VERIFIED_RSP.format(pid=pid).encode('utf-8')
|
||||||
|
|
||||||
self.write_to_fid(fid, contents)
|
self.write_to_fid(fid, contents)
|
||||||
return fid, filename
|
return fid, filename
|
||||||
|
Loading…
x
Reference in New Issue
Block a user