Here is yet another patch.  When compared with the previous patch,
this one adds the native status to the parameter lists of
apr_proc_wait() and apr_proc_wait_all_procs().  Fewer MPM changes are
necessary.

missing: fix the doc in apr_thread_proc.h
         roll the changes into apr/threadproc/foo/proc.c, foo != unix

untested, but there isn't much to screw up

The interfaces are the important thing to look at.

Index: server/mpm_common.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm_common.c,v
retrieving revision 1.69
diff -u -r1.69 mpm_common.c
--- server/mpm_common.c 2001/09/21 14:29:33     1.69
+++ server/mpm_common.c 2001/10/18 17:31:01
@@ -124,7 +124,7 @@
                 continue;
 
             proc.pid = pid;
-            waitret = apr_proc_wait(&proc, NULL, APR_NOWAIT);
+            waitret = apr_proc_wait(&proc, NULL, NULL, NULL, APR_NOWAIT);
             if (waitret != APR_CHILD_NOTDONE) {
                 MPM_NOTE_CHILD_KILLED(i);
                 continue;
@@ -204,7 +204,7 @@
     if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) {
         wait_or_timeout_counter = 0;
     }
-    rv = apr_proc_wait_all_procs(ret, status, APR_NOWAIT, p);
+    rv = apr_proc_wait_all_procs(ret, NULL, NULL, status, APR_NOWAIT, p);
     if (APR_STATUS_IS_EINTR(rv)) {
         ret->pid = -1;
         return;
@@ -213,6 +213,7 @@
         return;
     }
 #ifdef NEED_WAITPID
+    /* wtf... ancient cruft? */
     if ((ret = reap_children(status)) > 0) {
         return;
     }
Index: srclib/apr/include/apr_thread_proc.h
===================================================================
RCS file: /home/cvs/apr/include/apr_thread_proc.h,v
retrieving revision 1.75
diff -u -r1.75 apr_thread_proc.h
--- srclib/apr/include/apr_thread_proc.h        2001/09/20 08:59:30     1.75
+++ srclib/apr/include/apr_thread_proc.h        2001/10/18 17:31:04
@@ -81,6 +81,7 @@
 
 typedef enum {APR_SHELLCMD, APR_PROGRAM} apr_cmdtype_e;
 typedef enum {APR_WAIT, APR_NOWAIT} apr_wait_how_e;
+typedef enum {APR_CHILD_NORMAL_EXIT, APR_CHILD_SIGNAL_EXIT} apr_exit_how_e;
 
 #define APR_NO_PIPE          0
 #define APR_FULL_BLOCK       1
@@ -481,11 +482,18 @@
 /**
  * Wait for a child process to die
  * @param proc The process handle that corresponds to the desired child 
process 
- * @param exitcode The returned exit status of the child, if a child process
- *                 dies. On platforms that don't support obtaining this
- *                 information, the exitcode parameter will be returned as
- *                 APR_ENOTIMPL. This parameter may be NULL if the exit code
- *                 is not needed.
+ * @parameter exithow How the child exited.  One of:
+ * <PRE>
+ *            APR_CHILD_NORMAL_EXIT  -- child exited normally
+ *            APR_CHILD_SIGNAL_EXIT  -- child exited due to an uncaught signal
+ * </PRE>
+ * This parameter may be NULL if the reason for exiting is not needed.
+ * @param exitcode_or_signal The returned exit status of the child, if a child 
+ *                 process died normally, or the signal number if the child 
+ *                 process died due to an uncaught signal.  On platforms that 
+ *                 don't support obtaining this information, the exitcode 
+ *                 parameter will be returned as APR_ENOTIMPL. This parameter 
+ *                 may be NULL if the exit code is not needed.
  * @param waithow How should we wait.  One of:
  * <PRE>
  *            APR_WAIT   -- block until the child process dies.
@@ -499,7 +507,9 @@
  * </PRE>
  */
 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc, 
-                                        apr_wait_t *exitcode,
+                                        apr_exit_how_e *exithow,
+                                        int *exitcode_or_signal,
+                                        apr_wait_t *native_status,
                                         apr_wait_how_e waithow);
 
 /**
@@ -507,9 +517,6 @@
  * about that child.
  * @param proc Pointer to NULL on entry, will be filled out with child's 
  *             information 
- * @param status The returned exit status of the child, if a child process dies
- *               On platforms that don't support obtaining this information, 
- *               the status parameter will be returned as APR_ENOTIMPL.
  * @param waithow How should we wait.  One of:
  * <PRE>
  *            APR_WAIT   -- block until the child process dies.
@@ -519,9 +526,11 @@
  * @param p Pool to allocate child information out of.
  */
 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
