예제 #1
0
static void
collect_children(void)
{
	pid_t pid;
	sigset_t oset, nset;
	int status;

	/* block SIGCHLD while we check for dead children */
	sigemptyset(&nset);
	sigaddset(&nset, SIGCHLD);
	sigprocmask(SIG_BLOCK, &nset, &oset);
	if (child_terminated) {
		debug("Received SIGCHLD.");
		while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
		    (pid < 0 && errno == EINTR))
			if (pid > 0)
				session_close_by_pid(pid, status);
		child_terminated = 0;
	}
	sigprocmask(SIG_SETMASK, &oset, NULL);
}
예제 #2
0
static void
collect_children(void)
{
#ifndef WIN32_FIXME

  /*
   * Original OpenSSH code.
   */
   
	pid_t pid;
	sigset_t oset, nset;
	int status;

	/* block SIGCHLD while we check for dead children */
	sigemptyset(&nset);
	sigaddset(&nset, SIGCHLD);
	sigprocmask(SIG_BLOCK, &nset, &oset);
	if (child_terminated) {
		debug("Received SIGCHLD.");
		while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
		    (pid < 0 && errno == EINTR))
			if (pid > 0)
				session_close_by_pid(pid, status);
		child_terminated = 0;
	}
	sigprocmask(SIG_SETMASK, &oset, NULL);
#else

  /*
   * Win32 code.
   */
   
  HANDLE process;
  
  int status = 0;

  int i = 0;
  
  Session *s;
  
  do
  {
    s = session_get(&i);
    
    if (s != NULL) 
    {
      if (WaitForSingleObject(s -> pid, 0) == 0) 
      {
        debug("Received SIGCHLD.");
        
        process = s->pid;
        
        session_close_by_pid(s->pid, status);
        
        if (s->pid)
			CloseHandle(process);
		int WSHELPDelChildToWatch (HANDLE processtowatch);
		WSHELPDelChildToWatch (process); // take the process off from watch list in select mux
      }
    }
  } while (i > 0);
  
  child_terminated = 0;

#endif
}