httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Florian Wagner <flor...@wagner-flo.net>
Subject Re: child_init hook: Main vs. MPM processes
Date Mon, 14 Dec 2020 16:40:21 GMT
On Mon, 14 Dec 2020 13:38:43 +0100
Yann Ylavic <ylavic.dev@gmail.com> wrote:

> Hi Florian,
> 
> On Mon, Dec 14, 2020 at 12:11 PM Florian Wagner
> <florian@wagner-flo.net> wrote:
> >
> > is there a simple way to detect in a child_init hook if the current
> > process is also the main server process (the one that runs the
> > pre_config hook).  
> 
> It depends on the MPMs your module is targeting.

Thanks for your comment Yann. I'm targeting Unix/POSIX-like system only
for now.

> For unix MPMs (which fork() children processes) the config hooks are
> called only by the parent process, but others like MPM winnt do call
> them (plus child_init) in the child process too (there is only one
> child on winnt, and threads to handle the connections/requests)

I don't care about child processes calling pre_config, since by the
time that happens the main process has already run pre_config, set up
it's stuff there in global variables and retained data and these get
inherited by the forked children, so I can easily skip setup there.

But I need to disable cleanups in the children; and only there. That's
why I need to distinguish.

> With unix MPMs, pre/post_config and child_init hooks run in the same
> process only happen for ONE_PROCESS mode (-X), so the check could be
> ap_exists_config_define("ONE_PROCESS") to determine that.

Do I have that guarantee for any kind of MPM? Even third party? If not
I'd rather go the way of saving the pid in the main process and
comparing in child_init.

> With MPM winnt there is no inheritance/fork() of the parent resources
> on Windows so I don't know if your do-that-in-the-child-only design
> applies there anyway.

Maybe not. But I haven't the slightest clue about Windows programming
at all.

> The child process can be identified with "getenv("AP_PARENT_PID") !=
> NULL" if you need it, but as said above it does not mean that config
> hooks are not run..

That environment variable seems to be a mpm_winnt specific thing, from
a quick grep over the httpd sources.

Regards
Flo

Mime
View raw message