apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan Bloom" <rbl...@gmail.com>
Subject Re: apr_proc_create
Date Wed, 12 Apr 2006 02:23:33 GMT
Garrett is right in theory, but doing what he suggests will break Apache.  :-)

Basically, Apache relies on child processes to ensure that the server
keeps running.  If something happens to one child, the parent will
create another.  So, if you set the socket to be not inherited in
subsequent child processes, then everything will apear to work for a
while, and then it will just stop working when the child process dies
for some reason.

On unix, I would tell you to use apr_fork(), and close the socket
yourself, but that isn't an option on Windows.  Probably your best
option is to figure out how the Apache child process on Windows finds
the listening socket, re-attach to that in your child process, and
then close that socket.  I used to know how this all works, but I
haven't played in Apache for a number of years at this point.

Also, while this is an apr question, it is more of an Apache module
question, and belongs on dev@httpd.apache.org.  There are developers
there that can tell you exactly what you need to know about how to
close the socket in your child process.


On 4/11/06, Garrett Rooney <rooneg@electricjellyfish.net> wrote:
> On 4/11/06, Mike Behne <mdb32402@yahoo.com> wrote:
> >
> > I have a question about behavior of a process launched by apr_proc_create
> > from within an Apache plugin module on Windows.
> >
> > The created process is intended to remain running regardless of whether the
> > Apache server is running.  I'm noticing that after the process is created,
> > and the Apache server is stopped and I attempt to restart it, I get an
> > indication that the socket (port 80) is in use and Apache won't start.  Once
> > I stop the created process, Apache can successfully start.  I tried a few
> > things to change this behavior--apr_procattr_cmdtype_set,
> > apr_procattr_detach_set, apr_proc_detach--but no change.  Now I've
> > implemented some techniques to take the created proc down when Apache stops
> > to avoid the failed restart.  Is there anything I could do differently that
> > would allow the created proc to stay up without preventing Apache from
> > restarting?
> I suspect the problem is that the socket httpd is listening on is set
> to be inherited (as you'd expect, since it's created in a parent
> process and inherited by worker processes who do the accept), but what
> you want is for it to not be inheritted by subsequent child processes.
>  There are functions to control this inheritance,
> apr_socket_inherit_unset and apr_socket_inherit_set, but I'm not sure
> if there's an easy way to get at the appropriate socket to call them
> from your module.  It might need to be done inside the httpd core.  On
> the other hand, I could be wrong, I'm just theorizing at this point.
> -garrett

Ryan Bloom

View raw message