On Thu, Jan 03, 2002 at 08:28:14AM -0800, Aaron Bannert wrote:
> I see no reason why this can't be implemented in apache2, and I'll
> even test and commit a patch that properly implements it. :) Sorry
> I can't offer much more than that. Maybe if I get some more time
> later this week I can look into it, but the more surefire way to get
> it in would be to provide a patch.

Here's a patch that appears to dtrt. I chose DONT_FORK as the keyword but I
would happily change this or any other name to something else, just let me
know. The main thing is that the patch goes in :-) Btw, the patch is against
2.0.28, I hope that is not too big of a problem; I can look into bringing it
up to HEAD if desired.

Thanks!

lizzy:/usr/ports/www/apache2# ps -ax -o pid,ppid,pgid,command|grep httpd
  297   252   252 supervise httpd
73061   297 73061 httpd -DDONT_FORK
73064 73061 73061 httpd -DDONT_FORK
73067 73061 73061 httpd -DDONT_FORK
73068 73061 73061 httpd -DDONT_FORK
73069 73061 73061 httpd -DDONT_FORK
73070 73061 73061 httpd -DDONT_FORK
73071 73061 73061 httpd -DDONT_FORK

diff -ru work.dist/httpd-2_0_28/server/mpm/beos/beos.c 
work/httpd-2_0_28/server/mpm/beos/beos.c
--- work.dist/httpd-2_0_28/server/mpm/beos/beos.c       Tue Nov  6 21:29:36 2001
+++ work/httpd-2_0_28/server/mpm/beos/beos.c    Fri Jan  4 15:47:09 2002
@@ -946,16 +946,19 @@
 static void beos_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
 {
     static int restart_num = 0;
-    int no_detach, debug;
+    int no_detach, dont_fork, debug;
 
     debug = ap_exists_config_define("DEBUG");
 
-    if (debug)
+    if (debug) {
         no_detach = one_process = 1;
+        dont_fork = 0;
+    }
     else
     {
         one_process = ap_exists_config_define("ONE_PROCESS");
         no_detach = ap_exists_config_define("NO_DETACH");
+        dont_fork = ap_exists_config_define("DONT_FORK");
     }
 
     /* sigh, want this only the second time around */
@@ -963,7 +966,7 @@
         is_graceful = 0;
         
         if (!one_process && !no_detach)
-               apr_proc_detach();
+               apr_proc_detach(dont_fork);
 
         server_pid = getpid();
     }
