]> granicus.if.org Git - apache/commitdiff
Merge r1629925, r1629927, r1629928, r1733162, r1733173 from trunk:
authorStefan Eissing <icing@apache.org>
Thu, 17 Mar 2016 09:42:18 +0000 (09:42 +0000)
committerStefan Eissing <icing@apache.org>
Thu, 17 Mar 2016 09:42:18 +0000 (09:42 +0000)
Ensure that httpd exits with an error status when the MPM fails
to run.  [Yann Ylavic]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1735381 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
server/main.c
server/mpm/event/event.c
server/mpm/mpmt_os2/mpmt_os2.c
server/mpm/netware/mpm_netware.c
server/mpm/prefork/prefork.c
server/mpm/winnt/mpm_winnt.c
server/mpm/worker/worker.c

diff --git a/CHANGES b/CHANGES
index caf8a8df27c7c23fe108429030aa454a7253f206..12ed720e6fa4873d79eaa28d692137b0da167bd2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -105,6 +105,9 @@ Changes with Apache 2.4.19
      the SSLVerifyDepth applied with the default/handshaken vhost differs from
      the one applicable with the finally selected vhost.  [Yann Ylavic]
 
+  *) core: Ensure that httpd exits with an error status when the MPM fails
+     to run.  [Yann Ylavic]
+
   *) mod_ssl: Add SSLOCSPProxyURL to add the possibility to do all queries
      to OCSP responders through a HTTP proxy. [Ruediger Pluem]
 
diff --git a/STATUS b/STATUS
index 208248d4b75e8ef2d976a8cdefb6bd567bb3dea8..6964818e299108a0d20cbc42b124e6388999d605 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -112,16 +112,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) core: Ensure that httpd exits with an error status when the MPM fails
-     to run.
-     trunk patch: http://svn.apache.org/r1629925
-                  http://svn.apache.org/r1629927
-                  http://svn.apache.org/r1629928
-                  http://svn.apache.org/r1733162
-                  http://svn.apache.org/r1733173
-     2.4.x patch: http://home.apache.org/~ylavic/patches/httpd-2.4.x-exit_with_error_on_mpm_failure.patch
-     +1: ylavic, jim, icing
-
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
index 28d1872055f96bb9559975a931a732fd7f51016c..cfa5a9d3e5be5a60f8dfc22d894191dd6523de38 100644 (file)
@@ -453,6 +453,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 */
 
@@ -701,7 +702,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);
@@ -774,16 +775,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(02818)
+                     "MPM run failed, exiting");
+    }
+    destroy_and_exit_process(process, rc);
 
-    return 0; /* Termination 'ok' */
+    /* NOTREACHED */
+    return !OK;
 }
 
 #ifdef AP_USING_AUTOCONF
index 23368c7618bb3aa903445ec578d24c27384e96c0..631914eba39015914fdcad9bd4826b41ca689de4 100644 (file)
@@ -2812,7 +2812,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
@@ -3074,7 +3074,7 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
         ap_log_error(APLOG_MARK, APLOG_ALERT | level_flags, 0,
                      (startup ? NULL : s),
                      "no listening sockets available, shutting down");
-        return DONE;
+        return !OK;
     }
 
     if (one_process) {
@@ -3089,7 +3089,7 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
         ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                      (startup ? NULL : s),
                      "could not duplicate listeners");
-        return DONE;
+        return !OK;
     }
 
     all_buckets = apr_pcalloc(pconf, num_buckets * sizeof(*all_buckets));
@@ -3099,7 +3099,7 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
             ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                          (startup ? NULL : s),
                          "could not open pipe-of-death");
-            return DONE;
+            return !OK;
         }
         all_buckets[i].listeners = listen_buckets[i];
     }
index 2380e2e537505b1814cff53f99b34ba96f752405..ccce767faba938b9ec062bce8172ae70d9752e83 100644 (file)
@@ -102,7 +102,7 @@ typedef struct {
     listen_socket_t listeners[1];
 } parent_info_t;
 
-static char master_main();
+static int master_main();
 static void spawn_child(int slot);
 void ap_mpm_child_main(apr_pool_t *pconf);
 static void set_signals();
@@ -153,34 +153,35 @@ 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 */
-        char restart;
+        int rc;
         is_parent_process = TRUE;
 
         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);
 
-        restart = master_main();
+        rc = master_main();
         ++ap_my_generation;
         ap_scoreboard_image->global->running_generation = ap_my_generation;
 
-        if (!restart) {
+        if (rc != OK) {
             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;
+                         "caught %s, shutting down",
+                         (rc == DONE) ? "SIGTERM" : "error");
+            return rc;
         }
     }  /* Parent process */
 
-    return 0; /* Restart */
+    return OK; /* Restart */
 }
 
 
@@ -188,7 +189,7 @@ static int mpmt_os2_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
 /* Main processing of the parent process
  * returns TRUE if restarting
  */
