I'm somewhat confused on how to write perl module code that DTRT when it's loaded under MP2 when using PerlModule/PerlLoadModule.

Initially, I started out with this code:

$value = Apache2::RequestUtil->request->dir_config($key) ||

Of course, this failed under MP2 and caused apache to issue the "Global request not available" error.

Next I checked the restart count:

if (Apache2::ServerUtil::restart_count() == 1) {
        $value = Apache2::ServerUtil->server->dir_config($key) || $ENV{$key}
        || $default;
} else {
        $value = Apache2::RequestUtil->request->dir_config($key) ||
        $ENV{$key} || $default;
};

Curiously enough, this got rid of the error, but apache simply didn't spawn child processes and appeared to start, but didn't. It issued no errors or segfaults in any logs.

If I wrapped Apache::RequestUtil->request in eval, the server started. I'm not sure if that's a bug or a feature? Shouldn't it have died with the "Global request not available"

if (Apache2::ServerUtil::restart_count() == 1) {
        $value = Apache2::ServerUtil->server->dir_config($key) || $ENV{$key}
        || $default;
} else {
        eval{
                $value = Apache2::RequestUtil->server->dir_config($key) ||
                $ENV{$key} || $default;
>    };
};

Now, I reread the docs, and realized that I need to be checking for restart_count of >= 1. Now I'm confused. If the restart_count == 1, that means we're restarting. Does that count get propogated to the child processes when they're spawned?

Just because the count is >=1, how does the same code know during a request that even though restart_count>=1 that we're not restarting; but we're serving a request instead?

Or, is restart_count simply a way to determine that we're in the root main process, and when the child process listeners are created, their restart_count == 0?

I'm just trying to write code in a config reader that reads server->dir_config when it's loaded into apache, and request->dir_config when it is called during requests.

-=Chris

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to