diff -ru work.dist/httpd-2_0_28/server/mpm/perchild/perchild.c 
work/httpd-2_0_28/server/mpm/perchild/perchild.c
--- work.dist/httpd-2_0_28/server/mpm/perchild/perchild.c       Tue Nov  6 21:29:36 
2001
+++ work/httpd-2_0_28/server/mpm/perchild/perchild.c    Fri Jan  4 15:49:09 2002
@@ -1327,17 +1327,20 @@
 static void perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
 {
     static int restart_num = 0;
-    int no_detach, debug;
+    int no_detach, dont_fork, debug;
     int i;
 
     debug = ap_exists_config_define("DEBUG");
 
-    if (debug)
+    if (debug) {
         no_detach = one_process = 1;
+        dont_fork = 0;
+    }
     else
     {
         one_process = ap_exists_config_define("ONE_PROCESS");
         no_detach = ap_exists_config_define("NO_DETACH");
+        dont_fork = ap_exists_config_define("DONT_FORK");
     }
 
     /* sigh, want this only the second time around */
@@ -1345,7 +1348,7 @@
        is_graceful = 0;
 
        if (!one_process && !no_detach) {
-           apr_proc_detach();
+           apr_proc_detach(dont_fork);
        }
 
        my_pid = getpid();
diff -ru work.dist/httpd-2_0_28/server/mpm/prefork/prefork.c 
work/httpd-2_0_28/server/mpm/prefork/prefork.c
--- work.dist/httpd-2_0_28/server/mpm/prefork/prefork.c Tue Nov  6 21:29:36 2001
+++ work/httpd-2_0_28/server/mpm/prefork/prefork.c      Fri Jan  4 15:48:13 2002
@@ -1292,16 +1292,19 @@
 static void prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
 {
     static int restart_num = 0;
-    int no_detach, debug;
+    int no_detach, dont_fork, debug;
 
     debug = ap_exists_config_define("DEBUG");
 
-    if (debug)
+    if (debug) {
         no_detach = one_process = 1;
+        dont_fork = 0;
+    }
     else
     {
         no_detach = ap_exists_config_define("NO_DETACH");
         one_process = ap_exists_config_define("ONE_PROCESS");
+        dont_fork = ap_exists_config_define("DONT_FORK");
     }
 
     /* sigh, want this only the second time around */
@@ -1309,7 +1312,7 @@
        is_graceful = 0;
 
        if (!one_process && !no_detach) {
-           apr_proc_detach();
+           apr_proc_detach(dont_fork);
        }
 
        parent_pid = ap_my_pid = getpid();
diff -ru work.dist/httpd-2_0_28/server/mpm/threaded/threaded.c 
work/httpd-2_0_28/server/mpm/threaded/threaded.c
--- work.dist/httpd-2_0_28/server/mpm/threaded/threaded.c       Tue Nov  6 21:29:36 
2001
+++ work/httpd-2_0_28/server/mpm/threaded/threaded.c    Fri Jan  4 15:41:19 2002
@@ -1359,7 +1359,7 @@
 static void threaded_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t 
*ptemp)
 {
     static int restart_num = 0;
-    int no_detach, debug;
+    int no_detach, dont_fork, debug;
     ap_directive_t *pdir;
     ap_directive_t *max_clients = NULL;
 
@@ -1401,11 +1401,14 @@
 
     debug = ap_exists_config_define("DEBUG");
 
-    if (debug)
+    if (debug) {
         no_detach = one_process = 1;
+        dont_fork = 0;
+    }
     else
     {
         no_detach = ap_exists_config_define("NO_DETACH");
+        dont_fork = ap_exists_config_define("DONT_FORK");
         one_process = ap_exists_config_define("ONE_PROCESS");
     }
 
@@ -1414,7 +1417,7 @@
        is_graceful = 0;
 
        if (!one_process && !no_detach) {
-           apr_proc_detach();
+           apr_proc_detach(dont_fork);
        }
        parent_pid = ap_my_pid = getpid();
     }
diff -ru work.dist/httpd-2_0_28/server/mpm/worker/worker.c 
work/httpd-2_0_28/server/mpm/worker/worker.c
--- work.dist/httpd-2_0_28/server/mpm/worker/worker.c   Tue Nov  6 21:29:36 2001
+++ work/httpd-2_0_28/server/mpm/worker/worker.c        Fri Jan  4 15:42:01 2002
@@ -1424,7 +1424,7 @@
 static void worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
 {
     static int restart_num = 0;
-    int no_detach, debug;
+    int no_detach, dont_fork, debug;
     ap_directive_t *pdir;
     ap_directive_t *max_clients = NULL;
 
@@ -1466,8 +1466,10 @@
 
     debug = ap_exists_config_define("DEBUG");
 
-    if (debug)
+    if (debug) {
         no_detach = one_process = 1;
+        dont_fork = 0;
+    }
     else
     {
         one_process = ap_exists_config_define("ONE_PROCESS");
@@ -1479,7 +1481,7 @@
        is_graceful = 0;
 
        if (!one_process && !no_detach) {
-           apr_proc_detach();
+           apr_proc_detach(dont_fork);
        }
        parent_pid = ap_my_pid = getpid();
     }
diff -ru work.dist/httpd-2_0_28/srclib/apr/threadproc/netware/proc.c 
work/httpd-2_0_28/srclib/apr/threadproc/netware/proc.c
--- work.dist/httpd-2_0_28/srclib/apr/threadproc/netware/proc.c Tue Oct 23 10:29:46 
2001
+++ work/httpd-2_0_28/srclib/apr/threadproc/netware/proc.c      Fri Jan  4 14:20:19 
+2002
@@ -345,13 +345,13 @@
             }
             newargs[i + 2] = NULL;
             if (attr->detached) {
-                apr_proc_detach();
+                apr_proc_detach(0);
             }
             execve(SHELL_PATH, (char * const *) newargs, (char * const *)env);
         }
         else {
             if (attr->detached) {
-                apr_proc_detach();
+                apr_proc_detach(0);
             }
             execve(progname, (char * const *)args, (char * const *)env);
         }
