>>>> "Craig" == Craig Lanning
<CraigL(a)DyCon.com> writes:
Craig> This doesn't work for me on Win98 (mingw32). It actually
Craig> makes things worse.
Hello Craig, thanks for the feedback.
I am working on an improved patch.
The issue seems to be that the process may be gone before my patch
even gets the process handle from the process ID.
The new patch, which seems to work fine so far, determines the process
handle right after creating the new process and passes a process
HANDLE to wait_for_termination on WindowsNT.
Thanks for testing and sorry for the breakage.
Regards,
Adrian
This is the current state of my patch against 21.2-b19, which works
fine for me.
I'll submit it with ChangeLog after more testing in 21.2-b19 and
21.1.7.
Best regards,
Adrian
Index: src/callproc.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/callproc.c,v
retrieving revision 1.29.2.6
diff -u -r1.29.2.6 callproc.c
--- callproc.c 1999/05/01 05:13:23 1.29.2.6
+++ callproc.c 1999/10/14 02:13:55
@@ -114,7 +114,7 @@
/* #### "c-G" -- need non-consing Single-key-description */
message ("Waiting for process to die...(type C-g again to kill it
instantly)");
- wait_for_termination (pid);
+ wait_for_termination (OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid));
/* "Discard" the unwind protect. */
XCAR (fdpid) = Qnil;
@@ -170,6 +170,9 @@
Lisp_Object infile, buffer, current_dir, display, path;
int fd[2];
int filefd;
+#ifdef WINDOWSNT
+ HANDLE pHandle;
+#endif
int pid;
char buf[16384];
char *bufptr = buf;
@@ -358,7 +361,8 @@
fork_error = Qnil;
#ifdef WINDOWSNT
pid = child_setup (filefd, fd1, fd_error, new_argv,
- (char *) XSTRING_DATA (current_dir));
+ (char *) XSTRING_DATA (current_dir));
+ pHandle = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid);
#else /* not WINDOWSNT */
pid = fork ();
@@ -507,7 +511,7 @@
QUIT;
/* Wait for it to terminate, unless it already has. */
- wait_for_termination (pid);
+ wait_for_termination (pHandle);
/* Don't kill any children that the subprocess may have left behind
when exiting. */
Index: src/ntproc.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/ntproc.c,v
retrieving revision 1.14.2.10
diff -u -r1.14.2.10 ntproc.c
--- ntproc.c 1999/10/10 12:40:13 1.14.2.10
+++ ntproc.c 1999/10/14 02:13:59
@@ -457,7 +457,7 @@
#endif
*pPid = cp->pid;
-
+
return TRUE;
EH_Fail:
Index: src/sysdep.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/sysdep.c,v
retrieving revision 1.32.2.7
diff -u -r1.32.2.7 sysdep.c
--- sysdep.c 1999/07/05 05:56:44 1.32.2.7
+++ sysdep.c 1999/10/14 02:14:09
@@ -234,8 +234,11 @@
#endif /* NO_SUBPROCESSES */
-void
-wait_for_termination (int pid)
+#ifdef WINDOWSNT
+void wait_for_termination (HANDLE pid)
+#else
+void wait_for_termination (int pid)
+#endif
{
/* #### With the new improved SIGCHLD handling stuff, there is much
less danger of race conditions and some of the comments below
@@ -345,6 +348,36 @@
Since implementations may add their own error indicators on top,
we ignore it by default. */
+#elif defined (WINDOWSNT)
+ int ret = 0, status = 0;
+ if (pid == NULL) {
+ /*
+ * If the process is gone, it has probably been terminated. APA
+ */
+ stderr_out ("wait_for_termination.OpenProcess returns NULL GetLastError () %d
for pid %d\n", GetLastError (), (int)pid);
+ synch_process_alive = 0;
+ synch_process_death = signal_name (SIGTERM);
+ } else {
+ do {
+ QUIT;
+ ret = GetExitCodeProcess(pid, &status);
+ } while (status == STILL_ACTIVE);
+ if (ret) {
+ synch_process_alive = 0;
+ synch_process_retcode = status;
+ }
+ else {
+ /*
+ * GetExitCodeProcess() didn't return a valid exit status,
+ * nothing to do. APA
+ */
+ stderr_out ("wait_for_termination.GetExitCodeProcess status %d GetLastError ()
%d for pid %d\n", status, GetLastError (), (int)pid);
+ }
+ if (!CloseHandle(pid)) {
+ stderr_out ("wait_for_termination.CloseHandle GetLastError () %d for pid
%d\n",
+ GetLastError (), (int)pid);
+ }
+ }
#elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL)
&& defined (SIGCHLD)
while (1)
{
@@ -376,7 +409,7 @@
Try defining BROKEN_WAIT_FOR_SIGNAL. */
EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
}
-#else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
+#else /* not HAVE_WAITPID and not WINDOWSNT and (not EMACS_BLOCK_SIGNAL or
BROKEN_WAIT_FOR_SIGNAL) */
/* This approach is kind of cheesy but is guaranteed(?!) to work
for all systems. */
while (1)
@@ -578,7 +611,11 @@
static void
sys_subshell (void)
{
+#ifdef WINDOWSNT
+ HANDLE pid;
+#else
int pid;
+#endif
struct save_signal saved_handlers[5];
Lisp_Object dir;
unsigned char *str = 0;
@@ -617,7 +654,7 @@
xyzzy:
#ifdef WINDOWSNT
- pid = -1;
+ pid = NULL;
#else /* not WINDOWSNT */
pid = fork ();
@@ -651,7 +688,7 @@
#ifdef WINDOWSNT
/* Waits for process completion */
pid = _spawnlp (_P_WAIT, sh, sh, NULL);
- if (pid == -1)
+ if (pid == NULL)
write (1, "Can't execute subshell", 22);
#else /* not WINDOWSNT */
Index: src/sysdep.h
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/sysdep.h,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 sysdep.h
--- sysdep.h 1998/12/05 16:56:31 1.11.2.1
+++ sysdep.h 1999/10/14 02:14:10
@@ -48,7 +48,12 @@
/* Wait for subprocess with process id `pid' to terminate and
make sure it will get eliminated (not remain forever as a zombie) */
+#ifdef WINDOWSNT
+#include <windows.h>
+void wait_for_termination (HANDLE pid);
+#else
void wait_for_termination (int pid);
+#endif
/* flush any pending output
* (may flush input as well; it does not matter the way we use it)
cvs server: Diffing src/m
cvs server: Diffing src/s
cvs server: Diffing tests
cvs server: Diffing tests/DLL
cvs server: Diffing tests/Dnd
cvs server: Diffing tests/automated
cvs server: Diffing tests/mule
cvs server: Diffing tests/tooltalk