views:

106

answers:

0

Using the apache2 C api, I have created a child_init callback (registered through ap_hook_child_init) that is supposed to set up a per-process resource when the server is first started. Then, as each request comes in through the handler (registered through ap_hook_handler) I want the handler to look up that resource for its own use.

Currently I am attempting to store/retrieve this data using the server_rec->module_config pointer. What I am having trouble with is that the module_config pointed to during the child_init process seems to be different than the module_config pointed to by the handler, so the resource initialization isn't working.

Here's some a snippet code that illustrates my problem. Note that my_module is a global variable. Am I doing something wrong?

static void get_resource(void *module_config) {
    my_config *cfg = (my_config *)ap_get_module_config(module_config, &my_module);
    printf("module_config: %d\n", cfg);

    //...
}

static int my_handler(request_rec *r){
    //...
    printf("request server_config: %d\n", r->server->module_config);
    get_resource(r->server->module_config);
    //...
}

static int my_child_init(apr_pool_t *p, server_rec *s) {
    printf("init server_config: %d\n", s->module_config);
    get_resource(s->module_config);
    //...
}

This code prints out four different address locations where I would expect/hope for two - one for the server_rec->module_config and one for the returned value of ap_get_module_config().