From 3da7b6c2c74a05741823d6e3dcfacddb4f68839e Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Wed, 7 May 2008 19:38:50 +0000 Subject: [PATCH] mod_cgid: Don't try to restart the daemon if it fails to initialize the socket. It won't get any better without intervention, and it will fork() until some sort of intervention. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@654232 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 2 ++ modules/generators/mod_cgid.c | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index b8bfac24d6..bdb4c6a147 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ Changes with Apache 2.3.0 [ When backported to 2.2.x, remove entry from this file ] + *) mod_cgid: Don't try to restart the daemon if it fails to initialize + the socket. [Jeff Trawick] *) core: Do not allow Options ALL if not all options are allowed to be overwritten. PR 44262 [Michał Grzędzicki ] diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index 70efc49b80..670a4734b1 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -91,6 +91,15 @@ static const char *sockname; static pid_t parent_pid; static ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 }; +/* The APR other-child API doesn't tell us how the daemon exited + * (SIGSEGV vs. exit(1)). The other-child maintenance function + * needs to decide whether to restart the daemon after a failure + * based on whether or not it exited due to a fatal startup error + * or something that happened at steady-state. This exit status + * is unlikely to collide with exit signals. + */ +#define DAEMON_STARTUP_ERROR 254 + /* Read and discard the data in the brigade produced by a CGI script */ static void discard_script_output(apr_bucket_brigade *bb); @@ -254,9 +263,15 @@ static void cgid_maint(int reason, void *data, apr_wait_t status) stopping = 0; } if (!stopping) { - ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, - "cgid daemon process died, restarting"); - cgid_start(root_pool, root_server, proc); + if (status == DAEMON_STARTUP_ERROR) { + ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, + "cgid daemon failed to initialize"); + } + else { + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, + "cgid daemon process died, restarting"); + cgid_start(root_pool, root_server, proc); + } } break; case APR_OC_REASON_RESTART: @@ -785,7 +800,7 @@ static int cgid_server(void *data) apr_hash_set(script_hash, key, sizeof(cgid_req.conn_id), (void *)((long)procnew->pid)); } - return -1; + return -1; /* should be <= 0 to distinguish from startup errors */ } static int cgid_start(apr_pool_t *p, server_rec *main_server, @@ -802,8 +817,7 @@ static int cgid_start(apr_pool_t *p, server_rec *main_server, if (pcgi == NULL) { apr_pool_create(&pcgi, p); } - cgid_server(main_server); - exit(-1); + exit(cgid_server(main_server) > 0 ? DAEMON_STARTUP_ERROR : -1); } procnew->pid = daemon_pid; procnew->err = procnew->in = procnew->out = NULL; -- 2.40.0