Re: child_init hook: Main vs. MPM processes

2020-12-14 Thread Florian Wagner
On Mon, 14 Dec 2020 13:38:43 +0100
Yann Ylavic  wrote:

> Hi Florian,
> 
> On Mon, Dec 14, 2020 at 12:11 PM Florian Wagner
>  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


Re: child_init hook: Main vs. MPM processes

2020-12-14 Thread Yann Ylavic
Hi Florian,

On Mon, Dec 14, 2020 at 12:11 PM Florian Wagner  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.
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)

>
> At least for debug mode (-X commandline switch) both pre_config and
> child_init are being both run for that single process and there's some
> stuff I need to do in my module that only ever should be run in child
> processes.
>
> I could store the main process pid in get pre_config hook and compare
> it with getpid() result in the child_init but maybe there's a more
> elegant solution?

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.

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.
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..


Regards;
Yann.


child_init hook: Main vs. MPM processes

2020-12-14 Thread Florian Wagner
Hey everyone,

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).

At least for debug mode (-X commandline switch) both pre_config and
child_init are being both run for that single process and there's some
stuff I need to do in my module that only ever should be run in child
processes.

I could store the main process pid in get pre_config hook and compare
it with getpid() result in the child_init but maybe there's a more
elegant solution?

Thanks and regards
Florian