diff -ru work.dist/httpd-2_0_28/srclib/apr/threadproc/netware/procsup.c 
work/httpd-2_0_28/srclib/apr/threadproc/netware/procsup.c
--- work.dist/httpd-2_0_28/srclib/apr/threadproc/netware/procsup.c      Thu Aug  2 
13:28:52 2001
+++ work/httpd-2_0_28/srclib/apr/threadproc/netware/procsup.c   Fri Jan  4 14:16:37 
+2002
@@ -54,7 +54,7 @@
 
 #include "threadproc.h"
 
-apr_status_t apr_proc_detach(void)
+apr_status_t apr_proc_detach(int dont_fork)
 {
 #if 0
     int x;
diff -ru work.dist/httpd-2_0_28/srclib/apr/threadproc/os2/proc.c 
work/httpd-2_0_28/srclib/apr/threadproc/os2/proc.c
--- work.dist/httpd-2_0_28/srclib/apr/threadproc/os2/proc.c     Thu Oct 25 19:30:42 
2001
+++ work/httpd-2_0_28/srclib/apr/threadproc/os2/proc.c  Fri Jan  4 14:17:23 2002
@@ -620,7 +620,7 @@
 
 
 
-APR_DECLARE(apr_status_t) apr_proc_detach()
+APR_DECLARE(apr_status_t) apr_proc_detach(int dont_fork)
 {
     return APR_ENOTIMPL;
 }
diff -ru work.dist/httpd-2_0_28/srclib/apr/threadproc/unix/proc.c 
work/httpd-2_0_28/srclib/apr/threadproc/unix/proc.c
--- work.dist/httpd-2_0_28/srclib/apr/threadproc/unix/proc.c    Fri Oct 26 17:47:57 
2001
+++ work/httpd-2_0_28/srclib/apr/threadproc/unix/proc.c Fri Jan  4 15:43:49 2002
@@ -347,13 +347,13 @@
             }
             newargs[i + 2] = NULL;
             if (attr->detached) {
-                apr_proc_detach();
+                apr_proc_detach(0);
             }
             execve(SHELL_PATH, (char * const *) newargs, (char * const *)env);
         }
         else {
             if (attr->detached) {
-                apr_proc_detach();
+                apr_proc_detach(0);
             }
             execve(progname, (char * const *)args, (char * const *)env);
         }
diff -ru work.dist/httpd-2_0_28/srclib/apr/threadproc/unix/procsup.c 
work/httpd-2_0_28/srclib/apr/threadproc/unix/procsup.c
--- work.dist/httpd-2_0_28/srclib/apr/threadproc/unix/procsup.c Fri Aug 10 14:04:26 
2001
+++ work/httpd-2_0_28/srclib/apr/threadproc/unix/procsup.c      Fri Jan  4 14:12:29 
+2002
@@ -54,7 +54,7 @@
 
 #include "threadproc.h"
 
-APR_DECLARE(apr_status_t) apr_proc_detach(void)
+APR_DECLARE(apr_status_t) apr_proc_detach(int dont_fork)
 {
     int x;
     pid_t pgrp;
@@ -63,14 +63,16 @@
 #if !defined(MPE) && !defined(OS2) && !defined(TPF) && !defined(BEOS)
 /* Don't detach for MPE because child processes can't survive the death of
    the parent. */
-    if ((x = fork()) > 0)
-        exit(0);
-    else if (x == -1) {
-        perror("fork");
-        fprintf(stderr, "unable to fork new process\n");
-        exit(1);  /* we can't do anything here, so just exit. */
+    if (!dont_fork) {
+           if ((x = fork()) > 0)
+               exit(0);
+           else if (x == -1) {
+               perror("fork");
+               fprintf(stderr, "unable to fork new process\n");
+               exit(1);  /* we can't do anything here, so just exit. */
+           }
+    /*    RAISE_SIGSTOP(DETACH);*/
     }
-/*    RAISE_SIGSTOP(DETACH);*/
 #endif
 #if APR_HAVE_SETSID
     if ((pgrp = setsid()) == -1) {

-- 
Jos Backus                 _/  _/_/_/        Santa Clara, CA
                          _/  _/   _/
                         _/  _/_/_/             
                    _/  _/  _/    _/
[EMAIL PROTECTED]     _/_/   _/_/_/            use Std::Disclaimer;

Reply via email to