Skip to content

Commit 748da01

Browse files
committed
Report success when Windows kill() emulation signals an exiting process.
This is consistent with the POSIX verdict that kill() shall not report ESRCH for a zombie process. Back-patch to 9.0 (all supported versions). Test code from commit d7cdf6e depends on it, and log messages about kill() reporting "Invalid argument" will cease to appear for this not-unexpected condition.
1 parent 98d3a7b commit 748da01

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/port/kill.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,28 @@ pgkill(int pid, int sig)
5050
return 0;
5151
}
5252

53-
if (GetLastError() == ERROR_FILE_NOT_FOUND)
54-
errno = ESRCH;
55-
else if (GetLastError() == ERROR_ACCESS_DENIED)
56-
errno = EPERM;
57-
else
58-
errno = EINVAL;
59-
return -1;
53+
switch (GetLastError())
54+
{
55+
case ERROR_BROKEN_PIPE:
56+
case ERROR_BAD_PIPE:
57+
58+
/*
59+
* These arise transiently as a process is exiting. Treat them
60+
* like POSIX treats a zombie process, reporting success.
61+
*/
62+
return 0;
63+
64+
case ERROR_FILE_NOT_FOUND:
65+
/* pipe fully gone, so treat the process as gone */
66+
errno = ESRCH;
67+
return -1;
68+
case ERROR_ACCESS_DENIED:
69+
errno = EPERM;
70+
return -1;
71+
default:
72+
errno = EINVAL; /* unexpected */
73+
return -1;
74+
}
6075
}
6176

6277
#endif

0 commit comments

Comments
 (0)