apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/include apr_thread_proc.h
Date Mon, 24 Feb 2003 21:28:35 GMT
wrowe       2003/02/24 13:28:34

  Modified:    misc/unix otherchild.c
               include  apr_thread_proc.h
  Log:
    Several good changes.  We replaced the following functions:
  
      apr_proc_other_child_check [Unix]
          -> apr_proc_other_child_refresh_all(APR_OC_REASON_RESTART);
      apr_proc_other_child_check [Win32]
          -> apr_proc_other_child_refresh_all(APR_OC_REASON_RUNNING);
  
      apr_proc_other_child_read [Unix MPMs]
          -> apr_proc_other_child_alert(pid, APR_OC_REASON_DEATH
  
    and introduce a single checkup flavor apr_proc_other_child_refresh
    to update just a single child process.
  
    _alert() is an assertion that some health transition just occurred,
    while _refresh() checks the health and provides notification to any
    still-running processes.
  
    This code is nominially vetted, but I'm bringing it back down on OSX
  
    after this commit to begin vetting the Unix side.  Helpers welcomed!!!
  
    Now it's possible for the MPMs to be rewritten so they are legible,
    however the patch is binary compatible.
  
    Finally, we always export all entry points even if they aren't implemented
    to ensure binary compatibility.
  
  Revision  Changes    Path
  1.32      +117 -65   apr/misc/unix/otherchild.c
  
  Index: otherchild.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/otherchild.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- otherchild.c	7 Jan 2003 00:52:55 -0000	1.31
  +++ otherchild.c	24 Feb 2003 21:28:34 -0000	1.32
  @@ -90,7 +90,7 @@
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *pid,
  +APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
                        void (*maintenance) (int reason, void *, int status),
                        void *data, apr_file_t *write_fd, apr_pool_t *p)
   {
  @@ -98,7 +98,7 @@
   
       ocr = apr_palloc(p, sizeof(*ocr));
       ocr->p = p;
  -    ocr->proc = pid;
  +    ocr->proc = proc;
       ocr->maintenance = maintenance;
       ocr->data = data;
       if (write_fd == NULL) {
  @@ -138,91 +138,143 @@
       other_child_cleanup(data);
   }
   
  -APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *pid, int status)
  +APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
  +                                                     int reason,
  +                                                     int status)
   {
       apr_other_child_rec_t *ocr, *nocr;
   
       for (ocr = other_children; ocr; ocr = nocr) {
           nocr = ocr->next;
  -        if (ocr->proc->pid != pid->pid)
  +        if (ocr->proc->pid != proc->pid)
               continue;
   
           ocr->proc = NULL;
  -        (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
  -        return 0;
  +        (*ocr->maintenance) (reason, ocr->data, status);
  +        return APR_SUCCESS;
       }
  -    return APR_CHILD_NOTDONE;
  +    return APR_EPROC_UNKNOWN;
   }
  -#ifdef WIN32
  -/*
  - * Run the list of Other Children and restart the ones that have died.
  - * ToDo: APR'ize this function so it will serve Unix and Win32.
  - * Not clear to me how to make the Win32 function behave exactly like
  - * the non-win32 branch. wgs
  - */
  -APR_DECLARE(void) apr_proc_other_child_check(void)
  -{
  -    apr_other_child_rec_t *ocr, *nocr;
  -    DWORD status;
   
  +APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
  +                                               int reason)
  +{
       /* Todo: 
  -     * Implement code to detect if a pipe is still alive on Windows.
  +     * Implement code to detect if pipes are still alive.
        */
  -    if (other_children == NULL)
  -        return;
  +#ifdef WIN32
  +    DWORD status;
   
  -    for (ocr = other_children; ocr; ocr = nocr) {
  -        nocr = ocr->next;
  -        if (ocr->proc == NULL)
  -            continue;
  +    if (ocr->proc == NULL)
  +        return;
   
  -        if (!ocr->proc->hproc) {
  -            /* Already mopped up, perhaps we apr_proc_kill'ed it */
  -            (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, -1);
  -        }
  -        else if (!GetExitCodeProcess(ocr->proc->hproc, &status)) {
  -            CloseHandle(ocr->proc->hproc);
  -            ocr->proc = NULL;
  -            (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
  -        }
  -        else if (status == STILL_ACTIVE) {
  -            (*ocr->maintenance) (APR_OC_REASON_RESTART, ocr->data, -1);
  -        }
  -        else {
  -            CloseHandle(ocr->proc->hproc);
  -            ocr->proc->hproc = NULL;
  -            ocr->proc = NULL;
  -            (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
  -        }
  +    if (!ocr->proc->hproc) {
  +        /* Already mopped up, perhaps we apr_proc_kill'ed it */
  +        (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, -1);
       }
  -}
  +    else if (!GetExitCodeProcess(ocr->proc->hproc, &status)) {
  +        CloseHandle(ocr->proc->hproc);
  +        ocr->proc = NULL;
  +        (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
  +    }
  +    else if (status == STILL_ACTIVE) {
  +        (*ocr->maintenance) (reason, ocr->data, -1);
  +    }
  +    else {
  +        CloseHandle(ocr->proc->hproc);
  +        ocr->proc->hproc = NULL;
  +        ocr->proc = NULL;
  +        (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
  +    }
  +
   #else /* ndef Win32 */
  -APR_DECLARE(void) apr_proc_other_child_check(void)
  -{
  -    apr_other_child_rec_t *ocr, *nocr;
       pid_t waitret; 
       int status;
   
  -    for (ocr = other_children; ocr; ocr = nocr) {
  -        nocr = ocr->next;
  -        if (ocr->proc == NULL)
  -            continue;
  +    if (ocr->proc == NULL)
  +        return;
   
  -        waitret = waitpid(ocr->proc->pid, &status, WNOHANG);
  -        if (waitret == ocr->proc->pid) {
  -            ocr->proc = NULL;
  -            (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
  -        }
  -        else if (waitret == 0) {
  -            (*ocr->maintenance) (APR_OC_REASON_RESTART, ocr->data, -1);
  -        }
  -        else if (waitret == -1) {
  -            /* uh what the heck? they didn't call unregister? */
  -            ocr->proc = NULL;
  -            (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
  -        }
  +    waitret = waitpid(ocr->proc->pid, &status, WNOHANG);
  +    if (waitret == ocr->proc->pid) {
  +        ocr->proc = NULL;
  +        (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
  +    }
  +    else if (waitret == 0) {
  +        (*ocr->maintenance) (reason, ocr->data, -1);
  +    }
  +    else if (waitret == -1) {
  +        /* uh what the heck? they didn't call unregister? */
  +        ocr->proc = NULL;
  +        (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
       }
  -}
   #endif
  +}
  +
  +APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason)
  +{
  +    apr_other_child_rec_t *ocr, *next_ocr;
  +
  +    for (ocr = other_children; ocr; ocr = next_ocr) {
  +        next_ocr = ocr->next;
  +        apr_proc_other_child_refresh(ocr, reason);
  +    }
  +}
  +
  +#else /* !APR_HAS_OTHER_CHILD */
  +
  +APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
  +                     void (*maintenance) (int reason, void *, int status),
  +                     void *data, apr_file_t *write_fd, apr_pool_t *p)
  +{
  +    return;
  +}
  +
  +APR_DECLARE(void) apr_proc_other_child_unregister(void *data)
  +{
  +    return;
  +}
  +
  +APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
  +                                                     int reason,
  +                                                     int status)
  +{
  +    return APR_ENOTIMPL;
  +}
  +
  +APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
  +                                               int reason)
  +{
  +    return;
  +}
  +
  +APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason)
  +{
  +    return;
  +}
   
   #endif /* APR_HAS_OTHER_CHILD */
  +
  +
  +/* XXX: deprecated for removal in 1.0
  + * The checks behaved differently between win32 and unix, while
  + * the old win32 code did a health check, the unix code called
  + * other_child_check only at restart.
  + */
  +APR_DECLARE(void) apr_proc_other_child_check(void)
  +{
  +#ifdef WIN32
  +    apr_proc_other_child_refresh_all(APR_OC_REASON_RUNNING);
  +#else
  +    apr_proc_other_child_refresh_all(APR_OC_REASON_RESTART);
  +#endif
  +}
  +
  +/* XXX: deprecated for removal in 1.0
  + * This really didn't test any sort of read - it simply notified
  + * the maintenance function that the process had died.
  + */
  +APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status)
  +{
  +    return apr_proc_other_child_alert(proc, APR_OC_REASON_DEATH, status);
  +}
  +
  
  
  
  1.93      +51 -19    apr/include/apr_thread_proc.h
  
  Index: apr_thread_proc.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_thread_proc.h,v
  retrieving revision 1.92
  retrieving revision 1.93
  diff -u -r1.92 -r1.93
  --- apr_thread_proc.h	7 Feb 2003 21:02:30 -0000	1.92
  +++ apr_thread_proc.h	24 Feb 2003 21:28:34 -0000	1.93
  @@ -147,6 +147,10 @@
                                              * kill the child) */
   #define APR_OC_REASON_LOST          4     /**< somehow the child exited without
                                              * us knowing ... buggy os? */
  +#define APR_OC_REASON_RUNNING       5     /**< a health check is occuring, 
  +                                           * for most maintainence functions
  +                                           * this is a no-op.
  +                                           */
   /** @} */
   #endif /* APR_HAS_OTHER_CHILD */
   
  @@ -610,6 +614,8 @@
    *                          child is dead or not.
    * </PRE>
    * @param p Pool to allocate child information out of.
  + * @bug Passing proc as a *proc rather than **proc was an odd choice
  + * for some platforms... this should be revisited in 1.0
    */
   APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
                                                     int *exitcode,
  @@ -628,21 +634,24 @@
    */
   APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
   
  -#if APR_HAS_OTHER_CHILD
  -
   /**
  - * Register an other_child -- a child which must be kept track of so 
  - * that the program knows when it has died or disappeared.
  - * @param pid pid is the pid of the child.
  + * Register an other_child -- a child associated to its registered 
  + * maintence callback.  This callback is invoked when the process
  + * dies, is disconnected or disappears.
  + * @param proc The child process to register.
    * @param maintenance maintenance is a function that is invoked with a 
    *                    reason and the data pointer passed here.
  - * @param data The data to pass to the maintenance function.
  + * @param data Opaque context data passed to the maintenance function.
    * @param write_fd An fd that is probed for writing.  If it is ever unwritable
    *                 then the maintenance is invoked with reason 
    *                 OC_REASON_UNWRITABLE.
    * @param p The pool to use for allocating memory.
  + * @bug write_fd duplicates the proc->out stream, it's really redundant
  + * and should be replaced in the APR 1.0 API with a bitflag of which
  + * proc->in/out/err handles should be health checked.
  + * @bug no platform currently tests the pipes health.
    */
  -APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *pid, 
  +APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc, 
                                              void (*maintenance) (int reason, 
                                                                   void *, 
                                                                   int status),
  @@ -650,7 +659,7 @@
                                              apr_pool_t *p);
   
   /**
  - * Stop watching the specified process.
  + * Stop watching the specified other child.  
    * @param data The data to pass to the maintenance function.  This is
    *             used to find the process to unregister.
    * @warning Since this can be called by a maintenance function while we're
  @@ -661,20 +670,43 @@
   APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
   
   /**
  - * Check on the specified process.  If it is gone, call the maintenance 
  - * function.
  - * @param pid The process to check.
  + * Notify the maintenance callback of a registered other child process
  + * that application has detected an event, such as death.
  + * @param proc The process to check.
    * @param status The status to pass to the maintenance function.
  + * @remark An example of code using this behavior;
  + * <pre>
  + * rv = apr_proc_wait_all_procs(&proc, &exitcode, &status, APR_WAIT, p);
  + * if (APR_STATUS_IS_CHILD_DONE(rv)) {
  + * #if APR_HAS_OTHER_CHILD
  + *     if (apr_proc_other_child_alert(&proc, APR_OC_REASON_DEATH, status)
  + *             == APR_SUCCESS) {
  + *         ;  (already handled)
  + *     }
  + *     else
  + * #endif
  + *         [... handling non-otherchild processes death ...]
  + * </pre>
  + */
  +APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc, 
  +                                                     int reason,
  +                                                     int status);
  +
  +APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
  +                                               int reason);
  +
  +APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
  +
  +/** @deprecated 
  + * @see apr_proc_other_child_refresh_all(APR_OC_REASON_RESTART)
    */
  -APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *pid, int status);
  +APR_DECLARE(void) apr_proc_other_child_check(void);
   
  -/**
  - * Loop through all registered other_children and call the appropriate 
  - * maintenance function when necessary.
  +/** @deprecated 
  + * @see apr_proc_other_child_alert()
    */
  -APR_DECLARE(void) apr_proc_other_child_check(void); 
  +APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status);
   
  -#endif /* APR_HAS_OTHER_CHILD */
   
   /** 
    * Terminate a process.
  @@ -686,7 +718,7 @@
   /**
    * Register a process to be killed when a pool dies.
    * @param a The pool to use to define the processes lifetime 
  - * @param pid The process to register
  + * @param proc The process to register
    * @param how How to kill the process, one of:
    * <PRE>
    *         APR_KILL_NEVER         -- process is never sent any signals
  @@ -696,7 +728,7 @@
    *         APR_KILL_ONLY_ONCE     -- send SIGTERM and then wait
    * </PRE>
    */
  -APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *pid,
  +APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
                                              apr_kill_conditions_e how);
   
   #if APR_HAS_THREADS 
  
  
  

Mime
View raw message