Skip to content

Commit

Permalink
tidy-up: align MSYS2/Cygwin codepaths, follow Cygwin MAX_PID bump
Browse files Browse the repository at this point in the history
MSYS/MSYS2 and Cygwin are the same platform. Adjust code where they were
treated differently.

- drop separate `MSYS` from buildinfo flags. Our code is using the
  `CYGWIN` variable and CMake (since v3.21) sets it also for `MSYS`.
- fix test1158 and test1186 to exclude them for all Win32 targets,
  instead of just MSYS test envs. To align behavior between MSYS and
  Cygwin envs. Required for recent MSYS2 releases which reports itself
  as Cygwin, and no longer MSYS, which broke the previous exclusion
  logic.
- follow Cygwin bumping its `MAX_PID` value, to avoid PID collisions.
  https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=363357c023ce01e936bdaedf0f479292a8fa4e0f

Reported-by: Jeremy Drake
Bug: curl#16217 (comment)
Ref: https://www.msys2.org/news/#2025-02-14-moving-msys2-closer-to-cygwin
Closes curl#16411
  • Loading branch information
vszakats committed Feb 21, 2025
1 parent 540d341 commit 4842f22
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 31 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ endif()
if(CYGWIN)
string(APPEND _target_flags " CYGWIN")
endif()
if(MSYS)
string(APPEND _target_flags " MSYS")
endif()
if(DOS)
string(APPEND _target_flags " DOS")
endif()
Expand Down
1 change: 0 additions & 1 deletion acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,6 @@ AC_DEFUN([CURL_PREPARE_BUILDINFO], [
curl_pflags="${curl_pflags} CYGWIN"
fi
case $host_os in
msys*) curl_pflags="${curl_pflags} MSYS";;
msdos*) curl_pflags="${curl_pflags} DOS";;
amiga*) curl_pflags="${curl_pflags} AMIGA";;
esac
Expand Down
4 changes: 1 addition & 3 deletions tests/data/test1158
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ blablabla
<client>
<features>
Mime
!win32
</features>
<server>
http
Expand All @@ -31,9 +32,6 @@ HTTP RFC1867-type formposting with filename containing '"'
<command>
http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -F "file=@\"%LOGDIR/test%TESTNUMBER\\\".txt\";type=mo/foo;filename=\"test%TESTNUMBER\\\".txt\"" -F 'file2=@"%LOGDIR/test%TESTNUMBER\".txt"' -F 'file3=@"%LOGDIR/test%TESTNUMBER\".txt";type=m/f,"%LOGDIR/test%TESTNUMBER\".txt"'
</command>
<precheck>
%PERL -e "print 'Test requires a system supporting double quotes in file names' if ($^O eq 'msys');"
</precheck>
# We create this file before the command is invoked!
<file name=%LOGDIR/test%TESTNUMBER".txt>
foo bar
Expand Down
4 changes: 1 addition & 3 deletions tests/data/test1186
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ blablabla
<client>
<features>
Mime
!win32
</features>
<server>
http
Expand All @@ -31,9 +32,6 @@ Multipart formposting with backslash-escaping filename containing '"'
<command>
http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER --form-escape -F "file=@\"%LOGDIR/test%TESTNUMBER\\\".txt\";type=mo/foo;filename=\"test%TESTNUMBER\\\".txt\"" -F 'file2=@"%LOGDIR/test%TESTNUMBER\".txt"' -F 'file3=@"%LOGDIR/test%TESTNUMBER\".txt";type=m/f,"%LOGDIR/test%TESTNUMBER\".txt"'
</command>
<precheck>
%PERL -e "print 'Test requires a system supporting double quotes in file names' if ($^O eq 'msys');"
</precheck>
# We create this file before the command is invoked!
<file name=%LOGDIR/test%TESTNUMBER".txt>
foo bar
Expand Down
4 changes: 2 additions & 2 deletions tests/dictserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def dictserver(options):
pid = os.getpid()
# see tests/server/util.c function write_pidfile
if os.name == "nt":
pid += 65536
pid += 4194304
with open(options.pidfile, "w") as f:
f.write(str(pid))

