]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
fix the problem where a scoreboard init failure could leave
authorJeff Trawick <trawick@apache.org>
Mon, 28 Jan 2002 00:41:32 +0000 (00:41 +0000)
committerJeff Trawick <trawick@apache.org>
Mon, 28 Jan 2002 00:41:32 +0000 (00:41 +0000)
mod_cgid stranded

a pre_mpm hook can now return failures, so problems in
ap_create_scoreboard percolate back to a place where Apache
can exit cleanly

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93055 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
CHANGES
STATUS
include/ap_mmn.h
include/scoreboard.h
server/mpm/beos/beos.c
server/mpm/experimental/perchild/perchild.c
server/mpm/netware/mpm_netware.c
server/mpm/perchild/perchild.c
server/mpm/prefork/prefork.c
server/mpm/winnt/mpm_winnt.c
server/mpm/worker/worker.c
server/scoreboard.c

diff --git a/CHANGES b/CHANGES
index b3e5ec4d0af4735cfc767f52cc7f3a0d0fcaced9..b467e67190f16f895e8738c5d3e2a978343e19df 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,9 @@
 Changes with Apache 2.0.31-dev
+
+  *) Change the pre_mpm hook to return a value, so that scoreboard
+     init errors percolate up to code that knows how to exit 
+     cleanly.  This required bump to the MMN.  [Jeff Trawick]
+
   *) Add the socket back to the conn_rec and remove the create_connection
      hook. The create_connection hook had a design flaw that did not 
      allow creating connections based on vhost info. [Bill Stoddard]
diff --git a/STATUS b/STATUS
index 37dfadf122c72bca0d198e71194fd497d614a62f..dad73d49e8fd443b640ff3ba383a886084061b03 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                             -*-text-*-
-Last modified at [$Date: 2002/01/27 08:11:09 $]
+Last modified at [$Date: 2002/01/28 00:41:31 $]
 
 Release:
 
@@ -92,11 +92,6 @@ RELEASE SHOWSTOPPERS:
                 platforms, and should only be used in MPMs like worker
                 with limited OS exposure.
 
-    * ap_create_scoreboard() can exit the process, leaving stuff like
-      mod_cgid's daemon process stranded.  Either ap_create_scoreboard()
-      needs to be called at a different time or the pre-mpm hook needs
-      to be able to return an error code.
-
     * A binbuild installation picks up the right libraries when
       running apachectl because we set the appropriate environment
       variable, but ab, htpasswd, etc. don't know how to pick up apr,
index 8191c18e89d287b97ad74e0f7021c49cdf305887..8e5a0aaf27b5b8656189b708987b542b23dfac1d 100644 (file)
@@ -93,6 +93,7 @@
  * 20020114 (2.0.31-dev) mod_dav changed how it asks its provider to fulfill
  *                       a GET request
  * 20020118 (2.0.31-dev) Input filtering split of blocking and mode
+ * 20020127 (2.0.31-dev) bump for pre_mpm hook change
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */
index 30b8d97c2fabe4a64aefba50856d05980518bb67..c8c67d7abc08985d21f6a2cd91f3f91ca5214a99 100644 (file)
@@ -184,7 +184,7 @@ typedef struct ap_sb_handle_t ap_sb_handle_t;
 AP_DECLARE(int) ap_exists_scoreboard_image(void);
 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
 
-void ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
+int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
 apr_status_t reopen_scoreboard(apr_pool_t *p, int detached);
 void ap_init_scoreboard(void *shared_score);
 int ap_calc_scoreboard_size(void);
@@ -218,8 +218,9 @@ AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation;
   * @param p       Apache pool to allocate from.
   * @param sb_type 
   * @ingroup hooks
+  * @return OK or DECLINE on success; anything else is a error
   */  
