From 1915208a544d8cf2a59869f45c57db751b0222da Mon Sep 17 00:00:00 2001 From: quamrulmina Date: Fri, 2 Oct 2015 14:18:49 -0500 Subject: [PATCH] Fixed sshd process not ending when sftp-server and the shell ended NoMachine did not finish coding child process ending detection logic. Added the needed code so that child process handle is added to the handles that WaitForMultipleObjects() waits for in nomachine select() implementation in socket.c. Otherwise select() would be stuck in read/write dectection even when the process of interest has exited. --- contrib/win32/win32compat/socket.c | 17 +++++++++++++++-- session.c | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/contrib/win32/win32compat/socket.c b/contrib/win32/win32compat/socket.c index 7e6a6b7..57083f6 100644 --- a/contrib/win32/win32compat/socket.c +++ b/contrib/win32/win32compat/socket.c @@ -1986,6 +1986,13 @@ int cleanSelectThread(int thread_no) return 1; } +// Add a Child process to be added to select mux so thyat we know when it has exited +HANDLE ChildToWatch = NULL; +int WSHELPAddChildToWatch ( HANDLE processtowatch) +{ + ChildToWatch = processtowatch; + return 0; +} int WSHELPselect(int fds, fd_set* readsfds, fd_set* writesfds, fd_set* exceptsfds, const struct timeval* timeout) @@ -2288,6 +2295,12 @@ int WSHELPselect(int fds, fd_set* readsfds, fd_set* writesfds, DBG_MSG("WSHELPselect(fds = %d) : Waiting for signal from threads...\n", fds); DBG_MSG("i_sem = %d\n", i_sem); + + // add a child process handle to the mux if it was registered + if ( ChildToWatch ) { + semaphores[i_sem] = ChildToWatch ; + i_sem++; + } dwWaitResult = WaitForMultipleObjects(i_sem, semaphores, FALSE, ms); @@ -2536,8 +2549,8 @@ int WSHELPwrite(int sfd, const char *buf, unsigned int max) if (sfd != 2) { - error("write to socket sfd [%d] failed with error code [%d]", - sfd, GetLastError()); + //error("write to socket sfd [%d] failed with error code [%d]", + // sfd, GetLastError()); DBG_MSG("<- WSHELPwrite(sfd = %d, ret = -1)...\n", sfd); } diff --git a/session.c b/session.c index b334156..9830df1 100644 --- a/session.c +++ b/session.c @@ -834,6 +834,10 @@ do_exec_no_pty(Session *s, const char *command) s -> pid = pi.hProcess; s -> processId = pi.dwProcessId; + + // Add the child process created to select mux so that during our select data call we know if the process has exited + int WSHELPAddChildToWatch ( HANDLE processtowatch); + WSHELPAddChildToWatch ( pi.hProcess); /* * Set interactive/non-interactive mode.