mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-24 14:35:35 +02:00
Fixed double Close on process handle
This commit is contained in:
parent
eb9db70558
commit
399d345a1c
@ -156,27 +156,6 @@ sw_raise(int sig) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sw_kill(int pid, int sig) {
|
||||
int child_index, i;
|
||||
if (pid == GetCurrentProcessId())
|
||||
return sw_raise(sig);
|
||||
|
||||
/* for child processes - only SIGTERM supported*/
|
||||
/* TODO implement kill(SIGTERM) for child processes */
|
||||
child_index = -1;
|
||||
for (i = 0; i < children.num_children; i++)
|
||||
if (children.process_id[i] == pid) {
|
||||
child_index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (child_index != -1)
|
||||
TerminateProcess(children.handles[child_index], 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* processes pending signals, return EINTR if any are processed*/
|
||||
static int
|
||||
sw_process_pending_signals() {
|
||||
|
@ -127,6 +127,26 @@ sw_child_to_zombie(DWORD index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sw_kill(int pid, int sig) {
|
||||
int child_index, i;
|
||||
if (pid == GetCurrentProcessId())
|
||||
return sw_raise(sig);
|
||||
|
||||
/* for child processes - only SIGTERM supported*/
|
||||
child_index = -1;
|
||||
for (i = 0; i < children.num_children; i++)
|
||||
if (children.process_id[i] == pid) {
|
||||
child_index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (child_index != -1)
|
||||
TerminateProcess(children.handles[child_index], 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int waitpid(int pid, int *status, int options) {
|
||||
DWORD index, ret, ret_id, exit_code, timeout = 0;
|
||||
HANDLE process = NULL;
|
||||
@ -189,7 +209,7 @@ int waitpid(int pid, int *status, int options) {
|
||||
process = children.handles[index];
|
||||
ret_id = children.process_id[index];
|
||||
GetExitCodeProcess(process, &exit_code);
|
||||
CloseHandle(process);
|
||||
/* process handle will be closed when its removed from list */
|
||||
sw_remove_child_at_index(index);
|
||||
if (status)
|
||||
*status = exit_code;
|
||||
|
Loading…
x
Reference in New Issue
Block a user