From 5e4fba9c6c52043c5d3340f5dec9f35c22ed3ba5 Mon Sep 17 00:00:00 2001 From: Aaron Bannert Date: Thu, 21 Feb 2002 18:52:28 +0000 Subject: [PATCH] Implement apr_proc_detach changes and allow -DNO_DETACH in the multi-process mode to not "daemonize" while detaching from the controlling terminal. This is necessary for Apache to work with process-management tools like AIX's "System Resource Controller" as well as Dan Bernstein's "daemontools". What this means is apache must _NOT_ be a process group leader if called with the -DNO_DETACH flag. Submitted from: Jos Backus Edited/Reviewed by: Aaron Bannert git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93535 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/beos/beos.c | 5 +++-- server/mpm/experimental/perchild/perchild.c | 5 +++-- server/mpm/perchild/perchild.c | 5 +++-- server/mpm/prefork/prefork.c | 5 +++-- server/mpm/worker/worker.c | 13 +++++++------ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index c58a5786f4..c424f8cba4 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -1010,8 +1010,9 @@ static int beos_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptem if (restart_num++ == 1) { is_graceful = 0; - if (!one_process && !no_detach) { - rv = apr_proc_detach(); + if (!one_process) { + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND + : APR_PROC_DETACH_DAEMONIZE); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, "apr_proc_detach failed"); diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index 1ea2675b4f..a92cc0ddee 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -1473,8 +1473,9 @@ static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptem if (restart_num++ == 1) { is_graceful = 0; - if (!one_process && !no_detach) { - rv = apr_proc_detach(); + if (!one_process) { + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND + : APR_PROC_DETACH_DAEMONIZE); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, "apr_proc_detach failed"); diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index 1ea2675b4f..a92cc0ddee 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -1473,8 +1473,9 @@ static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptem if (restart_num++ == 1) { is_graceful = 0; - if (!one_process && !no_detach) { - rv = apr_proc_detach(); + if (!one_process) { + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND + : APR_PROC_DETACH_DAEMONIZE); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, "apr_proc_detach failed"); diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 352ffaf376..ccfdcae410 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -1216,8 +1216,9 @@ static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp if (restart_num++ == 1) { is_graceful = 0; - if (!one_process && !no_detach) { - rv = apr_proc_detach(); + if (!one_process) { + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND + : APR_PROC_DETACH_DAEMONIZE); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, "apr_proc_detach failed"); diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 309c0aac9b..61a63ae436 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -1551,17 +1551,17 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog, } } else if (!max_clients - && strncasecmp(pdir->directive, "MaxClients", 10) == 0) { + && strncasecmp(pdir->directive, "MaxClients", 10) == 0) { max_clients = pdir; } } debug = ap_exists_config_define("DEBUG"); - if (debug) + if (debug) { no_detach = one_process = 1; - else - { + } + else { one_process = ap_exists_config_define("ONE_PROCESS"); no_detach = ap_exists_config_define("NO_DETACH"); } @@ -1570,8 +1570,9 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog, if (restart_num++ == 1) { is_graceful = 0; - if (!one_process && !no_detach) { - rv = apr_proc_detach(); + if (!one_process) { + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND + : APR_PROC_DETACH_DAEMONIZE); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, "apr_proc_detach failed"); -- 2.50.1