From: Stefan Fritsch Date: Sat, 12 Feb 2011 21:18:32 +0000 (+0000) Subject: Create new ap_state_query() function that allows modules to determine X-Git-Tag: 2.3.11~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6de9e9f67189d8ac673b9af0be40f5101d907ef;p=thirdparty%2Fapache%2Fhttpd.git Create new ap_state_query() function that allows modules to determine if the current configuration run is the initial one at server startup, and if the server is started for testing/config dumping only. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1070151 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index f0554a8958e..23a1547ba56 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,11 @@ Changes with Apache 2.3.11 + *) core: Create new ap_state_query function that allows modules to determine + if the current configuration run is the initial one at server startup, + and if the server is started for testing/config dumping only. + [Stefan Fritsch] + *) mod_cache: When a bad Expires date is present, we need to behave as if the Expires is in the past, not as if the Expires is missing. PR 16521. [Co-Advisor ] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 0fd1eb63ad8..678286d665d 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -299,6 +299,7 @@ * Add pool argument to ap_add_file_conf(). * 20110117.1 (2.3.11-dev) Add ap_pstr2_alnum() and ap_str2_alnum() * 20110203.0 (2.3.11-dev) Raise DYNAMIC_MODULE_LIMIT to 256 + * 20110203.1 (2.3.11-dev) Add ap_state_query() */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -306,7 +307,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20110203 #endif -#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/http_core.h b/include/http_core.h index e9df5c826ce..3dff5e7af77 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -792,6 +792,52 @@ APR_DECLARE_OPTIONAL_FN(int, access_compat_ap_satisfies, (request_rec *r)); /* ---------------------------------------------------------------------- */ +/** Query the server for some state information + * @param query_code Which information is requested + * @return the requested state information + */ +AP_DECLARE(int) ap_state_query(int query_code); + +/* + * possible values for query_code in ap_state_query() + */ + + /** current status of the server */ +#define AP_SQ_MAIN_STATE 0 + /** are we going to serve requests or are we just testing/dumping config */ +#define AP_SQ_RUN_MODE 1 + +/* + * return values for ap_state_query() + */ + + /** return value for unknown query_code */ +#define AP_SQ_NOT_SUPPORTED -1 + +/* values returned for AP_SQ_MAIN_STATE */ + /** before the config preflight */ +#define AP_SQ_MS_INITIAL_STARTUP 1 + /** initial configuration run for setting up log config, etc. */ +#define AP_SQ_MS_CREATE_PRE_CONFIG 2 + /** tearing down configuration */ +#define AP_SQ_MS_DESTROY_CONFIG 3 + /** normal configuration run */ +#define AP_SQ_MS_CREATE_CONFIG 4 + /** running the MPM */ +#define AP_SQ_MS_RUN_MPM 5 + /** cleaning up for exit */ +#define AP_SQ_MS_EXITING 6 + +/* values returned for AP_SQ_RUN_MODE */ + /** command line not yet parsed */ +#define AP_SQ_RM_UNKNOWN 1 + /** normal operation (server requests or signal server) */ +#define AP_SQ_RM_NORMAL 2 + /** config test only */ +#define AP_SQ_RM_CONFIG_TEST 3 + /** only dump some parts of the config */ +#define AP_SQ_RM_CONFIG_DUMP 4 + #ifdef __cplusplus } #endif diff --git a/include/http_main.h b/include/http_main.h index 9af84c69e5f..1079507c80f 100644 --- a/include/http_main.h +++ b/include/http_main.h @@ -47,6 +47,10 @@ AP_DECLARE_DATA extern const char *ap_server_root; AP_DECLARE_DATA extern server_rec *ap_server_conf; /** global pool, for access prior to creation of server_rec */ AP_DECLARE_DATA extern apr_pool_t *ap_pglobal; +/** state of the server (startup, exiting, ...) */ +AP_DECLARE_DATA int ap_main_state; +/** run mode (normal, config test, config dump, ...) */ +AP_DECLARE_DATA int ap_run_mode; /* for -C, -c and -D switches */ /** An array of all -C directives. These are processed before the server's diff --git a/server/core.c b/server/core.c index 90b9290af73..caa02e69e35 100644 --- a/server/core.c +++ b/server/core.c @@ -110,6 +110,9 @@ static char errordocument_default; static apr_array_header_t *saved_server_config_defines = NULL; static apr_table_t *server_config_defined_vars = NULL; +AP_DECLARE_DATA int ap_main_state = AP_SQ_MS_INITIAL_STARTUP; +AP_DECLARE_DATA int ap_run_mode = AP_SQ_RM_UNKNOWN; + static void *create_core_dir_config(apr_pool_t *a, char *dir) { core_dir_config *conf; @@ -4341,6 +4344,18 @@ static int core_pre_connection(conn_rec *c, void *csd) return DONE; } +AP_DECLARE(int) ap_state_query(int query) +{ + switch (query) { + case AP_SQ_MAIN_STATE: + return ap_main_state; + case AP_SQ_RUN_MODE: + return ap_run_mode; + default: + return AP_SQ_NOT_SUPPORTED; + } +} + static void register_hooks(apr_pool_t *p) { errorlog_hash = apr_hash_make(p); diff --git a/server/main.c b/server/main.c index 3ea53d4bb42..dba315a06ca 100644 --- a/server/main.c +++ b/server/main.c @@ -259,6 +259,7 @@ static void destroy_and_exit_process(process_rec *process, * might get lost. */ apr_sleep(TASK_SWITCH_SLEEP); + ap_main_state = AP_SQ_MS_EXITING; apr_pool_destroy(process->pool); /* and destroy all descendent pools */ apr_terminate(); exit(process_exit_value); @@ -439,7 +440,7 @@ static void usage(process_rec *process) int main(int argc, const char * const argv[]) { char c; - int configtestonly = 0, showcompile = 0; + int showcompile = 0; const char *confname = SERVER_CONFIG_FILE; const char *def_server_root = HTTPD_ROOT; const char *temp_error_log = NULL; @@ -516,10 +517,10 @@ int main(int argc, const char * const argv[]) *new = apr_pstrdup(pcommands, opt_arg); /* Setting -D DUMP_VHOSTS is equivalent to setting -S */ if (strcmp(opt_arg, "DUMP_VHOSTS") == 0) - configtestonly = 1; + ap_run_mode = AP_SQ_RM_CONFIG_DUMP; /* Setting -D DUMP_MODULES is equivalent to setting -M */ if (strcmp(opt_arg, "DUMP_MODULES") == 0) - configtestonly = 1; + ap_run_mode = AP_SQ_RM_CONFIG_DUMP; break; case 'e': @@ -545,16 +546,6 @@ int main(int argc, const char * const argv[]) printf("Server built: %s\n", ap_get_server_built()); destroy_and_exit_process(process, 0); - case 'V': - if (strcmp(ap_show_mpm(), "")) { /* MPM built-in? */ - show_compile_settings(); - destroy_and_exit_process(process, 0); - } - else { - showcompile = 1; - } - break; - case 'l': ap_show_modules(); destroy_and_exit_process(process, 0); @@ -564,7 +555,8 @@ int main(int argc, const char * const argv[]) destroy_and_exit_process(process, 0); case 't': - configtestonly = 1; + if (ap_run_mode == AP_SQ_RM_UNKNOWN) + ap_run_mode = AP_SQ_RM_CONFIG_TEST; break; case 'T': @@ -572,28 +564,43 @@ int main(int argc, const char * const argv[]) break; case 'S': - configtestonly = 1; + ap_run_mode = AP_SQ_RM_CONFIG_DUMP; new = (char **)apr_array_push(ap_server_config_defines); *new = "DUMP_VHOSTS"; break; case 'M': - configtestonly = 1; + ap_run_mode = AP_SQ_RM_CONFIG_DUMP; new = (char **)apr_array_push(ap_server_config_defines); *new = "DUMP_MODULES"; break; + case 'V': + if (strcmp(ap_show_mpm(), "")) { /* MPM built-in? */ + show_compile_settings(); + destroy_and_exit_process(process, 0); + } + else { + showcompile = 1; + ap_run_mode = AP_SQ_RM_CONFIG_DUMP; + } + break; + case 'h': case '?': usage(process); } } + if (ap_run_mode == AP_SQ_RM_UNKNOWN) + ap_run_mode = AP_SQ_RM_NORMAL; + /* bad cmdline option? then we die */ if (rv != APR_EOF || opt->ind < opt->argc) { usage(process); } + ap_main_state = AP_SQ_MS_CREATE_PRE_CONFIG; apr_pool_create(&plog, ap_pglobal); apr_pool_tag(plog, "plog"); apr_pool_create(&ptemp, pconf); @@ -633,13 +640,15 @@ int main(int argc, const char * const argv[]) destroy_and_exit_process(process, 1); } - if (configtestonly) { - ap_run_test_config(pconf, ap_server_conf); - ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK"); - destroy_and_exit_process(process, 0); - } - else if (showcompile) { /* deferred due to dynamically loaded MPM */ - show_compile_settings(); + if (ap_run_mode != AP_SQ_RM_NORMAL) { + if (showcompile) { /* deferred due to dynamically loaded MPM */ + show_compile_settings(); + } + else { + ap_run_test_config(pconf, ap_server_conf); + if (ap_run_mode == AP_SQ_RM_CONFIG_TEST) + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK"); + } destroy_and_exit_process(process, 0); } } @@ -675,10 +684,12 @@ int main(int argc, const char * const argv[]) apr_pool_destroy(ptemp); for (;;) { + ap_main_state = AP_SQ_MS_DESTROY_CONFIG; apr_hook_deregister_all(); apr_pool_clear(pconf); ap_clear_auth_internal(); + ap_main_state = AP_SQ_MS_CREATE_CONFIG; for (mod = ap_prelinked_modules; *mod != NULL; mod++) { ap_register_hooks(*mod, pconf); } @@ -734,6 +745,7 @@ 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;