You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by sf...@apache.org on 2011/02/12 22:18:34 UTC

svn commit: r1070151 - in /httpd/httpd/trunk: CHANGES include/ap_mmn.h include/http_core.h include/http_main.h server/core.c server/main.c

Author: sf
Date: Sat Feb 12 21:18:32 2011
New Revision: 1070151

URL: http://svn.apache.org/viewvc?rev=1070151&view=rev
Log:
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.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/include/ap_mmn.h
    httpd/httpd/trunk/include/http_core.h
    httpd/httpd/trunk/include/http_main.h
    httpd/httpd/trunk/server/core.c
    httpd/httpd/trunk/server/main.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1070151&r1=1070150&r2=1070151&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Sat Feb 12 21:18:32 2011
@@ -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 <co...@measurement-factory.com>]

Modified: httpd/httpd/trunk/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_mmn.h?rev=1070151&r1=1070150&r2=1070151&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_mmn.h (original)
+++ httpd/httpd/trunk/include/ap_mmn.h Sat Feb 12 21:18:32 2011
@@ -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

Modified: httpd/httpd/trunk/include/http_core.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_core.h?rev=1070151&r1=1070150&r2=1070151&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_core.h (original)
+++ httpd/httpd/trunk/include/http_core.h Sat Feb 12 21:18:32 2011
@@ -792,6 +792,52 @@ APR_DECLARE_OPTIONAL_FN(int, access_comp
 
 /* ---------------------------------------------------------------------- */
 
+/** 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

Modified: httpd/httpd/trunk/include/http_main.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_main.h?rev=1070151&r1=1070150&r2=1070151&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_main.h (original)
+++ httpd/httpd/trunk/include/http_main.h Sat Feb 12 21:18:32 2011
@@ -47,6 +47,10 @@ AP_DECLARE_DATA extern const char *ap_se
 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

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=1070151&r1=1070150&r2=1070151&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Sat Feb 12 21:18:32 2011
@@ -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 
     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);

Modified: httpd/httpd/trunk/server/main.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/main.c?rev=1070151&r1=1070150&r2=1070151&view=diff
==============================================================================
--- httpd/httpd/trunk/server/main.c (original)
+++ httpd/httpd/trunk/server/main.c Sat Feb 12 21:18:32 2011
@@ -259,6 +259,7 @@ static void destroy_and_exit_process(pro
      * 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 ar
             *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 ar
             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 ar
             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 ar
            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 ar
             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 ar
     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 ar
 
         ap_run_optional_fn_retrieve();
 
+        ap_main_state = AP_SQ_MS_RUN_MPM;
         if (ap_run_mpm(pconf, plog, ap_server_conf) != OK)
             break;