httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ras...@lerdorf.on.ca (Rasmus Lerdorf)
Subject .conf initialization confusion
Date Thu, 27 Nov 1997 06:52:14 GMT
I am trying to get both per-server and per-directory configuration
directives to work and I have a couple of questions about the current
create/merge setup.  Perhaps the best way to ask is for me to explain how
I think it works.  I think I am making a wrong assumption.  If someone
could skim this and pick out any errors in my explanation, I would
appreciate it.

 . httpd starts up and the per-server config creator function is called
   from create_server_config()

 . per-directory config creator is called from
   create_default_per_dir_config()

 . now, for each virtual host directive encountered the per-dir config
   creator is called from handle_command()

 . each virtual host directive also causes the per-server config creator
   to be called.

 . Once this is done the fixup_virtual_hosts code calls
   merge_server_configs() which in turn calls the per-server config
   merger function.

 . And fixup_virtual_hosts also causes the per-dir config merger
   function to be called.

 . Finally the module initializer function is called

(then it does it all again, but we can ignore that for now)

Now somewhere deep in the guts of Apache, all these various config
structures are kept safe and sound and they are to be extracted with a
call to get_module_config().  On a page request,
get_module_config(r->per_dir_config, &module) is called to retrieve the
correct configuration structure for that request and the module can then
go about its business from then on.

My current problem is that I always end up getting the config structure
from the virtual host last parsed.  When tracing through the code I see
the other config structures being created, but get_module_config() always
returns the same one no matter what.  The basev and addv structures passed
to the merge functions are exactly what I would expect, so I have a
feeling that I am missing some basic step at the end.

My create/merge functions are pretty simple:

/* Initialize a per-server module configuation structure */
void *php3_create_conf(pool * p, server_rec *s)
{
    php3_module_conf *new;

    php3_module_startup(); /* This initializes php3_ini_master */

    new = (php3_module_conf *) palloc(p, sizeof(php3_module_conf));
    memcpy(new,&php3_ini_master,sizeof(php3_module_conf));

    return new;
}

static void *php3_merge_conf(pool *p, void *basev, void *addv)
{
    php3_module_conf *new = (php3_module_conf *) palloc(p,
sizeof(php3_module_conf));
    php3_module_conf *base = (php3_module_conf *) basev;
    php3_module_conf *add = (php3_module_conf *) addv;

    /*
     * Because of the way things are initialized, addv already contains
     * the new conf structure at this point, so we can just memcpy it
     */
    memcpy(new,add,sizeof(php3_module_conf));

    return new;
}

/*
 * Create the per-dir config struct with defaults from php3_ini_master
 */
static void *php3_create_dir(pool * p, char *dummy)
{
    php3_module_conf *new;

    new = (php3_module_conf *) palloc(p, sizeof(php3_module_conf));
    memcpy(new,&php3_ini_master,sizeof(php3_module_conf));

    return new;
}

/*
 * Merge in per-directory .conf directives
 */
static void *php3_merge_dir(pool *p, void *basev, void *addv)
{
    php3_module_conf *new = (php3_module_conf *) palloc(p,
sizeof(php3_module_conf));
    php3_module_conf *base = (php3_module_conf *) basev;
    php3_module_conf *add = (php3_module_conf *) addv;

    memcpy(new,add,sizeof(php3_module_conf));

    return new;
}

-Rasmus


Mime
View raw message