]> granicus.if.org Git - apache/commitdiff
core: ensure that MPMs return an error on runtime failure and hence that
authorYann Ylavic <ylavic@apache.org>
Tue, 7 Oct 2014 16:54:31 +0000 (16:54 +0000)
committerYann Ylavic <ylavic@apache.org>
Tue, 7 Oct 2014 16:54:31 +0000 (16:54 +0000)
      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

server/main.c
server/mpm/event/event.c
server/mpm/eventopt/eventopt.c
server/mpm/mpmt_os2/mpmt_os2.c
server/mpm/netware/mpm_netware.c
server/mpm/prefork/prefork.c
server/mpm/simple/simple_api.c
server/mpm/simple/simple_run.c
server/mpm/winnt/mpm_winnt.c
server/mpm/worker/worker.c

index 1acf64534eb23d41ebbb077b73946746a66984c3..6d4787faddb25d1c3ce3f158a1f175229cbf280c 100644 (file)
@@ -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
index 9f602c03ef91b643ee58300f392d535339dcffa1..436eff0f1210cc878356a2dad88021a1ff877e9f 100644 (file)
@@ -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
index f58aa8378f5e1834f426d7962d9ec17566778c53..a19304989f5889fffda6bd95d472e8aaeb22ffaf 100644 (file)
@@ -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
index 3bd360d0fff2403005780248989a8df4b52e8cb2..ab1413ee41f31cd9ce56167380623b81e8864045 100644 (file)
@@ -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 */
 }
 
 
index 4cef54152e39127d10f757dde9fcd74aced58992..5ff7107a3ae297e25a4a028fe75bd39e35a814f1 100644 (file)
@@ -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)
index 6fa52b1dfaf19c03376999dab2f0f49bdd09ae74..0b1714ba33b24f40c282ce2100874df5e08be2b1 100644 (file)
@@ -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)
index b118b05a28310cbe5a60e034afeb2e30d7692539..8906db62643ef384ad951114aef0578de22c44cc 100644 (file)
@@ -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);
index 6eb70ca7b306a0463bb09508939e5d45068aaab5..65cde43ef38c533a028846cc289c67ecf7ef30a2 100644 (file)
@@ -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);
index 746523994bb122970f74701860a953c017914c7c..c9b5317689d3dabfdb4abadd948182663f422d2f 100644 (file)
@@ -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;
         }
     }
 
index acc8b1b688071935955701afdeca6f8f6fe83b7b..ab350f60ec4f8e610a2e3be6d3d420a1c37aa3b5 100644 (file)
@@ -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