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 Mike Meyer <mw...@mired.org> on 2010/10/26 04:52:50 UTC

How to init an mmaped file?

I've got a module that has an mmaped file configured on a per-server
basis (well, that's the goal, anyway). I'm having trouble getting the
map propagated to request handlers properly.

The file name to be mapped is treated like any other config data in
the config creation & merge functions. The data for the mapping is
also in the config structure. Create sets it to null, merge ignores
it.

The post_config hook checks to make sure the file name is set
properly, then goes ahead and creates the file and maps it, using the
pool_userdata trick to only do this the second time. I can verify in
gdb that this is getting set up properly. The child_init hook does the
map again, and I can verify that I'm picking up the right values
there.

However, the data for the map is null in the config structure that
gets passed to the process_connection hook.

Anyone got some hints on how I ought to set this up? Maybe there's a
writeup somewhere I missed on config processing  Possibly there's some
facility that I ought to be looking at to replace the mmaped file?

	 Thanks,
	 <mike
-- 
Mike Meyer <mw...@mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Re: How to init an mmaped file?

Posted by Mike Meyer <mw...@mired.org>.
On Tue, 26 Oct 2010 20:49:32 +0200
Sorin Manolache <so...@gmail.com> wrote:

> On Tue, Oct 26, 2010 at 20:36, Mike Meyer
> <mw...@mired.org> wrote:
> > On Tue, 26 Oct 2010 10:03:11 +0100
> > Nick Kew <ni...@apache.org> wrote:
> >
> >> On 26 Oct 2010, at 03:52, Mike Meyer wrote:
> >> > Anyone got some hints on how I ought to set this up? Maybe there's a
> >> > writeup somewhere I missed on config processing  Possibly there's some
> >> > facility that I ought to be looking at to replace the mmaped file?
> >>
> >> One possible suggestion.  post_config and child_init get passed
> >> the first server_rec.  The server_rec in any later hook is the
> >> virtual host.  Could your problem be setting data in one server
> >> then trying to retrieve it from another?
> >
> > That indeed appears to be the case (Sorin got this also, pointing out
> > that it comes from using a virtual server).
> >
> > Since I want this to work properly with multiple virtual servers mapping
> > different files, I'd like this to work. To me, the obvious place to
> > put this would be the config merge hook, except that doesn't get
> > passed a copy of the server rec, and the pool it gets passed is
> > apparently different (or possibly reset) between invocations, so the
> > trick of using pool_userdata to skip doing this during the config
> > check doesn't work.
> >
> > I don't see a hook that's obviously convenient for this. Maybe there's
> > one with a non-obvious name? Barring that, it would seem that I have
> > to have both my post_config hook and child_init hook walk through the
> > servers checking their config to see if my module is enabled, and
> > setting them up appropriately.
> 
> I did something similar. As you say, I had to walk through the servers
> in both hooks. I can lookup up the code tomorrow if you want.

I'll ask if I have trouble figuring it out, or nobody provides a
pointer. Thanks

> I do not know the pool_userdata trick. What I did was to
> apr_pool_cleanup_register a callback on the config pool that undid
> what the post_config callback did. The config pool is cleaned up
> between the two invocations of the post_config callback.

That's documented here: http://wiki.apache.org/httpd/ModuleLife
I don't believe any of the pool's but s->process->pool survive to the
second invocation.

       <mike
-- 
Mike Meyer <mw...@mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Re: How to init an mmaped file?

Posted by Sorin Manolache <so...@gmail.com>.
On Tue, Oct 26, 2010 at 20:36, Mike Meyer
<mw...@mired.org> wrote:
> On Tue, 26 Oct 2010 10:03:11 +0100
> Nick Kew <ni...@apache.org> wrote:
>
>> On 26 Oct 2010, at 03:52, Mike Meyer wrote:
>> > Anyone got some hints on how I ought to set this up? Maybe there's a
>> > writeup somewhere I missed on config processing  Possibly there's some
>> > facility that I ought to be looking at to replace the mmaped file?
>>
>> One possible suggestion.  post_config and child_init get passed
>> the first server_rec.  The server_rec in any later hook is the
>> virtual host.  Could your problem be setting data in one server
>> then trying to retrieve it from another?
>
> That indeed appears to be the case (Sorin got this also, pointing out
> that it comes from using a virtual server).
>
> Since I want this to work properly with multiple virtual servers mapping
> different files, I'd like this to work. To me, the obvious place to
> put this would be the config merge hook, except that doesn't get
> passed a copy of the server rec, and the pool it gets passed is
> apparently different (or possibly reset) between invocations, so the
> trick of using pool_userdata to skip doing this during the config
> check doesn't work.
>
> I don't see a hook that's obviously convenient for this. Maybe there's
> one with a non-obvious name? Barring that, it would seem that I have
> to have both my post_config hook and child_init hook walk through the
> servers checking their config to see if my module is enabled, and
> setting them up appropriately.

I did something similar. As you say, I had to walk through the servers
in both hooks. I can lookup up the code tomorrow if you want.

I do not know the pool_userdata trick. What I did was to
apr_pool_cleanup_register a callback on the config pool that undid
what the post_config callback did. The config pool is cleaned up
between the two invocations of the post_config callback.

Sorin

Re: How to init an mmaped file?

Posted by Mike Meyer <mw...@mired.org>.
On Tue, 26 Oct 2010 10:03:11 +0100
Nick Kew <ni...@apache.org> wrote:

> On 26 Oct 2010, at 03:52, Mike Meyer wrote:
> > Anyone got some hints on how I ought to set this up? Maybe there's a
> > writeup somewhere I missed on config processing  Possibly there's some
> > facility that I ought to be looking at to replace the mmaped file?
> 
> One possible suggestion.  post_config and child_init get passed
> the first server_rec.  The server_rec in any later hook is the
> virtual host.  Could your problem be setting data in one server
> then trying to retrieve it from another?

That indeed appears to be the case (Sorin got this also, pointing out
that it comes from using a virtual server).

Since I want this to work properly with multiple virtual servers mapping
different files, I'd like this to work. To me, the obvious place to
put this would be the config merge hook, except that doesn't get
passed a copy of the server rec, and the pool it gets passed is
apparently different (or possibly reset) between invocations, so the
trick of using pool_userdata to skip doing this during the config
check doesn't work.

I don't see a hook that's obviously convenient for this. Maybe there's
one with a non-obvious name? Barring that, it would seem that I have
to have both my post_config hook and child_init hook walk through the
servers checking their config to see if my module is enabled, and
setting them up appropriately.

Any pointers to code that does that? Maybe a better way to approach
the problem?

    Thanks,
    <mike
-- 
Mike Meyer <mw...@mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Re: How to init an mmaped file?

Posted by Nick Kew <ni...@apache.org>.
On 26 Oct 2010, at 03:52, Mike Meyer wrote:

> Anyone got some hints on how I ought to set this up? Maybe there's a
> writeup somewhere I missed on config processing  Possibly there's some
> facility that I ought to be looking at to replace the mmaped file?

One possible suggestion.  post_config and child_init get passed
the first server_rec.  The server_rec in any later hook is the
virtual host.  Could your problem be setting data in one server
then trying to retrieve it from another?

-- 
Nick Kew


Re: How to init an mmaped file?

Posted by Sorin Manolache <so...@gmail.com>.
On Tue, Oct 26, 2010 at 06:47, Mike Meyer
<mw...@mired.org> wrote:
> On Tue, 26 Oct 2010 06:03:48 +0200
> Ben Noordhuis <in...@bnoordhuis.nl> wrote:
>
>> Mike, is your code available anywhere?
>
> Unfortunately, a lot of what happens after the connection is made is
> proprietary. I might be able to pull together enough releasable code
> to show what's going on up to the point the connection hook is
> called. Would that help?
>
>        <mike
> --
> Mike Meyer <mw...@mired.org>              http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>

Before invoking the process_connection callback, apache updates the
base_server field of the conn_rec structure based on the client IP.

The error could be that you mmap the file in one config object but you
get another config object as an argument to the process_connection
callback.

In order to check this hypothesis, log the value of the pointer
returned by create_server_config or merge_server_config and the value
of the config object pointer that you get in the process_connection
invokation.

Sorin

Re: How to init an mmaped file?

Posted by Mike Meyer <mw...@mired.org>.
On Tue, 26 Oct 2010 06:03:48 +0200
Ben Noordhuis <in...@bnoordhuis.nl> wrote:

> Mike, is your code available anywhere?

Unfortunately, a lot of what happens after the connection is made is
proprietary. I might be able to pull together enough releasable code
to show what's going on up to the point the connection hook is
called. Would that help?

	<mike
-- 
Mike Meyer <mw...@mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Re: How to init an mmaped file?

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
Mike, is your code available anywhere?