Hello Reviewers, hello Windows NT native experts!
I wouldn't dare to send this patch to xemacs-patches yet.
However, I have a first working[1] implementation for (call-process ...)
to return the correct exit status of the child process called.
It is a simple upgrade of the wait_for_termination(int pid) function
in src/sysdep.c conditionalized on WINDOWSNT.
Please test it, rip it apart and rebuild it, and send me suggestions
(copying xemacs-beta and/or xemacs-nt since my mail server is having
problems).
A Weak Spot:
When OpenProcess() returns an invalid process handle I fake a signal
termination signal.
synch_process_death = signal_name (SIGTERM);
This is nothing than a wild guess, but better than setting
synch_process_retcode = status;
I have tested this using external cygnus executables "sleep" and
"grep" as follows.
Patch against latest CVS source of 21.2-b19 is at end.
Thanks in advance for any help!
Best regards,
Adrian
;;; Sleeping for 3 seconds, then returns 0.
(apply 'call-process "sleep" nil nil nil (list "3"))
0
;;; Trying to sleep for 30 seconds, but killed via Windows NT Task
;;; Manager.
(apply 'call-process "sleep" nil nil nil (list "30"))
"software termination signal from kill"
;;; Looking for drivers in sysem file succeeds, returning 0.
(apply 'call-process "grep" nil nil nil
(list "drivers" "c:\\winnt\\system.ini"))
0
;;; Looking for passangers in sysem file fails, returning 1.
(apply 'call-process "grep" nil nil nil
(list "passangers" "c:\\winnt\\system.ini"))
1
;;; Looking for drivers in invalid file fails, returning 2.
(apply 'call-process "grep" nil nil nil
(list "drivers" "c:\winnt\system.ini"))
2
cvs server: Diffing src
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/11 14:13:46
@@ -345,6 +345,36 @@
Since implementations may add their own error indicators on top,
we ignore it by default. */
+#elif defined (WINDOWSNT)
+ int ret = 0, status = 0;
+ HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid);
+ if (hProcess == NULL) {
+ /*
+ * If the process is gone, it has probably been terminated. APA
+ */
+ synch_process_alive = 0;
+ synch_process_death = signal_name (SIGTERM);
+ } else {
+ do {
+ QUIT;
+ ret = GetExitCodeProcess(hProcess, &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 return %d for pid %d\n", status, GetLastError (), pid);
+ }
+ if (!CloseHandle(hProcess)) {
+ stderr_out ("wait_for_termination.CloseHandle return %d for pid %d\n",
+ GetLastError (), pid);
+ }
+ }
#elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
while (1)
{
cvs server: Diffing src/m
cvs server: Diffing src/s
Footnotes:
[1] driven by my need for ediff-directories to work in Windows NT
native XEmacs. It does now.