From aedb3178785974b16e21332b32e87f82c73ded77 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Mon, 4 Feb 2002 18:41:46 +0000 Subject: [PATCH] Not being able to bind to a socket is a fatal error. This makes all MPMs treat it as such. We now print a message to the console, and return a non-zero status code. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93227 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 5 +++ STATUS | 16 +------ server/mpm/experimental/perchild/perchild.c | 37 ++++++++++++++-- server/mpm/perchild/perchild.c | 37 ++++++++++++++-- server/mpm/prefork/prefork.c | 10 +++-- server/mpm/worker/worker.c | 49 ++++++++++++++------- 6 files changed, 112 insertions(+), 42 deletions(-) diff --git a/CHANGES b/CHANGES index 77fee86a1f..ea16d93377 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,10 @@ Changes with Apache 2.0.32-dev + *) Not being able to bind to the socket is a fatal error. We should + print an error to the console, and return a non-zero status code. + With these changes, all of the Unix MPMs do that correctly. + [Ryan Bloom] + *) suexec: Allow HTTPS and SSL_* environment variables to be passed through to CGI scripts. PR 9163 [Brian Reid , diff --git a/STATUS b/STATUS index 0e6e5dca1f..31ea37e39a 100644 --- a/STATUS +++ b/STATUS @@ -1,5 +1,5 @@ APACHE 2.0 STATUS: -*-text-*- -Last modified at [$Date: 2002/02/04 17:40:32 $] +Last modified at [$Date: 2002/02/04 18:41:45 $] Release: @@ -148,20 +148,6 @@ RELEASE SHOWSTOPPERS: RELEASE NON-SHOWSTOPPERS BUT WOULD BE REAL NICE TO WRAP THESE UP: - * Runtime startup failures don't reliably set the exit status. - For instance, try listening to port 80 and starting as non-root; - server fails with make_sock and 'no listening sockets' errors - but exits with 0 status. Even with -DONE_PROCESS -DNO_DETACH. - Justin says: "Is this really a showstopper? Most people won't - be using -DNO_DETACH and will look at the error - logs anyway." - Ken says: "Yes, it's a showstopper -- because it exits with - a 0 status on startup failure, whether it spawns - or not, before doing any work. A script will - incorrectly think it successfully daemonised." - Showstopper: Ken, BrianP, Martin - Not a showstopper: trawick, stoddard, Jim, Justin, Aaron - * The Add...Filter and Set...Filter directives do not allow the administrator to order filters, beyond the order of filename (mime) extensions. It isn't clear if Set...Filter(s) should be inserted diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index b79852d18d..d0dee44dce 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -1257,8 +1257,8 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) apr_status_t rv; apr_size_t one = 1; - pconf = _pconf; - ap_server_conf = s; + ap_log_pid(pconf, ap_pid_fname); + first_server_limit = server_limit; first_thread_limit = thread_limit; if (changed_limit_at_restart) { @@ -1289,7 +1289,6 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) "no listening sockets available, shutting down"); return 1; } - ap_log_pid(pconf, ap_pid_fname); /* Initialize cross-process accept lock */ ap_lock_fname = apr_psprintf(_pconf, "%s.%u", @@ -1424,6 +1423,32 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) return 0; } +/* This really should be a post_config hook, but the error log is already + * redirected by that point, so we need to do this in the open_logs phase. + */ +static int perchild_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) +{ + apr_status_t rv; + + pconf = p; + ap_server_conf = s; + + if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT|APLOG_STARTUP, 0, + NULL, "no listening sockets available, shutting down"); + return DONE; + } + + ap_log_pid(pconf, ap_pid_fname); + + if ((rv = ap_mpm_pod_open(pconf, &pod))) { + ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL, + "Could not open pipe-of-death."); + return DONE; + } + return OK; +} + static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) { static int restart_num = 0; @@ -1709,8 +1734,14 @@ static int perchild_pre_connection(conn_rec *c) static void perchild_hooks(apr_pool_t *p) { + /* The perchild open_logs phase must run before the core's, or stderr + * will be redirected to a file, and the messages won't print to the + * console. + */ + static const char *const aszSucc[] = {"core.c", NULL}; one_process = 0; + ap_hook_open_logs(perchild_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE); ap_hook_pre_config(perchild_pre_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_post_config(perchild_post_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_pre_connection(perchild_pre_connection,NULL,NULL, APR_HOOK_MIDDLE); diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index b79852d18d..d0dee44dce 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -1257,8 +1257,8 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) apr_status_t rv; apr_size_t one = 1; - pconf = _pconf; - ap_server_conf = s; + ap_log_pid(pconf, ap_pid_fname); + first_server_limit = server_limit; first_thread_limit = thread_limit; if (changed_limit_at_restart) { @@ -1289,7 +1289,6 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) "no listening sockets available, shutting down"); return 1; } - ap_log_pid(pconf, ap_pid_fname); /* Initialize cross-process accept lock */ ap_lock_fname = apr_psprintf(_pconf, "%s.%u", @@ -1424,6 +1423,32 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) return 0; } +/* This really should be a post_config hook, but the error log is already + * redirected by that point, so we need to do this in the open_logs phase. + */ +static int perchild_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) +{ + apr_status_t rv; + + pconf = p; + ap_server_conf = s; + + if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT|APLOG_STARTUP, 0, + NULL, "no listening sockets available, shutting down"); + return DONE; + } + + ap_log_pid(pconf, ap_pid_fname); + + if ((rv = ap_mpm_pod_open(pconf, &pod))) { + ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL, + "Could not open pipe-of-death."); + return DONE; + } + return OK; +} + static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) { static int restart_num = 0; @@ -1709,8 +1734,14 @@ static int perchild_pre_connection(conn_rec *c) static void perchild_hooks(apr_pool_t *p) { + /* The perchild open_logs phase must run before the core's, or stderr + * will be redirected to a file, and the messages won't print to the + * console. + */ + static const char *const aszSucc[] = {"core.c", NULL}; one_process = 0; + ap_hook_open_logs(perchild_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE); ap_hook_pre_config(perchild_pre_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_post_config(perchild_post_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_pre_connection(perchild_pre_connection,NULL,NULL, APR_HOOK_MIDDLE); diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 1af99f9aa6..3cecebe224 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -973,6 +973,8 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) int index; int remaining_children_to_start; + ap_log_pid(pconf, ap_pid_fname); + first_server_limit = server_limit; if (changed_limit_at_restart) { ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, s, @@ -1182,7 +1184,6 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) return 0; } - /* This really should be a post_config hook, but the error log is already * redirected by that point, so we need to do this in the open_logs phase. */ @@ -1199,8 +1200,6 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, return DONE; } - ap_log_pid(pconf, ap_pid_fname); - if ((rv = ap_mpm_pod_open(pconf, &pod))) { ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL, "Could not open pipe-of-death."); @@ -1260,9 +1259,12 @@ static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp static void prefork_hooks(apr_pool_t *p) { + /* The prefork open_logs phase must run before the core's, or stderr + * will be redirected to a file, and the messages won't print to the + * console. + */ static const char *const aszSucc[] = {"core.c", NULL}; - #ifdef AUX3 (void) set42sig(); #endif diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 84a65b52f2..c90a07d9fb 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -1288,8 +1288,8 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) int remaining_children_to_start; apr_status_t rv; - pconf = _pconf; - ap_server_conf = s; + ap_log_pid(pconf, ap_pid_fname); + first_server_limit = server_limit; first_thread_limit = thread_limit; if (changed_limit_at_restart) { @@ -1299,21 +1299,6 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) changed_limit_at_restart = 0; } - if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) { - /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */ - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, 0, s, - "no listening sockets available, shutting down"); - return 1; - } - - if ((rv = ap_mpm_pod_open(pconf, &pod))) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, - "Could not open pipe-of-death."); - return 1; - } - - ap_log_pid(pconf, ap_pid_fname); - /* Initialize cross-process accept lock */ ap_lock_fname = apr_psprintf(_pconf, "%s.%" APR_OS_PROC_T_FMT, ap_server_root_relative(_pconf, ap_lock_fname), @@ -1456,6 +1441,30 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) return 0; } +/* This really should be a post_config hook, but the error log is already + * redirected by that point, so we need to do this in the open_logs phase. + */ +static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) +{ + apr_status_t rv; + + pconf = p; + ap_server_conf = s; + + if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT|APLOG_STARTUP, 0, + NULL, "no listening sockets available, shutting down"); + return DONE; + } + + if ((rv = ap_mpm_pod_open(pconf, &pod))) { + ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL, + "Could not open pipe-of-death."); + return DONE; + } + return OK; +} + static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { @@ -1546,8 +1555,14 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog, static void worker_hooks(apr_pool_t *p) { + /* The worker open_logs phase must run before the core's, or stderr + * will be redirected to a file, and the messages won't print to the + * console. + */ + static const char *const aszSucc[] = {"core.c", NULL}; one_process = 0; + ap_hook_open_logs(worker_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE); ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } -- 2.50.1