From: Jeff Trawick Date: Wed, 25 Mar 2009 08:30:18 +0000 (+0000) Subject: Provide ap_set_retained_data()/ap_get_retained_data() for preservation X-Git-Tag: 2.3.3~829 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9db133b4a8dbcf3af10ff5d9e3dda4608d44f378;p=apache 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).) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@758173 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index e16d0be1b1..e8c8e81753 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 8c003d28bb..aaaff2e456 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -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 diff --git a/include/http_config.h b/include/http_config.h index cba626ea58..6ad9087046 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -915,6 +915,21 @@ AP_DECLARE(int) ap_process_config_tree(server_rec *s, 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 diff --git a/include/http_main.h b/include/http_main.h index 545ba5ac13..dc0a0de61b 100644 --- a/include/http_main.h +++ b/include/http_main.h @@ -45,6 +45,8 @@ AP_DECLARE_DATA extern const char *ap_server_argv0; 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 diff --git a/server/config.c b/server/config.c index fc2cb31dfa..f87c44c384 100644 --- a/server/config.c +++ b/server/config.c @@ -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 @@ AP_DECLARE(void) ap_show_modules(void) 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; +} diff --git a/server/main.c b/server/main.c index 48a5c234f1..5dff38339a 100644 --- a/server/main.c +++ b/server/main.c @@ -471,7 +471,6 @@ int main(int argc, const char * const argv[]) 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 @@ int main(int argc, const char * const argv[]) 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 @@ int main(int argc, const char * const argv[]) 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 @@ int main(int argc, const char * const argv[]) 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");