From: Jeff Trawick Date: Mon, 28 Jan 2002 00:41:32 +0000 (+0000) Subject: fix the problem where a scoreboard init failure could leave X-Git-Tag: 2.0.31~66 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7c1ce28ee134aaf458712661479b440700ba0705;p=thirdparty%2Fapache%2Fhttpd.git fix the problem where a scoreboard init failure could leave 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 --- diff --git a/CHANGES b/CHANGES index b3e5ec4d0af..b467e67190f 100644 --- 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 37dfadf122c..dad73d49e8f 100644 --- 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, diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 8191c18e89d..8e5a0aaf27b 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -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" */ diff --git a/include/scoreboard.h b/include/scoreboard.h index 30b8d97c2fa..c8c67d7abc0 100644 --- a/include/scoreboard.h +++ b/include/scoreboard.h @@ -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 diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index f9800d7b87c..97fd7afa72f 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -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; diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index b02c76be5ab..ff91d30d1ae 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -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) { diff --git a/server/mpm/netware/mpm_netware.c b/server/mpm/netware/mpm_netware.c index eed96e7847f..dbe0a98bc0c 100644 --- a/server/mpm/netware/mpm_netware.c +++ b/server/mpm/netware/mpm_netware.c @@ -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. */ diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index b02c76be5ab..ff91d30d1ae 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -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) { diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 3710663180d..5d48e73ee50 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -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 { diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 4b058321081..fb3236ba8e3 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -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) { diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 137bc4aaa62..f3f2248c0b5 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -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,", diff --git a/server/scoreboard.c b/server/scoreboard.c index 396627f24cc..23e45415179 100644 --- a/server/scoreboard.c +++ b/server/scoreboard.c @@ -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