From: Yann Ylavic Date: Tue, 7 Oct 2014 16:54:31 +0000 (+0000) Subject: core: ensure that MPMs return an error on runtime failure and hence that X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b0cbd0173dd28da5cef557fc035b0baa08ac978;p=thirdparty%2Fapache%2Fhttpd.git core: ensure that MPMs return an error on runtime failure and hence that httpd's main process also exits with an error. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1629925 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/main.c b/server/main.c index 1acf64534eb..6d4787faddb 100644 --- a/server/main.c +++ b/server/main.c @@ -475,6 +475,7 @@ int main(int argc, const char * const argv[]) module **mod; const char *opt_arg; APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server; + int rc = OK; AP_MONCONTROL(0); /* turn off profiling of startup */ @@ -723,7 +724,7 @@ int main(int argc, const char * const argv[]) apr_pool_destroy(ptemp); - for (;;) { + do { ap_main_state = AP_SQ_MS_DESTROY_CONFIG; apr_hook_deregister_all(); apr_pool_clear(pconf); @@ -796,16 +797,23 @@ int main(int argc, const char * const argv[]) ap_run_optional_fn_retrieve(); ap_main_state = AP_SQ_MS_RUN_MPM; - if (ap_run_mpm(pconf, plog, ap_server_conf) != OK) - break; + rc = ap_run_mpm(pconf, plog, ap_server_conf); apr_pool_lock(pconf, 0); - } - apr_pool_lock(pconf, 0); - destroy_and_exit_process(process, 0); + } while (rc == OK); + + if (rc == DONE) { + rc = OK; + } + else if (rc != OK) { + ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL, APLOGNO() + "MPM run failed, exiting"); + } + destroy_and_exit_process(process, rc); - return 0; /* Termination 'ok' */ + /* NOTREACHED */ + return !OK; } #ifdef AP_USING_AUTOCONF diff --git a/server/mpm/event/event.c b/server/mpm/event/event.c index 9f602c03ef9..436eff0f121 100644 --- a/server/mpm/event/event.c +++ b/server/mpm/event/event.c @@ -2994,7 +2994,7 @@ static int event_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s) if (!retained->is_graceful) { if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } /* fix the generation number in the global score; we just got a new, * cleared scoreboard diff --git a/server/mpm/eventopt/eventopt.c b/server/mpm/eventopt/eventopt.c index f58aa8378f5..a19304989f5 100644 --- a/server/mpm/eventopt/eventopt.c +++ b/server/mpm/eventopt/eventopt.c @@ -2815,7 +2815,7 @@ static int event_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s) if (!retained->is_graceful) { if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } /* fix the generation number in the global score; we just got a new, * cleared scoreboard diff --git a/server/mpm/mpmt_os2/mpmt_os2.c b/server/mpm/mpmt_os2/mpmt_os2.c index 3bd360d0fff..ab1413ee41f 100644 --- a/server/mpm/mpmt_os2/mpmt_os2.c +++ b/server/mpm/mpmt_os2/mpmt_os2.c @@ -153,7 +153,7 @@ static int mpmt_os2_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) ap_mpm_child_main(pconf); /* Outta here */ - return 1; + return DONE; } else { /* Parent process */ @@ -163,7 +163,7 @@ static int mpmt_os2_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) if (ap_setup_listeners(ap_server_conf) < 1) { ap_log_error(APLOG_MARK, APLOG_ALERT, 0, s, APLOGNO(00200) "no listening sockets available, shutting down"); - return 1; + return !OK; } ap_log_pid(pconf, ap_pid_fname); @@ -176,11 +176,11 @@ static int mpmt_os2_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) ap_remove_pid(pconf, ap_pid_fname); ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(00201) "caught SIGTERM, shutting down"); - return 1; + return DONE; } } /* Parent process */ - return 0; /* Restart */ + return OK; /* Restart */ } diff --git a/server/mpm/netware/mpm_netware.c b/server/mpm/netware/mpm_netware.c index 4cef54152e3..5ff7107a3ae 100644 --- a/server/mpm/netware/mpm_netware.c +++ b/server/mpm/netware/mpm_netware.c @@ -872,7 +872,7 @@ static int netware_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) if (setup_listeners(s)) { ap_log_error(APLOG_MARK, APLOG_ALERT, status, s, APLOGNO(00223) "no listening sockets available, shutting down"); - return -1; + return !OK; } restart_pending = shutdown_pending = 0; @@ -880,7 +880,7 @@ static int netware_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) if (!is_graceful) { if (ap_run_pre_mpm(s->process->pool, SB_NOT_SHARED) != OK) { - return 1; + return !OK; } } @@ -949,7 +949,7 @@ static int netware_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) } mpm_main_cleanup(); - return 1; + return DONE; } else { /* the only other way out is a restart */ /* advance to the next generation */ @@ -972,7 +972,7 @@ static int netware_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) } mpm_main_cleanup(); - return 0; + return OK; } static int netware_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 6fa52b1dfaf..0b1714ba33b 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -978,14 +978,14 @@ static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) s, _pconf, 0); if (rv != APR_SUCCESS) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } } if (!retained->is_graceful) { if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } /* fix the generation number in the global score; we just got a new, * cleared scoreboard @@ -1001,7 +1001,7 @@ static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) make_child(ap_server_conf, 0, 0); /* NOTREACHED */ ap_assert(0); - return DONE; + return !OK; } /* Don't thrash... */ @@ -1071,7 +1071,7 @@ static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) || ap_get_scoreboard_process(child_slot)->generation == retained->my_generation) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } else { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf, APLOGNO(00166) diff --git a/server/mpm/simple/simple_api.c b/server/mpm/simple/simple_api.c index b118b05a283..8906db62643 100644 --- a/server/mpm/simple/simple_api.c +++ b/server/mpm/simple/simple_api.c @@ -35,7 +35,7 @@ static int simple_run(apr_pool_t * pconf, apr_pool_t * plog, server_rec * s) if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { sc->mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } return simple_main_loop(sc); diff --git a/server/mpm/simple/simple_run.c b/server/mpm/simple/simple_run.c index 6eb70ca7b30..65cde43ef38 100644 --- a/server/mpm/simple/simple_run.c +++ b/server/mpm/simple/simple_run.c @@ -179,7 +179,7 @@ static int simple_run_loop(simple_core_t * sc) if (!APR_STATUS_IS_EINTR(rv) && !APR_STATUS_IS_TIMEUP(rv)) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, "simple_main_loop: apr_pollcb_poll failed"); - return DONE; + return !OK; } } @@ -321,7 +321,7 @@ int simple_main_loop(simple_core_t * sc) rv = simple_setup_pollcb(sc); if (rv) { - return rv; + return !OK; } rv = simple_setup_workers(sc); diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 746523994bb..c9b5317689d 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -1696,7 +1696,7 @@ static int winnt_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) if (!restart && ((parent_pid == my_pid) || one_process)) { /* Set up the scoreboard. */ if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { - return DONE; + return !OK; } } diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index acc8b1b6880..ab350f60ec4 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -1817,14 +1817,14 @@ static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) s, _pconf, 0); if (rv != APR_SUCCESS) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } } if (!retained->is_graceful) { if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { mpm_state = AP_MPMQ_STOPPING; - return DONE; + return !OK; } /* fix the generation number in the global score; we just got a new, * cleared scoreboard