Expand Down Expand Up @@ -90,7 +90,7 @@ def handle(self):
pid = os.getpid()
# see tests/server/util.c function write_pidfile
if os.name == "nt":
pid += 65536
pid += 4194304
response_data = VERIFIED_RSP.format(pid=pid)
else:
log.debug("[DICT] Received normal request")
Expand Down
4 changes: 2 additions & 2 deletions tests/negtelnetserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def telnetserver(options):
pid = os.getpid()
# see tests/server/util.c function write_pidfile
if os.name == "nt":
pid += 65536
pid += 4194304
with open(options.pidfile, "w") as f:
f.write(str(pid))

Expand Down Expand Up @@ -93,7 +93,7 @@ def handle(self):
pid = os.getpid()
# see tests/server/util.c function write_pidfile
if os.name == "nt":
pid += 65536
pid += 4194304
response = VERIFIED_RSP.format(pid=pid)
response_data = response.encode('utf-8')
else:
Expand Down
18 changes: 9 additions & 9 deletions tests/processhelp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ sub pidfromfile {
#
sub winpid_to_pid {
my $vpid = $_[0];
if(($^O eq 'cygwin' || $^O eq 'msys') && $vpid > 65536) {
my $pid = Cygwin::winpid_to_pid($vpid - 65536);
if(($^O eq 'cygwin' || $^O eq 'msys') && $vpid > 4194304) {
my $pid = Cygwin::winpid_to_pid($vpid - 4194304);
if($pid) {
return $pid;
} else {
Expand All @@ -133,8 +133,8 @@ sub pidexists {
if($pid > 0) {
# verify if currently existing Windows process
$pid = winpid_to_pid($pid);
if ($pid > 65536 && os_is_win()) {
$pid -= 65536;
if ($pid > 4194304 && os_is_win()) {
$pid -= 4194304;
if($^O ne 'MSWin32') {
my $filter = "PID eq $pid";
# https://ss64.com/nt/tasklist.html
Expand Down Expand Up @@ -164,8 +164,8 @@ sub pidterm {
if($pid > 0) {
# request the process to quit
$pid = winpid_to_pid($pid);
if ($pid > 65536 && os_is_win()) {
$pid -= 65536;
if ($pid > 4194304 && os_is_win()) {
$pid -= 4194304;
if($^O ne 'MSWin32') {
# https://ss64.com/nt/taskkill.html
my $cmd = "taskkill -t -pid $pid >nul 2>&1";
Expand All @@ -189,8 +189,8 @@ sub pidkill {
if($pid > 0) {
# request the process to quit
$pid = winpid_to_pid($pid);
if ($pid > 65536 && os_is_win()) {
$pid -= 65536;
if ($pid > 4194304 && os_is_win()) {
$pid -= 4194304;
if($^O ne 'MSWin32') {
# https://ss64.com/nt/taskkill.html
my $cmd = "taskkill -f -t -pid $pid >nul 2>&1";
Expand All @@ -214,7 +214,7 @@ sub pidwait {

$pid = winpid_to_pid($pid);
# check if the process exists
if ($pid > 65536 && os_is_win()) {
if ($pid > 4194304 && os_is_win()) {
if($flags == &WNOHANG) {
return pidexists($pid)?0:$pid;
}
Expand Down
14 changes: 8 additions & 6 deletions tests/server/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,15 @@ curl_off_t our_getpid(void)

pid = (curl_off_t)Curl_getpid();
#if 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
/* store pid + MAX_PID to avoid conflict with Cygwin/msys PIDs, see also:
* - 2019-01-31: https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵
* h=b5e1003722cb14235c4f166be72c09acdffc62ea
* - 2019-02-02: https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵
* h=448cf5aa4b429d5a9cebf92a0da4ab4b5b6d23fe
* - 2024-12-19: https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵
* h=363357c023ce01e936bdaedf0f479292a8fa4e0f
*/
pid += 65536;
pid += 4194304;
#endif
return pid;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/smbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def smbserver(options):
pid = os.getpid()
# see tests/server/util.c function write_pidfile
if os.name == "nt":
pid += 65536
pid += 4194304
with open(options.pidfile, "w") as f:
f.write(str(pid))

Expand Down Expand Up @@ -331,7 +331,7 @@ def get_server_path(self, requested_filename):
pid = os.getpid()
# see tests/server/util.c function write_pidfile
if os.name == "nt":
pid += 65536
pid += 4194304
contents = VERIFIED_RSP.format(pid=pid).encode('utf-8')

self.write_to_fid(fid, contents)
Expand Down

0 comments on commit 4842f22

Please sign in to comment.