Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.
The following page has been changed by MarcMongenet: http://wiki.apache.org/httpd/ModuleLife ------------------------------------------------------------------------------ * On graceful restart, new children processes may be running on the new configuration while old children on the old configuration are still serving a request. == 1st and next post_config calls == - In the post_config hook, we use apr_pool_userdata_get/set on the process pool to detect if we are called for the first time or not. Using a static variable does not work because the module may be unloaded/reloaded between the two calls. The process pool is not torn down between cycles. + If we want to execute the post_config hook only one, we have to set a flag. + + * Example from http://www.codemass.com/mod_shm_counter/downloads/mod_shm_counter.c {{{ - static int my_module_post_config(apr_pool_t *p, apr_pool_t *plog, + static int shm_counter_post_config(apr_pool_t *pconf, apr_pool_t *plog, - apr_pool_t *ptemp, server_rec *s) + apr_pool_t *ptemp, server_rec *s) + { + apr_status_t rv; + shm_counter_scfg_t *scfg; - void *data; + void *data = NULL; - const char *userdata_key = "my_module_init"; + const char *userdata_key = "shm_counter_post_config"; - /* userdata not set on 1st post_config execution. */ + /* Apache loads DSO modules twice. We want to wait until the second + * load before setting up our global mutex and shared memory segment. + * To avoid the first call to the post_config hook, we set some + * dummy userdata in a pool that lives longer than the first DSO + * load, and only run if that data is set on subsequent calls to + * this hook. */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); - if (!data) { + if (data == NULL) { + /* WARNING: This must *not* be apr_pool_userdata_setn(). The + * reason for this is because the static symbol section of the + * DSO may not be at the same address offset when it is reloaded. + * Since setn() does not make a copy and only compares addresses, + * the get() will be unable to find the original userdata. */ apr_pool_userdata_set((const void *)1, userdata_key, - apr_pool_cleanup_null, s->process->pool); + apr_pool_cleanup_null, s->process->pool); - return OK; + return OK; /* This would be the first time through */ } - }}} + + /* If we made it this far, we can safely initialize the module */}}} === post_config call by children processes === On WinNT MPM, the post_config hook is also called by the children. @@ -37, +53 @@ == Preventing module unloading == To prevent module unloading, there is a ''sick and twisted hack'' (wrowe dixit): "the evil method is to use apr_dso_load() against the process pool to load it 'permanently'". - == Simple module demonstrating portable mutex and shared memory == - * http://www.codemass.com/mod_shm_counter/downloads/mod_shm_counter.c -
