Skip to content

Commit 1915208

Browse files
committed
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.
1 parent 3f71c81 commit 1915208

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

contrib/win32/win32compat/socket.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,13 @@ int cleanSelectThread(int thread_no)
19861986
return 1;
19871987
}
19881988

1989+
// Add a Child process to be added to select mux so thyat we know when it has exited
1990+
HANDLE ChildToWatch = NULL;
1991+
int WSHELPAddChildToWatch ( HANDLE processtowatch)
1992+
{
1993+
ChildToWatch = processtowatch;
1994+
return 0;
1995+
}
19891996

19901997
int WSHELPselect(int fds, fd_set* readsfds, fd_set* writesfds,
19911998
fd_set* exceptsfds, const struct timeval* timeout)
@@ -2288,6 +2295,12 @@ int WSHELPselect(int fds, fd_set* readsfds, fd_set* writesfds,
22882295
DBG_MSG("WSHELPselect(fds = %d) : Waiting for signal from threads...\n", fds);
22892296

22902297
DBG_MSG("i_sem = %d\n", i_sem);
2298+
2299+
// add a child process handle to the mux if it was registered
2300+
if ( ChildToWatch ) {
2301+
semaphores[i_sem] = ChildToWatch ;
2302+
i_sem++;
2303+
}
22912304

22922305
dwWaitResult = WaitForMultipleObjects(i_sem, semaphores, FALSE, ms);
22932306

@@ -2536,8 +2549,8 @@ int WSHELPwrite(int sfd, const char *buf, unsigned int max)
25362549

25372550
if (sfd != 2)
25382551
{
2539-
error("write to socket sfd [%d] failed with error code [%d]",
2540-
sfd, GetLastError());
2552+
//error("write to socket sfd [%d] failed with error code [%d]",
2553+
// sfd, GetLastError());
25412554

25422555
DBG_MSG("<- WSHELPwrite(sfd = %d, ret = -1)...\n", sfd);
25432556
}

session.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ do_exec_no_pty(Session *s, const char *command)
834834

835835
s -> pid = pi.hProcess;
836836
s -> processId = pi.dwProcessId;
837+
838+
// Add the child process created to select mux so that during our select data call we know if the process has exited
839+
int WSHELPAddChildToWatch ( HANDLE processtowatch);
840+
WSHELPAddChildToWatch ( pi.hProcess);
837841

838842
/*
839843
* Set interactive/non-interactive mode.

0 commit comments

Comments
 (0)