On Sun, Jan 06, 2002 at 10:28:12PM -0800, Jos Backus wrote:
> On Sun, Jan 06, 2002 at 09:11:11PM -0800, Ryan Bloom wrote:
> > I'm 100% in favor of this stuff, but please just keep using NO_DETACH for
> > this. I didn't get the use case correct for NO_DETACH, but that doesn't
> > mean we should add another option.
>
> Fine with me. This does mean that the NO_DETACH behavior will change (for
> the better, in my view).
Here's the adjusted patch. NO_DETACH now causes apr_proc_detach() to be called
but the fork() skipped. But apr_proc_detach() still reopens std{in,out,err};
this may not be desired behavior. So maybe we should factor out the
setpgid()/setsid() part into its own function (apr_proc_newsessid()?) and call
it instead of apr_proc_detach() when using NO_DETACH? (apr_proc_detach()
would also call this new function.)
Thoughts? Or is this patch good enough?
Index: server/mpm/beos/beos.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/beos/beos.c,v
retrieving revision 1.75
diff -u -r1.75 beos.c
--- server/mpm/beos/beos.c 29 Dec 2001 23:16:23 -0000 1.75
+++ server/mpm/beos/beos.c 8 Jan 2002 06:44:31 -0000
@@ -998,7 +998,7 @@
debug = ap_exists_config_define("DEBUG");
if (debug)
- no_detach = one_process = 1;
+ no_detach = dont_fork = one_process = 1;
else
{
one_process = ap_exists_config_define("ONE_PROCESS");
@@ -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.97
diff -u -r1.97 perchild.c
--- server/mpm/perchild/perchild.c 29 Dec 2001 23:16:23 -0000 1.97
+++ server/mpm/perchild/perchild.c 8 Jan 2002 06:44:33 -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,8 +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.227
diff -u -r1.227 prefork.c
--- server/mpm/prefork/prefork.c 29 Dec 2001 23:16:24 -0000 1.227
+++ server/mpm/prefork/prefork.c 8 Jan 2002 06:44:34 -0000
@@ -1216,8 +1216,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.58
diff -u -r1.58 worker.c
--- server/mpm/worker/worker.c 29 Dec 2001 23:16:24 -0000 1.58
+++ server/mpm/worker/worker.c 8 Jan 2002 06:44:35 -0000
@@ -1596,8 +1596,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: 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 8 Jan 2002 06:44:36 -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.3
diff -u -r1.3 proc.c
--- srclib/apr/threadproc/netware/proc.c 23 Oct 2001 17:30:08 -0000 1.3
+++ srclib/apr/threadproc/netware/proc.c 8 Jan 2002 06:44:37 -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 8 Jan 2002 06:44:37 -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,14 +64,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) {
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 8 Jan 2002 06:44:38 -0000
@@ -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;
}
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 8 Jan 2002 06:44:38 -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 8 Jan 2002 06:44:38 -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,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
#ifdef HAVE_SETSID
if ((pgrp = setsid()) == -1) {
--
Jos Backus _/ _/_/_/ Santa Clara, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
[EMAIL PROTECTED] _/_/ _/_/_/ use Std::Disclaimer;