mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-27 15:54:22 +02:00
Fixed issue: sshd service terminates after a brief period of time (https://github.com/PowerShell/Win32-OpenSSH/issues/241)
This commit is contained in:
parent
2017ffdff0
commit
adbe5a2f2e
@ -472,14 +472,15 @@ settimes(wchar_t * path, FILETIME *cretime, FILETIME *acttime, FILETIME *modtime
|
|||||||
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||||
|
|
||||||
if (handle == INVALID_HANDLE_VALUE) {
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
errno = GetLastError;
|
/* TODO - convert Win32 error to errno */
|
||||||
|
errno = GetLastError();
|
||||||
debug("w32_settimes - CreateFileW ERROR:%d", errno);
|
debug("w32_settimes - CreateFileW ERROR:%d", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SetFileTime(handle, cretime, acttime, modtime) == 0)
|
if (SetFileTime(handle, cretime, acttime, modtime) == 0)
|
||||||
{
|
{
|
||||||
errno = GetLastError;
|
errno = GetLastError();
|
||||||
debug("w32_settimes - SetFileTime ERROR:%d", errno);
|
debug("w32_settimes - SetFileTime ERROR:%d", errno);
|
||||||
CloseHandle(handle);
|
CloseHandle(handle);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -258,7 +258,7 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
|
|||||||
if ((ret >= WAIT_OBJECT_0) && (ret <= WAIT_OBJECT_0 + num_all_events - 1)) {
|
if ((ret >= WAIT_OBJECT_0) && (ret <= WAIT_OBJECT_0 + num_all_events - 1)) {
|
||||||
//woken up by event signalled
|
//woken up by event signalled
|
||||||
/* is this due to a child process going down*/
|
/* is this due to a child process going down*/
|
||||||
if (children.num_children && ((ret - WAIT_OBJECT_0) < children.num_children)) {
|
if (live_children && ((ret - WAIT_OBJECT_0) < live_children)) {
|
||||||
sigaddset(&pending_signals, W32_SIGCHLD);
|
sigaddset(&pending_signals, W32_SIGCHLD);
|
||||||
sw_child_to_zombie(ret - WAIT_OBJECT_0);
|
sw_child_to_zombie(ret - WAIT_OBJECT_0);
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,17 @@ int sw_kill(int pid, int sig);
|
|||||||
/* child processes */
|
/* child processes */
|
||||||
#define MAX_CHILDREN 50
|
#define MAX_CHILDREN 50
|
||||||
struct _children {
|
struct _children {
|
||||||
|
/*
|
||||||
|
* array of handles and process_ids.
|
||||||
|
* intial (num_children - num_zombies) are alive
|
||||||
|
* rest are zombies
|
||||||
|
*/
|
||||||
HANDLE handles[MAX_CHILDREN];
|
HANDLE handles[MAX_CHILDREN];
|
||||||
DWORD process_id[MAX_CHILDREN];
|
DWORD process_id[MAX_CHILDREN];
|
||||||
/* total children */
|
/* total children */
|
||||||
DWORD num_children;
|
DWORD num_children;
|
||||||
/* #zombies */
|
/* #zombies */
|
||||||
/* (num_chileren - zombies) are live children */
|
/* (num_children - zombies) are live children */
|
||||||
DWORD num_zombies;
|
DWORD num_zombies;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ sw_remove_child_at_index(DWORD index) {
|
|||||||
|
|
||||||
int
|
int
|
||||||
sw_child_to_zombie(DWORD index) {
|
sw_child_to_zombie(DWORD index) {
|
||||||
DWORD last_non_zombie, last_child, zombie_pid;
|
DWORD last_non_zombie, zombie_pid;
|
||||||
HANDLE zombie_handle;
|
HANDLE zombie_handle;
|
||||||
|
|
||||||
debug("zombie'ing child at index %d, %d zombies of %d", index,
|
debug("zombie'ing child at index %d, %d zombies of %d", index,
|
||||||
@ -112,17 +112,17 @@ sw_child_to_zombie(DWORD index) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
zombie_pid = children.process_id[index];
|
|
||||||
zombie_handle = children.handles[index];
|
|
||||||
last_non_zombie = children.num_children - children.num_zombies - 1;
|
last_non_zombie = children.num_children - children.num_zombies - 1;
|
||||||
last_child = children.num_children - 1;
|
|
||||||
|
if (last_non_zombie != index) {
|
||||||
children.handles[index] = children.handles[last_non_zombie];
|
/* swap */
|
||||||
children.process_id[index] = children.process_id[last_non_zombie];
|
zombie_pid = children.process_id[index];
|
||||||
|
zombie_handle = children.handles[index];
|
||||||
children.handles[last_non_zombie] = children.handles[index];
|
children.handles[index] = children.handles[last_non_zombie];
|
||||||
children.process_id[last_non_zombie] = children.process_id[index];
|
children.process_id[index] = children.process_id[last_non_zombie];
|
||||||
|
children.handles[last_non_zombie] = zombie_handle;
|
||||||
|
children.process_id[last_non_zombie] = zombie_pid;
|
||||||
|
}
|
||||||
children.num_zombies++;
|
children.num_zombies++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -185,10 +185,13 @@ int waitpid(int pid, int *status, int options) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
process = children.handles[index];
|
/* wait if process is still alive */
|
||||||
ret = WaitForSingleObject(process, INFINITE);
|
if (index < children.num_children - children.num_zombies) {
|
||||||
if (ret != WAIT_OBJECT_0)
|
process = children.handles[index];
|
||||||
DebugBreak();//fatal
|
ret = WaitForSingleObject(process, INFINITE);
|
||||||
|
if (ret != WAIT_OBJECT_0)
|
||||||
|
DebugBreak();//fatal
|
||||||
|
}
|
||||||
|
|
||||||
ret_id = children.process_id[index];
|
ret_id = children.process_id[index];
|
||||||
GetExitCodeProcess(process, &exit_code);
|
GetExitCodeProcess(process, &exit_code);
|
||||||
@ -200,6 +203,15 @@ int waitpid(int pid, int *status, int options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* pid = -1*/
|
/* pid = -1*/
|
||||||
|
/* are there any existing zombies */
|
||||||
|
if (children.num_zombies) {
|
||||||
|
/* return one of them */
|
||||||
|
ret_id = children.process_id[children.num_children - 1];
|
||||||
|
sw_remove_child_at_index(children.num_children - 1);
|
||||||
|
return ret_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* all children are alive. wait for one of them to exit */
|
||||||
timeout = INFINITE;
|
timeout = INFINITE;
|
||||||
if (options & WNOHANG)
|
if (options & WNOHANG)
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user