diff src/process-nt.c @ 359:8e84bee8ddd0 r21-1-9

Import from CVS: tag r21-1-9
author cvs
date Mon, 13 Aug 2007 10:57:55 +0200
parents 182f72e8cd0d
children 972bbb6d6ca2
line wrap: on
line diff
--- a/src/process-nt.c	Mon Aug 13 10:57:07 2007 +0200
+++ b/src/process-nt.c	Mon Aug 13 10:57:55 2007 +0200
@@ -49,6 +49,7 @@
 struct nt_process_data
 {
   HANDLE h_process;
+  int need_enable_child_signals;
 };
 
 #define NT_DATA(p) ((struct nt_process_data*)((p)->process_data))
@@ -415,7 +416,7 @@
 		   Lisp_Object *argv, int nargv,
 		   Lisp_Object program, Lisp_Object cur_dir)
 {
-  HANDLE hmyshove, hmyslurp, hprocin, hprocout;
+  HANDLE hmyshove, hmyslurp, hprocin, hprocout, hprocerr;
   LPTSTR command_line;
   BOOL do_io, windowed;
   char *proc_env;
@@ -466,6 +467,10 @@
       CreatePipe (&hprocin, &hmyshove, &sa, 0);
       CreatePipe (&hmyslurp, &hprocout, &sa, 0);
 
+      /* Duplicate the stdout handle for use as stderr */
+      DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(), &hprocerr,
+       0, TRUE, DUPLICATE_SAME_ACCESS);
+
       /* Stupid Win32 allows to create a pipe with *both* ends either
 	 inheritable or not. We need process ends inheritable, and local
 	 ends not inheritable. */
@@ -593,7 +598,7 @@
       {
 	si.hStdInput = hprocin;
 	si.hStdOutput = hprocout;
-	si.hStdError = hprocout;
+       si.hStdError = hprocerr;
 	si.dwFlags |= STARTF_USESTDHANDLES;
       }
 
@@ -608,6 +613,7 @@
 	/* These just have been inherited; we do not need a copy */
 	CloseHandle (hprocin);
 	CloseHandle (hprocout);
+       CloseHandle (hprocerr);
       }
     
     /* Handle process creation failure */
@@ -634,12 +640,18 @@
 	CloseHandle (pi.hProcess);
       }
 
-    if (!windowed)
-      enable_child_signals (pi.hProcess);
-
     ResumeThread (pi.hThread);
     CloseHandle (pi.hThread);
 
+    /* Remember to enable child signals later if this is not a windowed
+       app.  Can't do it right now because that screws up the MKS Toolkit
+       shell. */
+    if (!windowed)
+      {
+       NT_DATA(p)->need_enable_child_signals = 10;
+       kick_status_notify ();
+      }
+
     /* Hack to support Windows 95 negative pids */
     return ((int)pi.dwProcessId < 0
 	    ? -(int)pi.dwProcessId : (int)pi.dwProcessId);
@@ -658,6 +670,18 @@
 nt_update_status_if_terminated (struct Lisp_Process* p)
 {
   DWORD exit_code;
+
+  if (NT_DATA(p)->need_enable_child_signals > 1)
+    {
+      NT_DATA(p)->need_enable_child_signals -= 1;
+      kick_status_notify ();
+    }
+  else if (NT_DATA(p)->need_enable_child_signals == 1)
+    {
+      enable_child_signals(NT_DATA(p)->h_process);
+      NT_DATA(p)->need_enable_child_signals = 0;
+    }
+
   if (GetExitCodeProcess (NT_DATA(p)->h_process, &exit_code)
       && exit_code != STILL_ACTIVE)
     {
@@ -759,6 +783,14 @@
 {
   struct Lisp_Process *p = XPROCESS (proc);
 
+  /* Enable child signals if necessary.  This may lose the first
+     but it's better than nothing. */
+  if (NT_DATA(p)->need_enable_child_signals > 0)
+    {
+      enable_child_signals(NT_DATA(p)->h_process);
+      NT_DATA(p)->need_enable_child_signals = 0;
+    }
+
   /* Signal error if SIGNO cannot be sent */
   validate_signal_number (signo);