Based on Michael Handler's feedback, here's another patch which simply fixes
-DNO_DETACH to dtrt. This way things are under operator control and we avoid
people running httpd under non-job-control shells shooting themselves in the
foot.

Please let me know if there's anything that prevents this patch from being
incorporated so I can fix it. Thanks!

Index: server/mpm/beos/beos.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/beos/beos.c,v
retrieving revision 1.76
diff -u -r1.76 beos.c
--- server/mpm/beos/beos.c      10 Jan 2002 00:27:58 -0000      1.76
+++ server/mpm/beos/beos.c      13 Jan 2002 21:35:08 -0000
@@ -1009,8 +1009,8 @@
     if (restart_num++ == 1) {
         is_graceful = 0;
         
-        if (!one_process && !no_detach)
-               apr_proc_detach();
+        if (!one_process)
+           apr_proc_detach(no_detach);
 
         server_pid = getpid();
     }
Index: server/mpm/perchild/perchild.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/perchild/perchild.c,v
retrieving revision 1.98
diff -u -r1.98 perchild.c
--- server/mpm/perchild/perchild.c      10 Jan 2002 00:27:59 -0000      1.98
+++ server/mpm/perchild/perchild.c      13 Jan 2002 21:35:10 -0000
@@ -1433,9 +1433,8 @@
 
     debug = ap_exists_config_define("DEBUG");
 
-    if (debug) {
+    if (debug)
         no_detach = one_process = 1;
-    }
     else {
         one_process = ap_exists_config_define("ONE_PROCESS");
         no_detach = ap_exists_config_define("NO_DETACH");
@@ -1445,9 +1444,8 @@
     if (restart_num++ == 1) {
         is_graceful = 0;
 
-        if (!one_process && !no_detach) {
-            apr_proc_detach();
-        }
+        if (!one_process)
+           apr_proc_detach(no_detach);
 
         my_pid = getpid();
     }
Index: server/mpm/prefork/prefork.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/prefork/prefork.c,v
retrieving revision 1.229
diff -u -r1.229 prefork.c
--- server/mpm/prefork/prefork.c        11 Jan 2002 14:13:23 -0000      1.229
+++ server/mpm/prefork/prefork.c        13 Jan 2002 21:35:11 -0000
@@ -1217,9 +1217,8 @@
     if (restart_num++ == 1) {
        is_graceful = 0;
 
-       if (!one_process && !no_detach) {
-           apr_proc_detach();
-       }
+       if (!one_process)
+           apr_proc_detach(no_detach);
 
        parent_pid = ap_my_pid = getpid();
     }
Index: server/mpm/worker/worker.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/worker/worker.c,v
retrieving revision 1.60
diff -u -r1.60 worker.c
--- server/mpm/worker/worker.c  11 Jan 2002 08:01:11 -0000      1.60
+++ server/mpm/worker/worker.c  13 Jan 2002 21:35:13 -0000
@@ -1596,9 +1596,9 @@
     if (restart_num++ == 1) {
         is_graceful = 0;
 
-        if (!one_process && !no_detach) {
-            apr_proc_detach();
-        }
+        if (!one_process)
+           apr_proc_detach(no_detach);
+
         parent_pid = ap_my_pid = getpid();
     }
 
Index: srclib/apr/include/apr_thread_proc.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_thread_proc.h,v
retrieving revision 1.78
diff -u -r1.78 apr_thread_proc.h
--- srclib/apr/include/apr_thread_proc.h        27 Dec 2001 17:02:59 -0000      1.78
+++ srclib/apr/include/apr_thread_proc.h        13 Jan 2002 21:35:14 -0000
@@ -552,7 +552,7 @@
 /**
  * Detach the process from the controlling terminal.
  */
-APR_DECLARE(apr_status_t) apr_proc_detach(void);
+APR_DECLARE(apr_status_t) apr_proc_detach(int dont_fork);
 
 #if APR_HAS_OTHER_CHILD
 
Index: srclib/apr/threadproc/netware/proc.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/netware/proc.c,v
retrieving revision 1.4
diff -u -r1.4 proc.c
--- srclib/apr/threadproc/netware/proc.c        8 Jan 2002 21:00:37 -0000       1.4
+++ srclib/apr/threadproc/netware/proc.c        13 Jan 2002 21:35:15 -0000
@@ -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);
         }
Index: srclib/apr/threadproc/netware/procsup.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/netware/procsup.c,v
retrieving revision 1.1
diff -u -r1.1 procsup.c
--- srclib/apr/threadproc/netware/procsup.c     2 Aug 2001 20:29:14 -0000       1.1
+++ srclib/apr/threadproc/netware/procsup.c     13 Jan 2002 21:35:15 -0000
@@ -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;
@@ -64,15 +64,18 @@
 #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) {
         return errno;
Index: srclib/apr/threadproc/os2/proc.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/os2/proc.c,v
retrieving revision 1.47
diff -u -r1.47 proc.c
--- srclib/apr/threadproc/os2/proc.c    26 Oct 2001 02:31:04 -0000      1.47
+++ srclib/apr/threadproc/os2/proc.c    13 Jan 2002 21:35:15 -0000
@@ -618,9 +618,7 @@
     return APR_SUCCESS;
 }
 
-
-
-APR_DECLARE(apr_status_t) apr_proc_detach()
+APR_DECLARE(apr_status_t) apr_proc_detach(int dont_fork)
 {
     return APR_ENOTIMPL;
 }
Index: srclib/apr/threadproc/unix/proc.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/unix/proc.c,v
retrieving revision 1.53
diff -u -r1.53 proc.c
--- srclib/apr/threadproc/unix/proc.c   11 Nov 2001 05:51:00 -0000      1.53
+++ srclib/apr/threadproc/unix/proc.c   13 Jan 2002 21:35:15 -0000
@@ -362,13 +362,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);
         }
Index: srclib/apr/threadproc/unix/procsup.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/unix/procsup.c,v
retrieving revision 1.33
diff -u -r1.33 procsup.c
--- srclib/apr/threadproc/unix/procsup.c        28 Dec 2001 19:03:48 -0000      1.33
+++ srclib/apr/threadproc/unix/procsup.c        13 Jan 2002 21:35:16 -0000
@@ -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,15 +63,18 @@
 #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
+
 #ifdef HAVE_SETSID
     if ((pgrp = setsid()) == -1) {
         return errno;

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

Reply via email to