]> granicus.if.org Git - apache/blobdiff - modules/examples/mod_example_ipc.c
Use ap_state_query() to fix many modules that were not correctly initializing
[apache] / modules / examples / mod_example_ipc.c
index ef39cd7b61bc809ccea5a2eb3ef35284e84a5a3f..483881b580fb04015c3b15cb7db9f73dbcd1e2c7 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "httpd.h"
 #include "http_config.h"
+#include "http_core.h"
 #include "http_log.h"
 #include "http_protocol.h"
 #include "util_mutex.h"
@@ -117,35 +118,19 @@ static int exipc_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
 static int exipc_post_config(apr_pool_t *pconf, apr_pool_t *plog, 
                              apr_pool_t *ptemp, server_rec *s)
 {
-    void *data; /* These two help ensure that we only init once. */
-    const char *userdata_key;
     apr_status_t rs;
     exipc_data *base;
     const char *tempdir; 
 
 
     /* 
-     * The following checks if this routine has been called before. 
-     * This is necessary because the parent process gets initialized
-     * a couple of times as the server starts up, and we don't want 
-     * to create any more mutexes and shared memory segments than
-     * we're actually going to use. 
-     * 
-     * The key needs to be unique for the entire web server, so put
-     * the module name in it.
+     * Do nothing if we are not creating the final configuration.
+     * The parent process gets initialized a couple of times as the
+     * server starts up, and we don't want to create any more mutexes
+     * and shared memory segments than we're actually going to use. 
      */ 
-    userdata_key = "example_ipc_init_module";
-    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
-    if (!data) {
-        /* 
-         * If no data was found for our key, this must be the first
-         * time the module is initialized. Put some data under that
-         * key and return.
-         */
-        apr_pool_userdata_set((const void *) 1, userdata_key, 
-                              apr_pool_cleanup_null, s->process->pool);
+    if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG)
         return OK;
-    } /* Kilroy was here */
 
     /* 
      * The shared memory allocation routines take a file name.