Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0ea1f2a

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 31f9bbf commit 0ea1f2a

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/port/kill.c

+22-7
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,28 @@ pgkill(int pid, int sig)
7070
return 0;
7171
}
7272

73-
if (GetLastError() == ERROR_FILE_NOT_FOUND)
74-
errno = ESRCH;
75-
else if (GetLastError() == ERROR_ACCESS_DENIED)
76-
errno = EPERM;
77-
else
78-
errno = EINVAL;
79-
return -1;
73+
switch (GetLastError())
74+
{
75+
case ERROR_BROKEN_PIPE:
76+
case ERROR_BAD_PIPE:
77+
78+
/*
79+
* These arise transiently as a process is exiting. Treat them
80+
* like POSIX treats a zombie process, reporting success.
81+
*/
82+
return 0;
83+
84+
case ERROR_FILE_NOT_FOUND:
85+
/* pipe fully gone, so treat the process as gone */
86+
errno = ESRCH;
87+
return -1;
88+
case ERROR_ACCESS_DENIED:
89+
errno = EPERM;
90+
return -1;
91+
default:
92+
errno = EINVAL; /* unexpected */
93+
return -1;
94+
}
8095
}
8196

8297
#endif

0 commit comments

Comments
 (0)