-AP_DECLARE_HOOK(void, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
+AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
 
 /* for time_process_request() in http_main.c */
 #define START_PREQUEST 1
index f9800d7b87cff5fc03acb4493f73f00fceac0831..97fd7afa72f67ff425b5a3957b445e35395b5470 100644 (file)
@@ -837,7 +837,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     
     if (!is_graceful) {
         /* setup the scoreboard shared memory */
-        ap_run_pre_mpm(pconf, SB_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+            return 1;
+        }
 
         for (i = 0; i < HARD_SERVER_LIMIT; i++) {
             ap_scoreboard_image->parent[i].pid = 0;
index b02c76be5abeea5ca6c7be9c1b0222b00490ff6a..ff91d30d1ae10d558c83cbf0b394d737860883f9 100644 (file)
@@ -1305,7 +1305,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     }
 
     if (!is_graceful) {
-        ap_run_pre_mpm(pconf, SB_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+            return 1;
+        }
     }
     /* Initialize the child table */
     if (!is_graceful) {
index eed96e7847f1850d182320feede28b04329a8db3..dbe0a98bc0c45c2a72ae0568d2a37bfba986a4ec 100644 (file)
@@ -881,7 +881,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     apr_thread_mutex_create(&accept_mutex, APR_THREAD_MUTEX_DEFAULT, pconf);
 
     if (!is_graceful) {
-        ap_run_pre_mpm(pconf, SB_NOT_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_NOT_SHARED) != OK) {
+            return 1;
+        }
     }
 
     /* Only set slot 0 since that is all NetWare will ever have. */
index b02c76be5abeea5ca6c7be9c1b0222b00490ff6a..ff91d30d1ae10d558c83cbf0b394d737860883f9 100644 (file)
@@ -1305,7 +1305,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     }
 
     if (!is_graceful) {
-        ap_run_pre_mpm(pconf, SB_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+            return 1;
+        }
     }
     /* Initialize the child table */
     if (!is_graceful) {
index 3710663180dedfbe8280b180f34f1470de96ce5e..5d48e73ee5018db71a73aa31695c074b8b3ef56a 100644 (file)
@@ -1001,7 +1001,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 
     SAFE_ACCEPT(accept_mutex_init(pconf));
     if (!is_graceful) {
-        ap_run_pre_mpm(pconf, SB_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+            return 1;
+        }
     }
 #ifdef SCOREBOARD_FILE
     else {
index 4b05832108183492b50acc1859a7c306c3a489bc..fb3236ba8e33e071adb77afd456bca8c9cf901ac 100644 (file)
@@ -2101,7 +2101,9 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
 
         if (one_process) {
             /* Set up the scoreboard. */
-            ap_run_pre_mpm(pconf, SB_SHARED);
+            if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+                return 1;
+            }
             if (ap_setup_listeners(ap_server_conf) < 1) {
                 return 1;
             }
@@ -2130,7 +2132,9 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
                 exit(1);
             }
 
-            ap_run_pre_mpm(pconf, SB_SHARED_CHILD);
+            if (ap_run_pre_mpm(pconf, SB_SHARED_CHILD) != OK) {
+                exit(1);
+            }
             ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
             get_listeners_from_parent(ap_server_conf);
         }
@@ -2148,7 +2152,9 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
     }
     else /* Child */ { 
         /* Set up the scoreboard. */
-        ap_run_pre_mpm(pconf, SB_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+            return 1;
+        }
 
         /* Parent process */
         if (ap_setup_listeners(ap_server_conf) < 1) {
index 137bc4aaa62b4c0c9f31c534fef6da1254aad9dd..f3f2248c0b5dbf053d5ab76aa060e32ecd65a437 100644 (file)
@@ -1422,7 +1422,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     }
 
     if (!is_graceful) {
-        ap_run_pre_mpm(pconf, SB_SHARED);
+        if (ap_run_pre_mpm(pconf, SB_SHARED) != OK) {
+            return 1;
+        }
     }
 
     set_signals();
@@ -1709,6 +1711,9 @@ static const char *set_max_clients (cmd_parms *cmd, void *dummy,
                     ap_daemons_limit);
        max_clients = ap_daemons_limit * ap_threads_per_child; 
     }
+    /* XXX
+     * ap_daemons_limit can reach server_limit * ap_threads_per_child, right?
+     */
     if (ap_daemons_limit > server_limit) {
        ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
                     "WARNING: MaxClients of %d would require %d servers,",
index 396627f24cc4c9f56fe4a0c98677eb4ce71b8006..23e454151796cffc046ae8337dcaf6e33f4b9547 100644 (file)
@@ -99,9 +99,9 @@ APR_HOOK_STRUCT(
     APR_HOOK_LINK(pre_mpm)
 )
  
-AP_IMPLEMENT_HOOK_VOID(pre_mpm,
-                       (apr_pool_t *p, ap_scoreboard_e sb_type),
-                       (p, sb_type))
+AP_IMPLEMENT_HOOK_RUN_ALL(int,pre_mpm,
+                          (apr_pool_t *p, ap_scoreboard_e sb_type),
+                          (p, sb_type),OK,DECLINED)
 
 struct ap_sb_handle_t {
     int child_num;
@@ -237,7 +237,7 @@ apr_status_t ap_cleanup_scoreboard(void *d)
 /* Create or reinit an existing scoreboard. The MPM can control whether
  * the scoreboard is shared across multiple processes or not
  */
-void ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
+int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
 {
     int running_gen = 0;
 #if APR_HAS_SHARED_MEMORY
@@ -255,7 +255,7 @@ void ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
             void *sb_shared;
             rv = open_scoreboard(p);
             if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
-                exit(APEXIT_INIT); /* XXX need to return an error from this function */
+                return HTTP_INTERNAL_SERVER_ERROR;
             }
             memset(sb_shared, 0, scoreboard_size);
             ap_init_scoreboard(sb_shared);
@@ -264,7 +264,7 @@ void ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
             void *sb_shared;
             rv = reopen_scoreboard(p, 1);
             if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
-                exit(APEXIT_INIT); /* XXX need to return an error from this function */
+                return HTTP_INTERNAL_SERVER_ERROR;
             }
             ap_init_scoreboard(sb_shared);
         }
@@ -277,7 +277,7 @@ void ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
                 ap_log_error(APLOG_MARK, APLOG_CRIT | APLOG_NOERRNO, 0, NULL,
                              "(%d)%s: cannot allocate scoreboard",
                              errno, strerror(errno));
-                exit(APEXIT_INIT); /* XXX need to return an error from this function */
+                return HTTP_INTERNAL_SERVER_ERROR;
             }
             ap_init_scoreboard(sb_mem);
         }
@@ -290,6 +290,7 @@ void ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
                                   apr_pool_cleanup_null);
     }
     ap_restart_time = apr_time_now();
+    return OK;
 }
 
 /* Routines called to deal with the scoreboard image