stoddard    00/01/27 19:10:53

  Modified:    src/lib/apr/include apr_win.h apr_winconfig.h
               src/lib/apr/lib apr_pools.c
  Log:
  Migrate free_proc_chain() for Windows to APR. Fix invalid handle exception
  when running CGI scripts.
  
  Revision  Changes    Path
  1.15      +1 -0      apache-2.0/src/lib/apr/include/apr_win.h
  
  Index: apr_win.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_win.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- apr_win.h 2000/01/26 05:56:38     1.14
  +++ apr_win.h 2000/01/28 03:10:49     1.15
  @@ -75,6 +75,7 @@
   #include <stdio.h>
   #include <time.h>
   #include <process.h>
  +#include <signal.h>
   
   #define ap_inline
   #define __attribute__(__x)
  
  
  
  1.4       +1 -1      apache-2.0/src/lib/apr/include/apr_winconfig.h
  
  Index: apr_winconfig.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_winconfig.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- apr_winconfig.h   2000/01/26 05:56:38     1.3
  +++ apr_winconfig.h   2000/01/28 03:10:49     1.4
  @@ -79,7 +79,6 @@
   #include <stdio.h>
   #include <time.h>
   
  -
   #define HAVE_SENDFILE 1
   
   /* Use this section to define all of the HAVE_FOO_H
  @@ -89,6 +88,7 @@
   #define HAVE_MALLOC_H 1
   #define HAVE_STDLIB_H 1
   #define HAVE_LIMITS_H 1
  +#define HAVE_SIGNAL_H 1
   
   typedef enum {APR_WIN_NT, APR_WIN_95, APR_WIN_98} ap_oslevel_e;
   
  
  
  
  1.30      +31 -53    apache-2.0/src/lib/apr/lib/apr_pools.c
  
  Index: apr_pools.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/lib/apr_pools.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- apr_pools.c       1999/12/13 20:42:18     1.29
  +++ apr_pools.c       2000/01/28 03:10:52     1.30
  @@ -73,6 +73,7 @@
   #include "apr_lib.h"
   #include "apr_lock.h"
   #include "misc.h"
  +
   #ifdef HAVE_SYS_STAT_H
   #include <sys/stat.h>
   #endif
  @@ -1248,7 +1249,6 @@
        * whatever it was we're cleaning up now.  This may involve killing
        * some of them off...
        */
  -
       struct process_chain *p;
       int need_timeout = 0;
       int status;
  @@ -1263,70 +1263,39 @@
        * don't waste any more cycles doing whatever it is that they shouldn't
        * be doing anymore.
        */
  -#ifdef WIN32
  -    /* Pick up all defunct processes */
  -    for (p = procs; p; p = p->next) {
  -     if (GetExitCodeProcess((HANDLE) p->pid, &status)) {
  -         p->kill_how = kill_never;
  -     }
  -    }
  -
  -
  -    for (p = procs; p; p = p->next) {
  -     if (p->kill_how == kill_after_timeout) {
  -         need_timeout = 1;
  -     }
  -     else if (p->kill_how == kill_always) {
  -         TerminateProcess((HANDLE) p->pid, 1);
  -     }
  -    }
  -    /* Sleep only if we have to... */
  -
  -    if (need_timeout) {
  -     sleep(3);
  -    }
  -
  -    /* OK, the scripts we just timed out for have had a chance to clean up
  -     * --- now, just get rid of them, and also clean up the system accounting
  -     * goop...
  -     */
  -
  -    for (p = procs; p; p = p->next) {
  -     if (p->kill_how == kill_after_timeout) {
  -         TerminateProcess((HANDLE) p->pid, 1);
  -     }
  -    }
   
  -    for (p = procs; p; p = p->next) {
  -     CloseHandle((HANDLE) p->pid);
  -    }
  -#else
   #ifndef NEED_WAITPID
       /* Pick up all defunct processes */
       for (p = procs; p; p = p->next) {
  -     if (ap_wait_proc(p->pid, APR_NOWAIT) > 0) {
  -         p->kill_how = kill_never;
  -     }
  +        if (ap_wait_proc(p->pid, APR_NOWAIT) == APR_CHILD_DONE) {
  +            p->kill_how = kill_never;
  +        }
       }
   #endif
   
       for (p = procs; p; p = p->next) {
  -     if ((p->kill_how == kill_after_timeout)
  -         || (p->kill_how == kill_only_once)) {
  -         /*
  -          * Subprocess may be dead already.  Only need the timeout if not.
  -          */
  -         if (ap_kill(p->pid, SIGTERM) != -1) {
  +        if ((p->kill_how == kill_after_timeout)
  +            || (p->kill_how == kill_only_once)) {
  +            /*
  +             * Subprocess may be dead already.  Only need the timeout if not.
  +             * Note: ap_kill on Windows is TerminateProcess(), which is 
  +             * similar to a SIGKILL, so always give the process a timeout
  +             * under Windows before killing it.
  +             */
  +#ifdef WIN32
  +            need_timeout = 1;
  +#else
  +         if (ap_kill(p->pid, APR_SIGTERM) == APR_SUCCESS) {
                need_timeout = 1;
            }
  +#endif
        }
        else if (p->kill_how == kill_always) {
  -         ap_kill(p->pid, SIGKILL);
  +         ap_kill(p->pid, APR_SIGKILL);
        }
       }
   
       /* Sleep only if we have to... */
  -
       if (need_timeout) {
        sleep(3);
       }
  @@ -1335,16 +1304,25 @@
        * --- now, just get rid of them, and also clean up the system accounting
        * goop...
        */
  -
       for (p = procs; p; p = p->next) {
  -
        if (p->kill_how == kill_after_timeout) {
  -         ap_kill(p->pid, SIGKILL);
  +         ap_kill(p->pid, APR_SIGKILL);
        }
  +    }
  +#ifdef WIN32
  +    /* Humm, still trying to understand what to do about this.
  +     * Do we need an APR function to clean-up a proc_t?
  +     * We have a handle leak here until this is fixed.
  +     for (p = procs; p; p = p->next) {
  +         CloseHandle(p->pid->pi.hProcess);
  +     }
  +    */
  +#endif /* WIN32 */
   
  +    /* Now wait for all the signaled processes to die */
  +    for (p = procs; p; p = p->next) {
        if (p->kill_how != kill_never) {
            status = ap_wait_proc(p->pid, APR_WAIT);
        }
       }
  -#endif /* WIN32 */
   }
  
  
  

Reply via email to