On Tue, 19 Sep 2000, Joshua Chamas wrote:

> Perhaps I should auto init srand() then for Apache::ASP
> to make sure that its happening post fork?  Something like
> 
>  if(! DONE FOR CURRENT PID) {
>    srand();
>  }
> 
> For reproducability within Apache::ASP, all that has to 
> happen is someone initializing it to srand(something)
> in one of their scripts.  
> 
> This idea though I think would do well to be bundled 
> into modperl itself.  Doug, what do you think?

how about this patch which will override the builtin srand with a noop
(Apache::srand) and call CORE::srand once per-child during child_init.

Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.108
diff -u -r1.108 Apache.xs
--- src/modules/perl/Apache.xs  2000/09/13 07:50:11     1.108
+++ src/modules/perl/Apache.xs  2000/09/25 19:15:51
@@ -540,6 +540,12 @@
     Apache_terminate_if_done(r,sts);
     perl_call_halt(sts);
 
+void
+srand(...)
+
+    CODE:
+    /*NOOP*/
+
 #in case you need Apache::fork
 # INCLUDE: fork.xs
 
Index: src/modules/perl/mod_perl.c
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/mod_perl.c,v
retrieving revision 1.126
diff -u -r1.126 mod_perl.c
--- src/modules/perl/mod_perl.c 2000/09/01 05:23:17     1.126
+++ src/modules/perl/mod_perl.c 2000/09/25 19:16:05
@@ -591,6 +591,13 @@
     perl_startup(s, p);
 }
 
+static void override_core_global(char *name)
+{
+    GV *gv = gv_fetchpv(form("CORE::GLOBAL::%s", name), TRUE, SVt_PVCV);
+    GvCV(gv) = perl_get_cv(form("Apache::%s", name), TRUE);
+    GvIMPORTED_CV_on(gv);
+}
+
 void perl_startup (server_rec *s, pool *p)
 {
     char *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
@@ -771,10 +778,10 @@
 #endif
 
     /* *CORE::GLOBAL::exit = \&Apache::exit */
-    if(gv_stashpv("CORE::GLOBAL", FALSE)) {
-       GV *exitgp = gv_fetchpv("CORE::GLOBAL::exit", TRUE, SVt_PVCV);
-       GvCV(exitgp) = perl_get_cv("Apache::exit", TRUE);
-       GvIMPORTED_CV_on(exitgp);
+    /* *CORE::GLOBAL::srand = \&Apache::srand */
+    if (gv_stashpv("CORE::GLOBAL", FALSE)) {
+        override_core_global("exit");
+        override_core_global("srand");
     }
 
     if(PERL_STARTUP_DONE_CHECK)        {
@@ -941,6 +948,7 @@
     register_cleanup(p, args, perl_child_exit_cleanup, null_cleanup);
 
     mod_perl_init_ids();
+    perl_eval_pv("CORE::srand()", TRUE);
     Apache__ServerStarting(FALSE);
     PERL_CALLBACK(hook, cls->PerlChildInitHandler);
 }

Reply via email to