Skip to content

Commit 721b267

Browse files
bulk88steve-m-hay
authored andcommitted
fix killpg on Win32, to meet posix expectations for killpg
On Win32 Perls built without PERL_IMPLICIT_SYS, killpg from win32.c was directly called by Perl_apply, yet killpg's return value had Win32 behavior, not POSIX behavior. Modify killpg token to have same meaning as PerlProcKillpg/PerlProc_killpg has on PERL_IMPLICIT_SYS builds. Use a macro rather than create a win32_killpg C function since win32_killpg would be nothing but a call to win32_kill anyways. win32_kill contains the Win32 to POSIX semantics conversion code. Rename old killpg to my_killpg since it has no use outside of win32.c. The psuedo-PID code in win32_kill also played a factor in not writing a separate win32_killpg that calls my_killpg. This fix is tested by kill0.t passing on no-PERL_IMPLICIT_SYS builds. [perl #121230]
1 parent 5ed061f commit 721b267

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

pod/perldelta.pod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ a bug in which the timeout monitor used for tests could not be cancelled once
316316
the test completes, and the full timeout period elapsed before running the next
317317
test file.
318318

319+
On a Perl built without psuedo-fork (psuedo-fork builds were not affected by
320+
this bug), probably since prcess tree kill feature was implemented on Win32,
321+
killing a process tree with L<perlfunc/kill> and a negative signal, resulted
322+
in kill inverting the returned value. This ment successfully killing
323+
1 process tree PID returned 0, and also passing 2 invalid PID, returned 2.
324+
This has been corrected so the documented behavior for return values for kill
325+
executes. [perl #121230]
326+
319327
=back
320328

321329
=head1 Internal Changes

win32/win32.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static int do_spawnvp_handles(int mode, const char *cmdname,
139139
static long find_pid(pTHX_ int pid);
140140
static void remove_dead_process(long child);
141141
static int terminate_process(DWORD pid, HANDLE process_handle, int sig);
142+
static int my_killpg(int pid, int sig);
142143
static int my_kill(int pid, int sig);
143144
static void out_of_memory(void);
144145
static char* wstr_to_str(const wchar_t* wstr);
@@ -1250,8 +1251,9 @@ terminate_process(DWORD pid, HANDLE process_handle, int sig)
12501251
return 0;
12511252
}
12521253

1253-
int
1254-
killpg(int pid, int sig)
1254+
/* returns number of processes killed */
1255+
static int
1256+
my_killpg(int pid, int sig)
12551257
{
12561258
HANDLE process_handle;
12571259
HANDLE snapshot_handle;
@@ -1271,7 +1273,7 @@ killpg(int pid, int sig)
12711273
if (Process32First(snapshot_handle, &entry)) {
12721274
do {
12731275
if (entry.th32ParentProcessID == (DWORD)pid)
1274-
killed += killpg(entry.th32ProcessID, sig);
1276+
killed += my_killpg(entry.th32ProcessID, sig);
12751277
entry.dwSize = sizeof(entry);
12761278
}
12771279
while (Process32Next(snapshot_handle, &entry));
@@ -1282,14 +1284,15 @@ killpg(int pid, int sig)
12821284
return killed;
12831285
}
12841286

1287+
/* returns number of processes killed */
12851288
static int
12861289
my_kill(int pid, int sig)
12871290
{
12881291
int retval = 0;
12891292
HANDLE process_handle;
12901293

12911294
if (sig < 0)
1292-
return killpg(pid, -sig);
1295+
return my_killpg(pid, -sig);
12931296

12941297
process_handle = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
12951298
/* OpenProcess() returns NULL on error, *not* INVALID_HANDLE_VALUE */

win32/win32.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ extern gid_t getegid(void);
322322
extern int setuid(uid_t uid);
323323
extern int setgid(gid_t gid);
324324
extern int kill(int pid, int sig);
325-
extern int killpg(int pid, int sig);
326325
#ifndef USE_PERL_SBRK
327326
extern void *sbrk(ptrdiff_t need);
328327
# define HAS_SBRK_PROTO

win32/win32iop.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ END_EXTERN_C
448448
# undef kill
449449
#endif
450450
#define kill win32_kill
451+
#ifdef UNDER_CE
452+
# undef killpg
453+
#endif
454+
#define killpg(pid, sig) win32_kill(pid, -(sig))
455+
451456

452457
#ifdef UNDER_CE
453458
# undef opendir

0 commit comments

Comments
 (0)