Fixed double Close on process handle

This commit is contained in:
Manoj Ampalam 2016-04-04 14:55:29 -07:00
parent eb9db70558
commit 399d345a1c
2 changed files with 21 additions and 22 deletions

View File

@ -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() {

View File

@ -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;