You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Simone Caruso <in...@simonecaruso.com> on 2011/08/13 18:06:03 UTC

Can't access module config from handler function

Hi all,

im writing a module that stores data in a shared memory to set php conf values
and other in 'traslate_name' hook.. it works fine.

I decided to output the shm content within an http request using an handler
(like mod_status).

In configuration i have this:
<Location /output/>
sethandler "module_test_output"
</Location>

I setup the shm in post_config hook:
ap_hook_post_config(post_config_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);

ending with the "post_config" hook function like this:
   ...
   conf->cache = apr_rmm_addr_get(rmm_addr, offset);
   conf->test_string = "costant string";
   return OK;
}


Within the translate_name hook the module access conf->cache correctly and
shm+rmm works well.

Problems come When i use "ap_get_module_config" within my 'shmoutput_handler':
conf->cache AND conf->test_string gives me a null pointers cauing segfaults.

My module is very similar to mod_shm_counter:
http://www.codemass.com/mod_shm_counter/downloads/mod_shm_counter.c

but my handler hook don't work.... do someone have an idea?

Thanks!


Re: Can't access module config from handler function

Posted by Simone Caruso <in...@simonecaruso.com>.
On 17/08/2011 09:10, Zaid Amireh wrote:
> 
> On Aug 15, 2011, at 1:45 PM, Simone Caruso wrote:
> 
>> On 15/08/2011 01:44, Nick Kew wrote:
>>> or set up something server-wide
>> How? there's some code that can i read?
>>
> 
> You can use a global variable which gets set during apache's startup, you have to treat it as read only after the childs initialize though, many modules do this.
> 
> Zaid
I discovered that the server_rec is a linked list (server_rec->next) of
configs... i solved attaching the shm/rmm addresses inside a while loop.

Re: Can't access module config from handler function

Posted by Zaid Amireh <tu...@gmail.com>.
On Aug 15, 2011, at 1:45 PM, Simone Caruso wrote:

> On 15/08/2011 01:44, Nick Kew wrote:
>> or set up something server-wide
> How? there's some code that can i read?
> 

You can use a global variable which gets set during apache's startup, you have to treat it as read only after the childs initialize though, many modules do this.

Zaid

Re: Can't access module config from handler function

Posted by Simone Caruso <in...@simonecaruso.com>.
On 15/08/2011 01:44, Nick Kew wrote:
> or set up something server-wide
How? there's some code that can i read?

Thanks Nick

Re: Can't access module config from handler function

Posted by Nick Kew <ni...@apache.org>.
On 14 Aug 2011, at 03:51, Simone Caruso wrote:

> 
>> because the config it sees hasn't been merged for the <location>
> The config is a server based confing not a per-dir one.

Then maybe your configuration is attached to the wrong virtualhost.
Look carefully at what gets passed in the post_config hook: you can
access every vhost with care, or set up something server-wide.

-- 
Nick Kew

Re: Can't access module config from handler function

Posted by Simone Caruso <in...@simonecaruso.com>.
> because the config it sees hasn't been merged for the <location>
The config is a server based confing not a per-dir one.

> 
> I suspect you're using the wrong configuration hierarchy for the job at hand.
Im attacking shm segmets in post_confing hook, i can see the address in
'traslate' but not in my handler.

> If not, then the fix might be as simple as a merge_config function.
>
merge_server_config doesnt exec before post_confing hook?


Re: Can't access module config from handler function

Posted by Simone Caruso <in...@simonecaruso.com>.
> Using it in a <Location> would suggest it's per_dir config.
>>
>> I setup the shm in post_config hook:
>> ap_hook_post_config(post_config_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);
> 
> ... but per_dir config for your location doesn't exist at post_config time!
> 
Now im sure this is not a problem related to per_dir config, i tried without the
<Location> directive.

If i make changes in module config inside "post_config" hook i see these
correctly in "translate_name" hook but NOT in the "ap_hook_handler", do someone
knows why??

Thanks

Re: Can't access module config from handler function

Posted by Simone Caruso <in...@simonecaruso.com>.
maybe the problem is more stupid than expected... i think u have put me on the
right road!

Thank u very much Nick!

Re: Can't access module config from handler function

Posted by Nick Kew <ni...@apache.org>.
On 13 Aug 2011, at 17:06, Simone Caruso wrote:

> Hi all,
> 
> im writing a module that stores data in a shared memory to set php conf values
> and other in 'traslate_name' hook.. it works fine.
> 
> I decided to output the shm content within an http request using an handler
> (like mod_status).
> 
> In configuration i have this:
> <Location /output/>
> sethandler "module_test_output"
> </Location>

Using it in a <Location> would suggest it's per_dir config.
> 
> I setup the shm in post_config hook:
> ap_hook_post_config(post_config_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);

... but per_dir config for your location doesn't exist at post_config time!

> Within the translate_name hook the module access conf->cache correctly and
> shm+rmm works well.

because the config it sees hasn't been merged for the <location>

I suspect you're using the wrong configuration hierarchy for the job at hand.
If not, then the fix might be as simple as a merge_config function.

There's a very brief (and ancient) piece at http://www.apachetutor.org/dev/config
In the book there's a whole chapter, which is both substantially expanded and
updated from that.

-- 
Nick Kew