httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug MacEachern <do...@covalent.net>
Subject srand() usage
Date Thu, 29 Nov 2001 00:15:29 GMT
mod_rewrite has a race condition with threaded mpms:

static int rewrite_rand_init_done = 0;

static void rewrite_rand_init(void)
{
    if (!rewrite_rand_init_done) {
        srand((unsigned)(getpid()));
        rewrite_rand_init_done = 1;
    }
    return;
}

and mod_ssl calls srand(time(NULL)) on *every* request if
'SSLRandomSeed connect builtin' is configured.

i was thinking there should be an ap_srand() that can be called by modules
in the child_init hook.  something like:

static int ap_srand_init = 0;

AP_DECLARE(void) ap_srand(void)
{
    if (!ap_srand_init) {
        srand(...);
        ap_srand_init = 1;
    }
}

this will help ensure srand() is only called once per-process and avoid
the race condition.  thoughts?

only snag is it looks like all MPMs except for beos call
ap_run_child_init(), any reason the beos mpm shouldn't be calling it?



Mime
View raw message