Name
Child Initialization
Synopsis
static void module_child_init(server_rec *pServer,pool *pPool)
An Apache server may consist of many processes (on Unix, for example)
or a single process with many threads (on Win32) or, in the future, a
combination of the two. module_child_init()
is
called once for each instance of a heavyweight process, that is,
whatever level of execution corresponds to a separate address space,
file handles, etc. In the case of Unix, this is once per child
process, but on Win32 it is called only once in total,
not once per thread. This is because threads
share address space and other resources. There is not currently a
corresponding per-thread call, but there may be in the future. There
is a corresponding call for child exit, described later in this
chapter.
See Example 21-11 (1.3) for an excerpt from mod_unique_id.c.
Example
static void unique_id_child_init(server_rec *s, pool *p) { pid_t pid; #ifndef NO_GETTIMEOFDAY struct timeval tv; #endif pid = getpid(); cur_unique_id.pid = pid; if (cur_unique_id.pid != pid) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_CRIT, s, "oh no! pids are greater than 32-bits! I'm broken!"); } cur_unique_id.in_addr = global_in_addr; #ifndef NO_GETTIMEOFDAY if (gettimeofday(&tv, NULL) == -1) { cur_unique_id.counter = 0; } else { cur_unique_id.counter = tv.tv_usec / 10; } #else cur_unique_id.counter = 0; #endif cur_unique_id.pid = htonl(cur_unique_id.pid); cur_unique_id.counter = htons(cur_unique_id.counter); ...
Get Apache: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.