diff src/ntproc.c @ 290:c9fe270a4101 r21-0b43

Import from CVS: tag r21-0b43
author cvs
date Mon, 13 Aug 2007 10:36:47 +0200
parents e11d67e05968
children 33bdb3d4b97f
line wrap: on
line diff
--- a/src/ntproc.c	Mon Aug 13 10:35:55 2007 +0200
+++ b/src/ntproc.c	Mon Aug 13 10:36:47 2007 +0200
@@ -345,204 +345,6 @@
   return FALSE;
 }
 
-/* create_child doesn't know what emacs' file handle will be for waiting
-   on output from the child, so we need to make this additional call
-   to register the handle with the process
-   This way the select emulator knows how to match file handles with
-   entries in child_procs.  */
-void 
-register_child (int pid, int fd)
-{
-  child_process *cp;
-  
-  cp = find_child_pid (pid);
-  if (cp == NULL)
-    {
-      DebPrint (("register_child unable to find pid %lu\n", pid));
-      return;
-    }
-  
-#ifdef FULL_DEBUG
-  DebPrint (("register_child registered fd %d with pid %lu\n", fd, pid));
-#endif
-  
-  cp->fd = fd;
-
-  /* thread is initially blocked until select is called; set status so
-     that select will release thread */
-  cp->status = STATUS_READ_ACKNOWLEDGED;
-
-  /* attach child_process to fd_info */
-  if (fd_info[fd].cp != NULL)
-    {
-      DebPrint (("register_child: fd_info[%d] apparently in use!\n", fd));
-      abort ();
-    }
-
-  fd_info[fd].cp = cp;
-}
-
-/* When a process dies its pipe will break so the reader thread will
-   signal failure to the select emulator.
-   The select emulator then calls this routine to clean up.
-   Since the thread signaled failure we can assume it is exiting.  */
-static void 
-reap_subprocess (child_process *cp)
-{
-  if (cp->procinfo.hProcess)
-    {
-      /* Reap the process */
-      if (WaitForSingleObject (cp->procinfo.hProcess, INFINITE) != WAIT_OBJECT_0)
-	DebPrint (("reap_subprocess.WaitForSingleObject (process) failed "
-		   "with %lu for fd %ld\n", GetLastError (), cp->fd));
-      CloseHandle (cp->procinfo.hProcess);
-      cp->procinfo.hProcess = NULL;
-      CloseHandle (cp->procinfo.hThread);
-      cp->procinfo.hThread = NULL;
-    }
-
-  /* For asynchronous children, the child_proc resources will be freed
-     when the last pipe read descriptor is closed; for synchronous
-     children, we must explicitly free the resources now because
-     register_child has not been called. */
-  if (cp->fd == -1)
-    delete_child (cp);
-}
-
-/* Wait for any of our existing child processes to die
-   When it does, close its handle
-   Return the pid and fill in the status if non-NULL.  */
-
-int 
-sys_wait (int *status)
-{
-  DWORD active, retval;
-  int nh;
-  int pid;
-  child_process *cp, *cps[MAX_CHILDREN];
-  HANDLE wait_hnd[MAX_CHILDREN];
-  
-  nh = 0;
-  if (dead_child != NULL)
-    {
-      /* We want to wait for a specific child */
-      wait_hnd[nh] = dead_child->procinfo.hProcess;
-      cps[nh] = dead_child;
-      if (!wait_hnd[nh]) abort ();
-      nh++;
-      active = 0;
-      goto get_result;
-    }
-  else
-    {
-      for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
-	/* some child_procs might be sockets; ignore them */
-	if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess)
-	  {
-	    wait_hnd[nh] = cp->procinfo.hProcess;
-	    cps[nh] = cp;
-	    if (!wait_hnd[nh]) abort (); /* Sync with FSF Emacs 19.34.6 note: only in XEmacs */
-	    nh++;
-	  }
-    }
-  
-  if (nh == 0)
-    {
-      /* Nothing to wait on, so fail */
-      errno = ECHILD;
-      return -1;
-    }
-  
-  do
-    {
-      /* Check for quit about once a second. */
-      QUIT;
-      active = WaitForMultipleObjects (nh, wait_hnd, FALSE, 1000);
-    } while (active == WAIT_TIMEOUT);
-
-  if (active == WAIT_FAILED)
-    {
-      errno = EBADF;
-      return -1;
-    }
-  else if (active >= WAIT_OBJECT_0 &&
-	   active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
-    {
-      active -= WAIT_OBJECT_0;
-    }
-  else if (active >= WAIT_ABANDONED_0 &&
-	   active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
-    {
-      active -= WAIT_ABANDONED_0;
-    }
-  else
-    abort ();
-  
-get_result:
-  if (!GetExitCodeProcess (wait_hnd[active], &retval))
-    {
-      DebPrint (("Wait.GetExitCodeProcess failed with %lu\n",
-		 GetLastError ()));
-      retval = 1;
-    }
-  if (retval == STILL_ACTIVE)
-    {
-      /* Should never happen */
-      DebPrint (("Wait.WaitForMultipleObjects returned an active process\n"));
-      errno = EINVAL;
-      return -1;
-    }
-
-  /* Massage the exit code from the process to match the format expected
-     by the WIFSTOPPED et al macros in syswait.h.  Only WIFSIGNALED and
-     WIFEXITED are supported; WIFSTOPPED doesn't make sense under NT.  */
-
-  if (retval == STATUS_CONTROL_C_EXIT)
-    retval = SIGINT;
-  else
-    retval <<= 8;
-  
-  cp = cps[active];
-  pid = cp->pid;
-#ifdef FULL_DEBUG
-  DebPrint (("Wait signaled with process pid %d\n", cp->pid));
-#endif
-
-  if (status)
-    {
-      *status = retval;
-    }
-  else if (synch_process_alive)
-    {
-      synch_process_alive = 0;
-
-      /* Report the status of the synchronous process.  */
-      if (WIFEXITED (retval))
-	synch_process_retcode = WRETCODE (retval);
-      else if (WIFSIGNALED (retval))
-	{
-	  int code = WTERMSIG (retval);
-	  char *signame = 0;
-	  
-	  if (code < NSIG)
-	    {
-	      /* Suppress warning if the table has const char *.  */
-	      signame = (char *) sys_siglist[code];
-	    }
-	  if (signame == 0)
-	    signame = "unknown";
-
-	  synch_process_death = signame;
-	}
-
-      reap_subprocess (cp);
-    }
-  
-  reap_subprocess (cp);
-  
-  return pid;
-}
-
 void
 win32_executable_type (char * filename, int * is_dos_app, int * is_cygnus_app)
 {