At the moment you can say:
$s->push_handlers(PerlChildInitHandler => 'foo');
after the child process has been spawned (e.g. in the response phase). Of
course it won't do anything. I suggest that we prevent this from happening.
I've a real use for this case.
At the moment if before the child processes are spawned any perl code
(e.g. startup.pl) is calling srand() or rand(), the child processes will
all have the same IV for rand and all generate the same rand sequence
which is not good. I wonder if we should try to fix that in mod_perl, or
do you think someone will want this as a feature? The issue is
perl-specific really:
% perl -le 'srand(); fork(); print "$$: " . rand();'
6326: 0.813502754391269
6325: 0.813502754391269
interestingly enough it doesn't happen with threads:
% perl -Mthreads -le 'srand(); threads->new("x")->join; x(); \
sub x { my $tid = threads->self->tid; print "$tid: " . rand()}'
1: 0.924164554876374
0: 0.306549259319098
at the moment under mp2 we are consistently giving the same sequence, be
it prefork or worker.
In any case here, at mailchannels.com, we try to solve this bug by making
sure that ChildInit runs srand() to avoid this problem (so each process
has its own seed), but it's so easy to forget to configure it, if you give
this code to users. So we were wondering how to ensure this execution. I
have suggested that if we ensure that
$s->push_handlers(PerlChildInitHandler => 'foo');
can be only run before PerlChildInitHanlder phase (or during it), than we
can easily ensure that the phase will be configured by doing this at the
compile time:
package foo;
use Apache2::ServerUtil ();
Apache2::ServerUtil->server->push_handlers(PerlChildInitHandler => 'foo');
...
1;
now if the module is loaded at the server startup, it'll register the
callback just fine. If not and it'll be attempted to load after the server
startup, that push_handlers call will fail, saying:
"It's too late to register PerlChildInitHandler"
What do you think?
Later we may extend this to other phases as well (e.g. prevent registering
Auth handler, from response phase). of course assuming that we find an
efficient way to do that.
I wonder if we should just srand() inside mod_perl, I should probably also
ask this at p5p, since fork() and threads() are inconsistent in that
aspect. since threads do have different seeds
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://mailchannels.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]