static void Rivet_ChildInit()

in src/mod_rivet_ng/mod_rivet.c [425:497]


static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
{
    int                 idx;
    rivet_server_conf*  root_server_conf;
    server_rec*         s;

    /* the thread key used to access to Tcl threads private data */

    ap_assert (apr_threadkey_private_create (&rivet_thread_key, NULL, pChild) == APR_SUCCESS);

    /* This code is run once per child process. The forking
     * of a child process doesn't preserve the thread where the Tcl
     * notifier runs. The Notifier should have been restarted by one the
     * pthread_atfork callbacks (setup in Tcl >= 8.5.14 and Tcl >= 8.6.1). In
     * case pthread_atfork is not supported we unconditionally call Tcl_InitNotifier
     * hoping for the best (Bug #55153)
     */

#if !defined(HAVE_PTHREAD_ATFORK)
    Tcl_InitNotifier();
#endif

    /* We can rely on the existence of module_globals only when
     * running the prefork MPM, otherwise the pointer is NULL and
     * the structure has to be allocated and filled with data
     */

    if (module_globals == NULL)
    {
        module_globals = Rivet_CreateModuleGlobals(pChild);
        module_globals->rivet_mpm_bridge = Rivet_SeekMPMBridge(pChild);
        module_globals->server = server;
    }

    /*
     * the mutex to protect the process wide pool is created here
     */

    apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pChild);

    /* Once we have established a pool with the same lifetime of the child process we
     * process all the configured server records assigning an integer as unique key
     * to each of them
     */

    root_server_conf = RIVET_SERVER_CONF(server->module_config);
    idx = 0;
    for (s = server; s != NULL; s = s->next)
    {
        rivet_server_conf*  myrsc;

        myrsc = RIVET_SERVER_CONF(s->module_config);

        /* We only have a different rivet_server_conf if MergeConfig
         * was called. We really need a separate one for each server,
         * so we go ahead and create one here, if necessary. */

        if (s != server && myrsc == root_server_conf) {
            myrsc = RIVET_NEW_CONF(pChild);
            ap_set_module_config(s->module_config,&rivet_module,myrsc);
            Rivet_CopyConfig(root_server_conf,myrsc);
        }

        myrsc->idx = idx++;
    }
    module_globals->vhosts_count = idx;

    /* Calling the brigde child process initialization */

    RIVET_MPM_BRIDGE_CALL(thread_init,pChild,server);

    apr_pool_cleanup_register(pChild,server,Rivet_Finalize,Rivet_Finalize);
}