httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michaelr <my...@freenet.de>
Subject Re: child init/ exit and the apr_cleanup_register
Date Tue, 22 Nov 2011 09:20:37 GMT
Hi Sorin,

thank's for your explanation. Eyerything work fine when i register the
cleanup in the way you suggested.

apr_pool_cleanup_register(p, NULL, child_exit, apr_pool_cleanup_null);

That saved my day.

Greetings 
 Michael



On Tue, 2011-11-22 at 10:02 +0100, Sorin Manolache wrote:
> On Tue, Nov 22, 2011 at 09:19, michaelr <mypop@freenet.de> wrote:
> > Hello again,
> >
> > maybe another stupid question but i could not found any
> > example in the modules dir of the httpd source.
> >
> > Let's say i have an child_init_function which opens a
> > filehandle. This filehandle should be open until the child
> > ends.
> >
> > In mod_example.c they register an cleanup function to call a
> > function on child exit.
> >
> > static apr_status_t child_exit ( void *data )
> >        {
> >        //close file handle...
> >
> >        return OK;
> >        }
> >
> > static void child_init ( apr_pool_t *p, server_rec *s )
> >        {
> >        //open file handle...
> >
> >        apr_pool_cleanup_register(p, s, NULL, child_exit) ;
> >        }
> >
> > I understand the cleanup as a function which runs on pool_cleanup.
> > This could happend on any time which i can't control - right?
> >
> > When i return an HTTP_INTERNAL_SERVER_ERROR in my handler function
> > as an example the cleanup get's called also but the child is still
> > alive. The filehandle is closed and on the next request i run into
> > some kind of trouble.
> 
> 
> The cleanup callback should not be called when you finish processing a
> request. It should be called only when the child exits.
> 
> Register the cleanup function as follows:
> 
> apr_pool_cleanup_register(p, NULL, child_exit, apr_pool_cleanup_null);
> 
> The third argument (child_exit) is invoked when the pool is destroyed.
> The 4th (apr_pool_cleanup_null) is invoked when subpools of p are
> destroyed.
> 
> You can pass the file handle in the second argument (where I've put
> NULL). Then it will show up as the data argument in child_exit.
> 
> 
> S
> 
> >
> > Is there a way to define a 'real' exit function or can i force child
> > shutdown in above example? What's the right way to do it correctly?
> >
> > Thanks a lot and greetings
> >  Michael
> >
> >
> >
> >
> >



Mime
View raw message