Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/win32/win32compat/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
return 0;
}


int
sw_initialize()
{
memset(&children, 0, sizeof(children));
atexit(terminate_all_child_processes);
sw_init_signal_handler_table();
if (sw_init_timer() != 0)
return -1;
Expand Down
1 change: 1 addition & 0 deletions contrib/win32/win32compat/signal_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int register_child(HANDLE child, DWORD pid);
int sw_remove_child_at_index(DWORD index);
int sw_child_to_zombie(DWORD index);
void sw_cleanup_child_zombies();
void terminate_all_child_processes();

struct _timer_info {
HANDLE timer;
Expand Down
20 changes: 19 additions & 1 deletion contrib/win32/win32compat/signal_sigchld.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,22 @@ sw_cleanup_child_zombies()
int pid = 1;
while (pid > 0)
pid = waitpid(-1, NULL, WNOHANG);
}
}

void
terminate_all_child_processes()
{
if (children.num_children > 0 && children.num_children <= MAX_CHILDREN) {
if (children.num_zombies >= 0 && children.num_children > children.num_zombies) {
DWORD live_children = children.num_children - children.num_zombies;
while (live_children--) {
DWORD pid = children.process_id[live_children];
HANDLE handle = children.handles[live_children];
TerminateProcess(handle, 0);
CloseHandle(handle);
debug4("Terminate child process %p pid %d", handle, pid);
++children.num_zombies;
}
}
}
}
4 changes: 2 additions & 2 deletions regress/pesterTests/SSHD.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Describe "E2E scenarios for sshd" -Tags "CI" {

# with a connection, there should be two additional session processes
$sshdPidsCountWithConn | Should Be (2 + $sshdPidCountBefore)
# after LoginGraceTime expires, one of the session processes should exit
$sshdPidsCountAfter | Should Be (1 + $sshdPidCountBefore)
# after LoginGraceTime expires, all session processes should exit
$sshdPidsCountAfter | Should Be $sshdPidCountBefore
}

It "sshd pre-auth process is spawned under runtime generated virtual account" {
Expand Down
7 changes: 5 additions & 2 deletions sshd-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ privsep_child_cmdline()
static void
grace_alarm_handler(int sig)
{
#ifndef WINDOWS
#ifdef WINDOWS
/* We don't have to be signal-safe on Windows. Different native event mechanisms (APC). */
exit(EXIT_LOGIN_GRACE); /* Perform full C library cleanup and call atexit() registered functions. */
#else
/*
* Try to kill any processes that we have spawned, E.g. authorized
* keys command helpers or privsep children.
Expand All @@ -560,8 +563,8 @@ grace_alarm_handler(int sig)
(void)sigaction(SIGTERM, &sa, NULL);
kill(0, SIGTERM);
}
_exit(EXIT_LOGIN_GRACE); /* We have to be signal-safe. */
#endif /* WINDOWS */
_exit(EXIT_LOGIN_GRACE);
}

/* Destroy the host and server keys. They will no longer be needed. */
Expand Down