/* ---------------------------------------------------------------------- */
+/** 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
* 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);
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;
*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':
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);
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':
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);
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);
}
}
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);
}
ap_run_optional_fn_retrieve();
+ ap_main_state = AP_SQ_MS_RUN_MPM;
if (ap_run_mpm(pconf, plog, ap_server_conf) != OK)
break;