apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bnicho...@apache.org
Subject cvs commit: apr/include/arch/netware apr_arch_threadproc.h
Date Tue, 11 Feb 2003 17:15:58 GMT
bnicholes    2003/02/11 09:15:58

  Modified:    threadproc/netware proc.c
               include/arch/netware apr_arch_threadproc.h
  Log:
  Implemented apr_proc_wait and apr_wait_all_procs for NetWare
  
  Revision  Changes    Path
  1.23      +60 -34    apr/threadproc/netware/proc.c
  
  Index: proc.c
  ===================================================================
  RCS file: /home/cvs/apr/threadproc/netware/proc.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- proc.c	7 Feb 2003 21:02:31 -0000	1.22
  +++ proc.c	11 Feb 2003 17:15:58 -0000	1.23
  @@ -62,8 +62,14 @@
   apr_status_t apr_netware_proc_cleanup(void *theproc)
   {
       apr_proc_t *proc = theproc;
  +    int exit_int;
  +    int waitpid_options = WUNTRACED | WNOHANG;
   
  -	NXVmDestroy(proc->pid);
  +    if (proc->pid > 0) {
  +        waitpid(proc->pid, &exit_int, waitpid_options);
  +    }
  +
  +/*	NXVmDestroy(proc->pid); */
       return APR_SUCCESS;
   }
   
  @@ -76,6 +82,7 @@
       }
       (*new)->pool = pool;
       (*new)->cmdtype = APR_PROGRAM;
  +/*	(*new)->detached = 1;*/
       return APR_SUCCESS;
   
   }
  @@ -318,7 +325,8 @@
       /* attr->detached and PROC_DETACHED do not mean the same thing.  attr->detached
means
        * start the NLM in a separate address space.  PROC_DETACHED means don't wait for the
        * NLM to unload by calling wait() or waitpid(), just clean up */
  -    addr_space = (attr->detached ? 0 : PROC_CURRENT_SPACE) | PROC_LOAD_SILENT | PROC_DETACHED;
  +    addr_space = PROC_LOAD_SILENT | ((attr->cmdtype == APR_PROGRAM_ENV) ? 0 : PROC_CURRENT_SPACE);
  +    addr_space |= (attr->detached ? PROC_DETACHED : 0);
   
       if (attr->currdir) {
           char *fullpath = NULL;
  @@ -353,8 +361,8 @@
       }
   
   
  -//    apr_pool_cleanup_register(pool, (void *)newproc, apr_netware_proc_cleanup,
  -//        apr_pool_cleanup_null);
  +    apr_pool_cleanup_register(pool, (void *)newproc, apr_netware_proc_cleanup,
  +        apr_pool_cleanup_null);
   
       return APR_SUCCESS;
   }
  @@ -365,52 +373,70 @@
                                                     apr_wait_how_e waithow,
                                                     apr_pool_t *p)
   {
  -#if 0
  +    proc->pid = -1;
  +    return apr_proc_wait(proc, exitcode, exitwhy, waithow);
  +}
  +
  +APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
  +                                        int *exitcode, apr_exit_why_e *exitwhy,
  +                                        apr_wait_how_e waithow)
  +{
  +    pid_t pstatus;
       int waitpid_options = WUNTRACED;
  +    int exit_int;
  +    int ignore;
  +    apr_exit_why_e ignorewhy;
  +
  +    if (exitcode == NULL) {
  +        exitcode = &ignore;
  +    }
  +
  +    if (exitwhy == NULL) {
  +        exitwhy = &ignorewhy;
  +    }
   
       if (waithow != APR_WAIT) {
           waitpid_options |= WNOHANG;
       }
   
  -    if ((proc->pid = waitpid(-1, status, waitpid_options)) > 0) {
  +    /* If the pid is 0 then the process was started detached. There 
  +       is no need to wait since there is nothing to wait for on a 
  +       detached process.  Starting a process as non-detached and
  +       then calling wait or waitpid could cause the thread to hang.
  +       The reason for this is because NetWare does not have a way 
  +       to kill or even signal a process to be killed.  Starting 
  +       all processes as detached avoids the possibility of a 
  +       thread hanging. */
  +    if (proc->pid == 0) {
  +        *exitwhy = APR_PROC_EXIT;
  +        *exitcode = 0;
           return APR_CHILD_DONE;
       }
  -    else if (proc->pid == 0) {
  -        return APR_CHILD_NOTDONE;
  -    }
  -    return errno;
  -#else
  -    return APR_ENOTIMPL;
  -#endif
  -} 
   
  -APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
  -                                        int *exitcode, apr_exit_why_e *exitwhy,
  -                                        apr_wait_how_e waithow)
  -{
  -#if 0
  -    pid_t status;
  +    if ((pstatus = waitpid(proc->pid, &exit_int, waitpid_options)) > 0) {
  +        proc->pid = pstatus;
   
  -    if (waithow == APR_WAIT) {
  -        if ((status = waitpid(proc->pid, NULL, WUNTRACED)) > 0) {
  -            return APR_CHILD_DONE;
  -        }
  -        else if (status == 0) {
  -            return APR_CHILD_NOTDONE;
  +        if (WIFEXITED(exit_int)) {
  +            *exitwhy = APR_PROC_EXIT;
  +            *exitcode = WEXITSTATUS(exit_int);
  +        }
  +        else if (WIFSIGNALED(exit_int)) {
  +            *exitwhy = APR_PROC_SIGNAL;
  +            *exitcode = WTERMSIG(exit_int);
  +        }
  +        else {
  +            /* unexpected condition */
  +            return APR_EGENERAL;
           }
  -        return errno;
  -    }
  -    if ((status = waitpid(proc->pid, NULL, WUNTRACED | WNOHANG)) > 0) {
  +
           return APR_CHILD_DONE;
       }
  -    else if (status == 0) {
  +    else if (pstatus == 0) {
           return APR_CHILD_NOTDONE;
       }
  +
       return errno;
  -#else
  -    return APR_ENOTIMPL;
  -#endif
  -} 
  +}
   
   APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32_t what,

                             struct rlimit *limit)
  
  
  
  1.2       +3 -2      apr/include/arch/netware/apr_arch_threadproc.h
  
  Index: apr_arch_threadproc.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/netware/apr_arch_threadproc.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_arch_threadproc.h	6 Jan 2003 23:44:23 -0000	1.1
  +++ apr_arch_threadproc.h	11 Feb 2003 17:15:58 -0000	1.2
  @@ -55,12 +55,13 @@
   #include "apr.h"
   #include "apr_thread_proc.h"
   #include "apr_file_io.h"
  -//srj #include "apr_portable.h"
  +
  +#include <sys/wait.h>
   
   #ifndef THREAD_PROC_H
   #define THREAD_PROC_H
   
  -#define SHELL_PATH "cmd.exe"
  +#define SHELL_PATH ""
   #define APR_DEFAULT_STACK_SIZE 65536
   
   struct apr_thread_t {
  
  
  

Mime
View raw message