From 19613bbf382c9d40bb1a9906a305ebce8ef3ef45 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Mon, 4 Feb 2002 16:58:54 +0000 Subject: [PATCH] This patch allows the prefork MPM to print messages to the console if it can't open a socket for some reason. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93224 13f79535-47bb-0310-9956-ffa450edef68 --- server/listen.c | 4 +-- server/main.c | 5 +++- server/mpm/prefork/prefork.c | 49 +++++++++++++++++++++++------------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/server/listen.c b/server/listen.c index 55ce7c1cf8..b94f3f10ac 100644 --- a/server/listen.c +++ b/server/listen.c @@ -142,7 +142,7 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server) #endif if ((stat = apr_bind(s, server->bind_addr)) != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_CRIT, stat, p, + ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, stat, p, "make_sock: could not bind to address %pI", server->bind_addr); apr_socket_close(s); @@ -150,7 +150,7 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server) } if ((stat = apr_listen(s, ap_listenbacklog)) != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_ERR, stat, p, + ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_ERR, stat, p, "make_sock: unable to listen for connections on address %pI", server->bind_addr); apr_socket_close(s); diff --git a/server/main.c b/server/main.c index 763584e59c..d1874be81e 100644 --- a/server/main.c +++ b/server/main.c @@ -446,8 +446,11 @@ int main(int argc, const char * const argv[]) destroy_and_exit_process(process, 0); } apr_pool_clear(plog); + /* It is assumed that if you are going to fail the open_logs phase, then + * you will print out your own message that explains what has gone wrong. + * The server doesn't need to do that for you. + */ if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) { - ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR| APLOG_NOERRNO, 0, NULL, "Unable to open logs\n"); destroy_and_exit_process(process, 1); } if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) { diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 644f5ec17b..1af99f9aa6 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -972,10 +972,7 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) { int index; int remaining_children_to_start; - apr_status_t rv; - pconf = _pconf; - ap_server_conf = s; first_server_limit = server_limit; if (changed_limit_at_restart) { ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, s, @@ -984,21 +981,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; - } - - ap_log_pid(pconf, ap_pid_fname); - - 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; - } - SAFE_ACCEPT(accept_mutex_init(pconf)); if (!is_graceful) { if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) { @@ -1200,6 +1182,33 @@ 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 prefork_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 prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) { static int restart_num = 0; @@ -1251,10 +1260,14 @@ 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) { + static const char *const aszSucc[] = {"core.c", NULL}; + + #ifdef AUX3 (void) set42sig(); #endif + ap_hook_open_logs(prefork_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE); ap_hook_pre_config(prefork_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } -- 2.50.1