httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kean Johnston <>
Subject Re: pre_config hook
Date Sun, 02 Feb 2014 23:58:48 GMT
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

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> ... 

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.


View raw message