-static char master_main()
+static int master_main()
 {
     server_rec *s = ap_server_conf;
     ap_listen_rec *lr;
@@ -203,7 +204,7 @@ static char master_main()
     if (ap_setup_listeners(ap_server_conf) < 1) {
         ap_log_error(APLOG_MARK, APLOG_ALERT, 0, s, APLOGNO(00202)
                      "no listening sockets available, shutting down");
-        return FALSE;
+        return !OK;
     }
 
     /* Allocate a shared memory block for the array of listeners */
@@ -219,7 +220,7 @@ static char master_main()
     if (rc) {
         ap_log_error(APLOG_MARK, APLOG_ALERT, APR_FROM_OS_ERROR(rc), s, APLOGNO(00203)
                      "failure allocating shared memory, shutting down");
-        return FALSE;
+        return !OK;
     }
 
     /* Store the listener sockets in the shared memory area for our children to see */
@@ -236,7 +237,7 @@ static char master_main()
     if (rc) {
         ap_log_error(APLOG_MARK, APLOG_ALERT, APR_FROM_OS_ERROR(rc), s, APLOGNO(00204)
                      "failure creating accept mutex, shutting down");
-        return FALSE;
+        return !OK;
     }
 
     parent_info->accept_mutex = ap_mpm_accept_mutex;
@@ -251,7 +252,7 @@ static char master_main()
         if (rc) {
             ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf, APLOGNO(00205)
                          "unable to allocate shared memory for scoreboard , exiting");
-            return FALSE;
+            return !OK;
         }
 
         ap_init_scoreboard(sb_mem);
@@ -266,7 +267,7 @@ static char master_main()
     if (one_process) {
         ap_scoreboard_image->parent[0].pid = getpid();
         ap_mpm_child_main(pconf);
-        return FALSE;
+        return DONE;
     }
 
     while (!restart_pending && !shutdown_pending) {
@@ -318,7 +319,7 @@ static char master_main()
     }
 
     DosFreeMem(parent_info);
-    return restart_pending;
+    return restart_pending ? OK : DONE;
 }
 
 
index d86ed23f6a070f71c0fd7186e18e14fb11ad41c6..42d2a54196ca7a4ca48852ab97de72cd0e564d99 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 f2b4e410cc9d8bbc86ffb5b9f98b7a29493e7623..68709dbb5dbdc1cf602a74298b5891e405751d2e 100644 (file)
@@ -963,7 +963,7 @@ static int prefork_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
@@ -979,7 +979,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 since num_buckets depends on the
@@ -1059,7 +1059,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)
@@ -1296,7 +1296,7 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         ap_log_error(APLOG_MARK, APLOG_ALERT | level_flags, 0,
                      (startup ? NULL : s),
                      "no listening sockets available, shutting down");
-        return DONE;
+        return !OK;
     }
 
     if (one_process) {
@@ -1311,7 +1311,7 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                      (startup ? NULL : s),
                      "could not duplicate listeners");
-        return DONE;
+        return !OK;
     }
     all_buckets = apr_pcalloc(pconf, num_buckets *
                                      sizeof(prefork_child_bucket));
@@ -1320,7 +1320,7 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
             ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                          (startup ? NULL : s),
                          "could not open pipe-of-death");
-            return DONE;
+            return !OK;
         }
         /* Initialize cross-process accept lock (safe accept needed only) */
         if ((rv = SAFE_ACCEPT((apr_snprintf(id, sizeof id, "%i", i),
@@ -1330,7 +1330,7 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
             ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                          (startup ? NULL : s),
                          "could not create accept mutex");
-            return DONE;
+            return !OK;
         }
         all_buckets[i].listeners = listen_buckets[i];
     }
index 3d9ef15e5e7d615f24982c3058b3bb813d2a15dc..cf11e0cc21245b7fa87aa63ac2cbc25d7015bdea 100644 (file)
@@ -1660,7 +1660,7 @@ static int winnt_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, s
     if (ap_setup_listeners(s) < 1) {
         ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0,
                      NULL, APLOGNO(00451) "no listening sockets available, shutting down");
-        return DONE;
+        return !OK;
     }
 
     return OK;
@@ -1713,7 +1713,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 89f7ae11e4ca1f77acb168caea09165013d66785..be3895064b6e6e1b92f815c7d7050bedd284a41f 100644 (file)
@@ -1813,7 +1813,7 @@ static int worker_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
@@ -2031,7 +2031,7 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         ap_log_error(APLOG_MARK, APLOG_ALERT | level_flags, 0,
                      (startup ? NULL : s),
                      "no listening sockets available, shutting down");
-        return DONE;
+        return !OK;
     }
 
     if (one_process) {
@@ -2046,7 +2046,7 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                      (startup ? NULL : s),
                      "could not duplicate listeners");
-        return DONE;
+        return !OK;
     }
 
     all_buckets = apr_pcalloc(pconf, num_buckets * sizeof(*all_buckets));
@@ -2056,7 +2056,7 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
             ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                          (startup ? NULL : s),
                          "could not open pipe-of-death");
-            return DONE;
+            return !OK;
         }
         /* Initialize cross-process accept lock (safe accept needed only) */
         if ((rv = SAFE_ACCEPT((apr_snprintf(id, sizeof id, "%i", i),
@@ -2066,7 +2066,7 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
             ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
                          (startup ? NULL : s),
                          "could not create accept mutex");
-            return DONE;
+            return !OK;
         }
         all_buckets[i].listeners = listen_buckets[i];
     }