You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@apache.org on 2009/03/25 09:30:21 UTC

svn commit: r758173 - in /httpd/httpd/trunk: CHANGES include/ap_mmn.h include/http_config.h include/http_main.h server/config.c server/main.c

Author: trawick
Date: Wed Mar 25 08:30:18 2009
New Revision: 758173

URL: http://svn.apache.org/viewvc?rev=758173&view=rev
Log:
Provide ap_set_retained_data()/ap_get_retained_data() for preservation
of module state across unload/load.

The existing idiom used by modules to associate userdata with pglobal
doesn't work in the earliest phases of module execution.

(This does expose pglobal as an implementation detail, but it would be great 
to unexpose it if at all possible (but modules already have access to pglobal
at almost all stages of execution anyway).)

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/include/ap_mmn.h
    httpd/httpd/trunk/include/http_config.h
    httpd/httpd/trunk/include/http_main.h
    httpd/httpd/trunk/server/config.c
    httpd/httpd/trunk/server/main.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=758173&r1=758172&r2=758173&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Wed Mar 25 08:30:18 2009
@@ -2,6 +2,9 @@
 
 Changes with Apache 2.3.3
 
+  *) Provide ap_set_retained_data()/ap_get_retained_data() for preservation
+     of module state across unload/load.  [Jeff Trawick]
+
   *) mod_substitute: Fix a memory leak. PR 44948
      [Dan Poirier <poirier pobox.com>]
 

Modified: httpd/httpd/trunk/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_mmn.h?rev=758173&r1=758172&r2=758173&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_mmn.h (original)
+++ httpd/httpd/trunk/include/ap_mmn.h Wed Mar 25 08:30:18 2009
@@ -189,6 +189,7 @@
  * 20090130.0 (2.3.2-dev)  Add ap_ prefix to unixd_setup_child().
  * 20090131.0 (2.3.2-dev)  Remove ap_default_type(), disable DefaultType
  * 20090208.0 (2.3.2-dev)  Add conn_rec::current_thread.
+ * 20090208.1 (2.3.3-dev)  Add ap_set_retained_data()/ap_get_retained_data()
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -196,7 +197,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20090208
 #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_config.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_config.h?rev=758173&r1=758172&r2=758173&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_config.h (original)
+++ httpd/httpd/trunk/include/http_config.h Wed Mar 25 08:30:18 2009
@@ -915,6 +915,21 @@
                                        apr_pool_t *p,
                                        apr_pool_t *ptemp);
 
+/**
+ * Store data which will be retained across unload/load of modules
+ * @param key The unique key associated with this module's retained data
+ * @param Size in bytes of the retained data (to be allocated)
+ * @return Address of new retained data structure, initially cleared
+ */
+AP_DECLARE(void *) ap_set_retained_data(const char *key, apr_size_t size);
+
+/**
+ * Retrieve data which was stored by ap_set_retained_data()
+ * @param key The unique key associated with this module's retained data
+ * @return Address of previously retained data structure, or NULL if not yet saved
+ */
+AP_DECLARE(void *) ap_get_retained_data(const char *key);
+    
 /* Module-method dispatchers, also for http_request.c */
 /**
  * Run the handler phase of each module until a module accepts the

Modified: httpd/httpd/trunk/include/http_main.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_main.h?rev=758173&r1=758172&r2=758173&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_main.h (original)
+++ httpd/httpd/trunk/include/http_main.h Wed Mar 25 08:30:18 2009
@@ -45,6 +45,8 @@
 AP_DECLARE_DATA extern const char *ap_server_root;
 /** The global server's server_rec */
 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;
 
 /* for -C, -c and -D switches */
 /** An array of all -C directives.  These are processed before the server's

Modified: httpd/httpd/trunk/server/config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/config.c?rev=758173&r1=758172&r2=758173&view=diff
==============================================================================
--- httpd/httpd/trunk/server/config.c (original)
+++ httpd/httpd/trunk/server/config.c Wed Mar 25 08:30:18 2009
@@ -53,6 +53,7 @@
 AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
 AP_DECLARE_DATA const char *ap_server_root = NULL;
 AP_DECLARE_DATA server_rec *ap_server_conf = NULL;
+AP_DECLARE_DATA apr_pool_t *ap_pglobal = NULL;
 
 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL;
 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL;
@@ -2193,3 +2194,19 @@
         printf("  %s\n", ap_loaded_modules[n]->name);
 }
 
+AP_DECLARE(void *) ap_get_retained_data(const char *key)
+{
+    void *retained;
+
+    apr_pool_userdata_get((void *)&retained, key, ap_pglobal);
+    return retained;
+}
+
+AP_DECLARE(void *) ap_set_retained_data(const char *key, apr_size_t size)
+{
+    void *retained;
+
+    retained = apr_pcalloc(ap_pglobal, size);
+    apr_pool_userdata_set((const void *)retained, key, apr_pool_cleanup_null, ap_pglobal);
+    return retained;
+}

Modified: httpd/httpd/trunk/server/main.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/main.c?rev=758173&r1=758172&r2=758173&view=diff
==============================================================================
--- httpd/httpd/trunk/server/main.c (original)
+++ httpd/httpd/trunk/server/main.c Wed Mar 25 08:30:18 2009
@@ -471,7 +471,6 @@
     const char *temp_error_log = NULL;
     const char *error;
     process_rec *process;
-    apr_pool_t *pglobal;
     apr_pool_t *pconf;
     apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
     apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
@@ -485,7 +484,7 @@
     AP_MONCONTROL(0); /* turn off profiling of startup */
 
     process = init_process(&argc, &argv);
-    pglobal = process->pool;
+    ap_pglobal = process->pool;
     pconf = process->pconf;
     ap_server_argv0 = process->short_name;
 
@@ -494,15 +493,15 @@
     apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
 
 #if APR_CHARSET_EBCDIC
-    if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
+    if (ap_init_ebcdic(ap_pglobal) != APR_SUCCESS) {
         destroy_and_exit_process(process, 1);
     }
 #endif
-    if (ap_expr_init(pglobal) != APR_SUCCESS) {
+    if (ap_expr_init(ap_pglobal) != APR_SUCCESS) {
         destroy_and_exit_process(process, 1);
     }
 
-    apr_pool_create(&pcommands, pglobal);
+    apr_pool_create(&pcommands, ap_pglobal);
     apr_pool_tag(pcommands, "pcommands");
     ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
     ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
@@ -639,7 +638,7 @@
         usage(process);
     }
 
-    apr_pool_create(&plog, pglobal);
+    apr_pool_create(&plog, ap_pglobal);
     apr_pool_tag(plog, "plog");
     apr_pool_create(&ptemp, pconf);
     apr_pool_tag(ptemp, "ptemp");