Hi everyone,
I am new to apache development and I need some help with this issue please.
I have a configuration directive (ArcMaxRequestSize) in httpd.conf at the
top level which makes apache segfault in the start-up phase when using my
module.
It seems to me that only per-dir config is taken into account which seems
really weird ...
I'm using AP_INIT_TAKE1 and ap_set_int_slot (see below).
AP_INIT_TAKE1("ArcMaxRequestSize", ap_set_int_slot,
(void *)APR_OFFSETOF(arc_config_t, max_request_size), RSRC_CONF,
"Maximum size of a request"),
The segmentation fault occurs in ap_set_int_slot because its struct_ptr
parameter is NULL:
1436 AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd,
1437 void *struct_ptr,
1438 const char *arg)
1439 {
1440 char *endptr;
1441 char *error_str = NULL;
1442 int offset = (int)(long)cmd->info;
1443
> 1444 *(int *)((char*)struct_ptr + offset) = strtol(arg, &endptr,
10);
1445
1446 if ((*arg == '\0') || (*endptr != '\0')) {
The stack looks like this:
#0 0x0808e2bf in ap_set_int_slot (cmd=0xbffff3a8, struct_ptr=0x0,
arg=0x8198df0 "22222") at config.c:1444
#1 0x0808cfab in invoke_cmd (cmd=0xb7abe5e0, parms=0xbffff3a8,
mconfig=0x0, args=0x8147965 "") at config.c:909
#2 0x0808df8e in ap_walk_config_sub (current=0x8147938, parms=0xbffff3a8,
section_vector=0x810cf90) at config.c:1298
#3 0x0808e020 in ap_walk_config (current=0x8147938, parms=0xbffff3a8,
section_vector=0x810cf90) at config.c:1331
#4 0x0808f326 in ap_process_config_tree (s=0x810be20, conftree=0x8138c00,
p=0x80d50a8, ptemp=0x8135aa0) at config.c:2055
#5 0x080690d8 in main (argc=2, argv=0xbffff564) at main.c:639
In ap_walk_config_sub (stack#2) we have :
1284 for ( ; ml != NULL; ml = ml->next) {
1285 void *dir_config = ap_set_config_vectors(parms->server,
1286 section_vector,
1287 parms->path,
1288 ml->m,
1289 parms->pool);
1290 const char *retval;
1291 cmd = ml->cmd;
1292
1293 /* Once was enough? */
1294 if (cmd->req_override & EXEC_ON_READ) {
1295 continue;
1296 }
1297
1298 retval = invoke_cmd(cmd, parms, dir_config, current->args);
ap_set_config_vectors returns NULL here. Looking inside it I have the
feeling that the server config is ignored and only the per-directory config
is returned and in my case this is NULL:
in server/config.c :
1052 AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server,
1053 ap_conf_vector_t
*section_vector,
1054 const char *section,
1055 module *mod, apr_pool_t
*pconf)
1056 {
1057 void *section_config = ap_get_module_config(section_vector, mod);
1058 void *server_config = ap_get_module_config(server->module_config,
mod);
1059
1060 if (!section_config && mod->create_dir_config) {
1061 /* ### need to fix the create_dir_config functions'
prototype... */
1062 section_config = (*mod->create_dir_config)(pconf, (char
*)section);
1063 ap_set_module_config(section_vector, mod, section_config);
1064 }
1065
1066 if (!server_config && mod->create_server_config) {
1067 server_config = (*mod->create_server_config)(pconf, server);
1068 ap_set_module_config(server->module_config, mod,
server_config);
1069 }
1070
1071 return section_config;
1072 }
If I modiffy this to:
1068 ap_set_module_config(server->module_config, mod,
server_config);
1069 }
1070 if(NULL == section_config)
1071 return server_config;
1072 return section_config;
1073 }
then everything works fine and as (I) expected.
I took some screenshots from my debugging session which can be found here:
http://www.crivat.eu/wp-content/uploads/2012/08/1.png
http://www.crivat.eu/wp-content/uploads/2012/08/2.png
http://www.crivat.eu/wp-content/uploads/2012/08/3_Boum_.png
Thanks in advance for your help,
Alex
=============== BEGIN mod_arc.c (extract) =========================
static void *arc_perserver_create_config(apr_pool_t *pool, server_rec *s)
{
arc_config_t *conf = apr_pcalloc(pool, sizeof(arc_config_t));
return conf;
}
static const command_rec arc_config_directives[] =
{
AP_INIT_TAKE1("ArcMaxRequestSize", ap_set_int_slot,
(void *)APR_OFFSETOF(arc_config_t, max_request_size), RSRC_CONF,
"Maximum size of a request"),
{NULL}
};
module AP_MODULE_DECLARE_DATA arc_module =
{
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
arc_perserver_create_config, /* create per-server config structures
*/
NULL, /* merge per-server config structures */
arc_config_directives, /* table of config file commands
*/
arc_register_hooks /* register hooks
*/
};
=============== END mod_arc.c (extract) ===========================
=============== BEGIN httpd.conf (extract) =========================
LoadModule arc_module modules/mod_arc.so
ArcMaxRequestSize 22222
<Location /arc>
SetHandler arc
</Location>
=============== END httpd.conf (extract) ===========================