Commit eca0e889 authored by Stefan Fritsch's avatar Stefan Fritsch
Browse files

Use ap_state_query() to fix many modules that were not correctly initializing

if they were not active during server startup but got enabled later during a
graceful restart (in which case they need to do all work during a single
config run).


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1070153 13f79535-47bb-0310-9956-ffa450edef68
parent 3e2a9f52
Loading
Loading
Loading
Loading
+4 −0
Changes for CHANGES: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@

Changes with Apache 2.3.11

  *) modules: Fix many modules that were not correctly initializing if they
     were not active during server startup but got enabled later during a
     graceful restart. [Stefan Fritsch]

  *) 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.
+2 −8
Changes for modules/aaa/mod_auth_digest.c: 2 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -382,18 +382,12 @@ static int pre_init(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
static int initialize_module(apr_pool_t *p, apr_pool_t *plog,
                             apr_pool_t *ptemp, server_rec *s)
{
    void *data;
    const char *userdata_key = "auth_digest_init";

    /* initialize_module() will be called twice, and if it's a DSO
     * then all static data from the first call will be lost. Only
     * set up our static data on the second call. */
    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
        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;
    }

    if (initialize_secret(s) != APR_SUCCESS) {
        return !OK;
    }
+2 −7
Changes for modules/cluster/mod_heartmonitor.c: 2 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -665,8 +665,6 @@ static int hm_post_config(apr_pool_t *p, apr_pool_t *plog,
                          apr_pool_t *ptemp, server_rec *s)
{
    apr_status_t rv;
    const char *userdata_key = "mod_heartmonitor_init";
    void *data;
    hm_ctx_t *ctx = ap_get_module_config(s->module_config,
                                         &heartmonitor_module);
    APR_OPTIONAL_FN_TYPE(ap_watchdog_get_instance) *hm_watchdog_get_instance;
@@ -681,11 +679,8 @@ static int hm_post_config(apr_pool_t *p, apr_pool_t *plog,
    }

    /* Create the slotmem */
    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
        /* first call do nothing */
        apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
    } else {
    if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_CONFIG) {
        /* this is the real thing */
        if (maxworkers) {
            storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shared", "0");
            if (!storage) {
+5 −3
Changes for modules/core/mod_watchdog.c: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "mod_watchdog.h"
#include "ap_provider.h"
#include "ap_mpm.h"
#include "http_core.h"
#include "util_mutex.h"

#define AP_WATCHODG_PGROUP    "watchdog"
@@ -444,11 +445,12 @@ static int wd_post_config_hook(apr_pool_t *pconf, apr_pool_t *plog,
        if (!(wd_server_conf = apr_pcalloc(pproc, sizeof(wd_server_conf_t))))
            return APR_ENOMEM;
        apr_pool_create(&wd_server_conf->pool, pproc);
        wd_server_conf->s = s;
        apr_pool_userdata_set(wd_server_conf, pk, apr_pool_cleanup_null, pproc);
    }

    if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG)
        /* First time config phase -- skip. */
        return OK;
    }

#if defined(WIN32)
    {
        const char *ppid = getenv("AP_PARENT_PID");
+6 −21
Changes for modules/examples/mod_example_ipc.c: 6 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -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.
     */ 
    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.
     * 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. 
     */ 
        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.
Loading