You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Kean Johnston <ke...@gmail.com> on 2014/02/02 04:01:49 UTC
pre_config hook
I have a question about the pre_config hook. I have a module that registers
for that hook, but the function I specify is never called. The module is
loaded with LoadModule and later configured within an <IfModule my_module>
block. Seems to me that the pre_config hooks have already been run by the
time LoadModule is processed.
I have a hash table that needs to be initialized before any of my config
directives are parsed, and I am getting a SIGSEGV because that is not the
case. Is it acceptable to initialize that hash table in my register_hooks
function instead? I don't see other modules doing that so II am wondering
if there's a reason for that.
Guidance greatly appreciated.
Re: pre_config hook
Posted by Kean Johnston <ke...@gmail.com>.
On 2/2/2014 10:53 PM, Nick Kew wrote:
>
> On 2 Feb 2014, at 03:01, Kean Johnston wrote:
>
> (this really belongs on modules-dev)
Apologies. Moving this reply there.
>
>> I have a question about the pre_config hook. I have a module that registers for that hook, but the function I specify is never called.
>
> I expect it is, but …
Actually I found out why it wasn't (yet). I was attempting to use a config
container using AP_INIT_RAW_ARGS, and with EXEC_ON_READ set, I was being
called before pre_config had been run.
>> I have a hash table that needs to be initialized before any of my config directives are parsed, and I am getting a SIGSEGV because that is not the case.
>
> Is the hash table a member of a configuration struct?
> I expect it's initialised in the root context, but your config
> directives are in some other context.
No, it's just a static variable in my module. Everything is limited to the
root context. Here's what I am trying to do.
The module is for dealing with FastCGI servers, but without any form of
process management as things like mod_fcgid do. For lack of a better word I
call these "external" FastCGI servers. I wanted things configured thus:
<ExtfcgiServer "name">
Option1 arg1 etc
Option2 arg1 arg2 etc
StillMoreOptions etc etc
</ExtfcgiServer>
My command_rec has, inter alia:
AP_INIT_RAW_ARGS("<ExtfcgiServer", new_ext_server, NULL,
EXEC_ON_READ | RSRC_CONF,
"Define a new external FastCGI application server"),
With EXEC_ON_READ set, new_ext_server was being called before the
pre_config hook, which simply has:
static int extfcgi_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp)
{
extfcgi_servers = apr_hash_make(pconf);
return OK;
}
extfcgi_servers is simply a hash with all of the defined external FastCGI
application servers.
>
>> Is it acceptable to initialize that hash table in my register_hooks function instead?
>
> Yes, if you can deal with the pool management. But you'll probably
> run up against exactly the same issue.
If I use EXEC_ON_READ, I move that initialization of extfcgi_servers into
my register_hooks function, and allocate the hash in the pool that is the
only argument to that function. Is that not safe?
If I don't use EXEC_ON_READ then the pre_config hook is run just fine
before new_ext_server().
Attempting to use a configuration container like I am is proving to be
quite tough for a neophyte. With EXEC_ON_READ, I find I can safely use
ap_cfg_getline(), and use cmd->config_file as the third argument to that
function. However, if I do NOT use EXEC_ON_READ, then cmd->config_file is
NULL and ap_cfg_getline() of course coredumps.
Ideally I'd like to not use EXEC_ON_READ, but then I have to figure out
what to pass as the third argument of ap_cfg_getline(), or find some other
function that I can get config lines between <ExtfcgiServer> ...
</ExtfcgiServer>.
An alternative approach is to give up on using a config container at all
and just have a normal config directive and use ap_getword_conf().
Something along the lines of how mod_ext_filter does things. I'd prefer not
to though, the container approach looks better. Advice greatly appreciated.
Sincerely,
Kean
Re: pre_config hook
Posted by Nick Kew <ni...@webthing.com>.
On 2 Feb 2014, at 03:01, Kean Johnston wrote:
(this really belongs on modules-dev)
> I have a question about the pre_config hook. I have a module that registers for that hook, but the function I specify is never called.
I expect it is, but …
> I have a hash table that needs to be initialized before any of my config directives are parsed, and I am getting a SIGSEGV because that is not the case.
Is the hash table a member of a configuration struct?
I expect it's initialised in the root context, but your config
directives are in some other context.
> Is it acceptable to initialize that hash table in my register_hooks function instead?
Yes, if you can deal with the pool management. But you'll probably
run up against exactly the same issue.
A function implementing your config directives could also
do it (if cfg->hash == NULL { initialise it ; } ). That might be
a good line of thought, as you should consider whether
your hash should be global, per-vhost, or whatever.
Oh, and I'd suggest dropping the <IfModule>. That's only really useful
for package/installation management systems.
--
Nick Kew