-                                             apr_wait_t *status,
-                                             apr_wait_how_e waithow,
-                                             apr_pool_t *p);
+                                                  apr_exit_how_e *exithow,
+                                                  int *exitcode_or_signal,
+                                                  apr_wait_t *native_status,
+                                                  apr_wait_how_e waithow,
+                                                  apr_pool_t *p);
 
 /**
  * Detach the process from the controlling terminal.
Index: srclib/apr/memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.113
diff -u -r1.113 apr_pools.c
--- srclib/apr/memory/unix/apr_pools.c  2001/09/28 15:22:35     1.113
+++ srclib/apr/memory/unix/apr_pools.c  2001/10/18 17:31:09
@@ -1505,7 +1505,7 @@
 #ifndef NEED_WAITPID
     /* Pick up all defunct processes */
     for (p = procs; p; p = p->next) {
-        if (apr_proc_wait(p->pid, NULL, APR_NOWAIT) != APR_CHILD_NOTDONE) {
+        if (apr_proc_wait(p->pid, NULL, NULL, NULL, APR_NOWAIT) != 
APR_CHILD_NOTDONE) {
             p->kill_how = kill_never;
         }
     }
@@ -1550,7 +1550,7 @@
     /* Now wait for all the signaled processes to die */
     for (p = procs; p; p = p->next) {
        if (p->kill_how != kill_never) {
-           (void) apr_proc_wait(p->pid, NULL, APR_WAIT);
+           (void) apr_proc_wait(p->pid, NULL, NULL, NULL, APR_WAIT);
        }
     }
 #ifdef WIN32
Index: srclib/apr/threadproc/unix/proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/proc.c,v
retrieving revision 1.49
diff -u -r1.49 proc.c
--- srclib/apr/threadproc/unix/proc.c   2001/09/21 16:14:50     1.49
+++ srclib/apr/threadproc/unix/proc.c   2001/10/18 17:31:12
@@ -362,37 +362,57 @@
 }
 
 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc, 
-                                                  apr_wait_t *status,
+                                                  apr_exit_how_e *exithow,
+                                                  int *exitcode_or_signal,
+                                                  apr_wait_t *native_status,
                                                   apr_wait_how_e waithow, 
                                                   apr_pool_t *p)
 {
     proc->pid = -1;
-    return apr_proc_wait(proc, status, waithow);
+    return apr_proc_wait(proc, exithow, exitcode_or_signal, native_status, 
+                         waithow);
 } 
 
 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc, 
-                                        apr_wait_t *exitcode,
+                                        apr_exit_how_e *exithow,
+                                        int *exitcode_or_signal,
+                                        apr_wait_t *native_status,
                                         apr_wait_how_e waithow)
 {
     pid_t pstatus;
-    int waitpid_options = WUNTRACED;
-    int exit_int;
+    int waitpid_options = 0;
+    int exit_int, ignored_exitcode_or_signal;
+    apr_exit_how_e ignored_exithow;
+    apr_wait_t ignored_native_status;
 
+    /* exithow and exitcode_or_signal and ignored_native_status are optional */
+    if (!exithow)
+        exithow = &ignored_exithow;
+    if (!exitcode_or_signal)
+        exitcode_or_signal = &ignored_exitcode_or_signal;
+    if (!native_status)
+        native_status = &ignored_native_status;
+
     if (waithow != APR_WAIT) {
         waitpid_options |= WNOHANG;
     }
     
     if ((pstatus = waitpid(proc->pid, &exit_int, waitpid_options)) > 0) {
-        if (proc->pid == -1) {
-            proc->pid = pstatus;
-        }
+        proc->pid = pstatus;
+        *native_status = exit_int;
         if (WIFEXITED(exit_int)) {
-            if (exitcode != NULL) {
-                *exitcode = WEXITSTATUS(exit_int);
-            }
-            return APR_CHILD_DONE;
+            *exithow = APR_CHILD_NORMAL_EXIT;
+            *exitcode_or_signal = WEXITSTATUS(exit_int);
+        }
+        else if (WIFSIGNALED(exit_int)) {
+            *exithow = APR_CHILD_SIGNAL_EXIT;
+            *exitcode_or_signal = WTERMSIG(exit_int);
+        }
+        else {
+            /* unexpected condition */
+            return APR_EGENERAL;
         }
-        return APR_CHILD_NOTDONE;
+        return APR_CHILD_DONE;
     }
     else if (pstatus == 0) {
         return APR_CHILD_NOTDONE;

-- 
Jeff Trawick | [EMAIL PROTECTED] | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Reply via email to