httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@trudge.engr.sgi.com (Mike Abbott)
Subject buffered logs
Date Wed, 13 Sep 2000 18:52:03 GMT
I'm trying to make BUFFERED_LOGS work in 2.0a6 and I need some guidance.
Bear with me, this is a little convoluted.

First I found and fixed a bug that kept mod_log_config.c from compiling
with BUFFERED_LOGS turned on.  I filed a bug on this:  mod_log-any/6519.

Then I noticed that the access log buffer is not flushed out upon server
termination.  The reason for this is that init_config_log() in
mod_log_config.c registers a cleanup to call flush_all_logs() with a
null data argument.  (init_config_log() uses s to iterate through the
virtual server chain and then calls apr_register_cleanup() with an
always-null s.)  flush_all_logs(NULL) does nothing.  Easy solution:
call apr_register_cleanup() with the original value of s.

Except that causes Apache to segfault in flush_all_logs() during startup
because the server_rec has been zeroed out (in particular,
s->module_config is nil).  In fact, the server_rec has been freed and
reallocated.  See, the server_rec is allocated out of pconf but the
cleanup is registered on plog.  During startup main() clears pconf and
allocates a new server_rec before clearing plog.

I see several possible solutions to this problem and I'm not sure which
one is best.  (I haven't tested any of these so there may be other
unforeseen problems.)  Please help me decide.

But first, a question about plog:  What is it really for?  It is
described unhelpfully in the comment in main as "Pool of log streams,
reset _after_ each read of conf."  (What's a log "stream," and why is it
cleared when it is?)  It's passed to all the pre- and post-config hooks
and to ap_mpm_run(), none of which use it.  The ONLY code that actually
uses it is init_config_log(), via mod_log_config's open-logs hook, which
I've already noted relies on both plog (for the cleanup and other
allocations) and pconf (for the server_rec) which have different
lifetimes.  How should plog be used?  Why is it passed to pre-config,
post-config, and mpm-run?  In 1.3 there is no plog and flush_all_logs()
is called only via a child_exit hook.

Anyway, here are the solutions I see.  These are all mutually exclusive.
(You may want to apply bug 6519's suggested patch -- or find a different
solution of course -- before experimenting with these.)

Solution 1.  Move the apr_clear_pool(plog) call from the middle of
main()'s for(;;) loop to the top.  This would cause flush_all_logs() to
be called before pconf is nuked two lines later, but I wonder if this
violates the intended lifetime of plog.

Solution 2.  Make init_config_log() use pconf rather than plog to
register the cleanup, since flush_all_logs() needs a valid server_rec.
Makes me wonder if the other allocations in that function should also
use pconf, in which case NOTHING would use plog.

Solution 3.  Make plog a descendant of pconf not pglobal.

The above solve the initial startup problem but don't address the issue
of flushing log buffers upon child-process exit.  For that, here are
more possibilities:

Solution 4.  Make plog a descendant of pchild and make sure that pchild
is cleaned up when each child process exits.  This is tough because MPMs
are responsible for children (if they exist at all) but plog is known in
main() and is passed to ap_mpm_run().

Solution 5.  Pick one of solutions 1-3 and add that each MPM must
apr_clear_pool(plog or pconf) upon child exit.

Bleah, these are getting ugly.  Please help by describing the intended
(as opposed to actual) design and use of plog and its relation to child
processes.

PS -- I will file a bug against this problem with a tested patch, once
you help me decide which way to go.
-- 
Michael J. Abbott        mja@sgi.com        http://reality.sgi.com/mja/

Mime
View raw message