1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "apr_portable.h"
19 #include "apr_strings.h"
20 #include "apr_thread_proc.h"
21 #include "apr_signal.h"
23 #define APR_WANT_STDIO
24 #define APR_WANT_STRFUNC
30 #if APR_HAVE_SYS_TYPES_H
31 #include <sys/types.h>
34 #include "ap_config.h"
36 #include "mpm_default.h"
37 #include "http_main.h"
39 #include "http_config.h"
40 #include "http_core.h" /* for get_remote_host */
41 #include "http_connection.h"
42 #include "scoreboard.h"
44 #include "util_mutex.h"
46 #include "mpm_common.h"
47 #include "ap_listen.h"
54 #ifdef HAVE_SYS_PROCESSOR_H
55 #include <sys/processor.h> /* for bindprocessor() */
59 #include <sys/times.h>
61 /* Limit on the total --- clients will be locked out if more servers than
62 * this are needed. It is intended solely to keep the server from crashing
63 * when things get out of hand.
65 * We keep a hard maximum number of servers, for two reasons --- first off,
66 * in case something goes seriously wrong, we want to stop the fork bomb
67 * short of actually crashing the machine we're running on by filling some
68 * kernel table. Secondly, it keeps the size of the scoreboard file small
69 * enough that we can read the whole thing without worrying too much about
72 #ifndef DEFAULT_SERVER_LIMIT
73 #define DEFAULT_SERVER_LIMIT 256
76 /* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want
77 * some sort of compile-time limit to help catch typos.
79 #ifndef MAX_SERVER_LIMIT
80 #define MAX_SERVER_LIMIT 200000
83 #ifndef HARD_THREAD_LIMIT
84 #define HARD_THREAD_LIMIT 1
89 static apr_proc_mutex_t *accept_mutex;
90 static int ap_daemons_to_start=0;
91 static int ap_daemons_min_free=0;
92 static int ap_daemons_max_free=0;
93 static int ap_daemons_limit=0; /* MaxRequestWorkers */
94 static int server_limit = 0;
95 static int mpm_state = AP_MPMQ_STARTING;
98 /* data retained by prefork across load/unload of the module
99 * allocated on first call to pre-config hook; located on
100 * subsequent calls to pre-config hook
102 typedef struct prefork_retained_data {
103 int first_server_limit;
105 ap_generation_t my_generation;
106 int volatile is_graceful; /* set from signal handler */
107 int maxclients_reported;
109 * The max child slot ever assigned, preserved across restarts. Necessary
110 * to deal with MaxRequestWorkers changes across AP_SIG_GRACEFUL restarts. We
111 * use this value to optimize routines that have to scan the entire scoreboard.
113 int max_daemons_limit;
115 * idle_spawn_rate is the number of children that will be spawned on the
116 * next maintenance cycle if there aren't enough idle servers. It is
117 * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
118 * without the need to spawn.
121 #ifndef MAX_SPAWN_RATE
122 #define MAX_SPAWN_RATE (32)
124 int hold_off_on_exponential_spawning;
125 } prefork_retained_data;
126 static prefork_retained_data *retained;
128 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
130 /* one_process --- debugging mode variable; can be set from the command line
131 * with the -X flag. If set, this gets you the child_main loop running
132 * in the process which originally started up (no detach, no make_child),
133 * which is a pretty nice debugging environment. (You'll get a SIGHUP
134 * early in standalone_main; just continue through. This is the server
135 * trying to kill off any child processes which it might have lying
136 * around --- Apache doesn't keep track of their pids, it just sends
137 * SIGHUP to the process group, ignoring it in the root process.
138 * Continue through and you'll be fine.).
141 static int one_process = 0;
143 static apr_pool_t *pconf; /* Pool for config stuff */
144 static apr_pool_t *pchild; /* Pool for httpd child stuff */
146 static pid_t ap_my_pid; /* it seems silly to call getpid all the time */
147 static pid_t parent_pid;
148 static int my_child_num;
152 * change directory for gprof to plop the gmon.out file
153 * configure in httpd.conf:
154 * GprofDir $RuntimeDir/ -> $ServerRoot/$RuntimeDir/gmon.out
155 * GprofDir $RuntimeDir/% -> $ServerRoot/$RuntimeDir/gprof.$pid/gmon.out
157 static void chdir_for_gprof(void)
159 core_server_config *sconf =
160 ap_get_core_module_config(ap_server_conf->module_config);
161 char *dir = sconf->gprof_dir;
167 int len = strlen(sconf->gprof_dir) - 1;
168 if(*(dir + len) == '%') {
170 buf = ap_append_pid(pconf, dir, "gprof.");
172 use_dir = ap_server_root_relative(pconf, buf ? buf : dir);
173 res = apr_dir_make(use_dir,
174 APR_UREAD | APR_UWRITE | APR_UEXECUTE |
175 APR_GREAD | APR_GEXECUTE |
176 APR_WREAD | APR_WEXECUTE, pconf);
177 if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
178 ap_log_error(APLOG_MARK, APLOG_ERR, res, ap_server_conf,
179 "gprof: error creating directory %s", dir);
183 use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
189 #define chdir_for_gprof()
192 static void prefork_note_child_killed(int childnum, pid_t pid,
195 AP_DEBUG_ASSERT(childnum != -1); /* no scoreboard squatting with this MPM */
196 ap_run_child_status(ap_server_conf,
197 ap_scoreboard_image->parent[childnum].pid,
198 ap_scoreboard_image->parent[childnum].generation,
199 childnum, MPM_CHILD_EXITED);
200 ap_scoreboard_image->parent[childnum].pid = 0;
203 static void prefork_note_child_started(int slot, pid_t pid)
205 ap_scoreboard_image->parent[slot].pid = pid;
206 ap_run_child_status(ap_server_conf,
207 ap_scoreboard_image->parent[slot].pid,
208 retained->my_generation, slot, MPM_CHILD_STARTED);
211 /* a clean exit from a child with proper cleanup */
212 static void clean_child_exit(int code) __attribute__ ((noreturn));
213 static void clean_child_exit(int code)
215 mpm_state = AP_MPMQ_STOPPING;
218 apr_pool_destroy(pchild);
222 prefork_note_child_killed(/* slot */ 0, 0, 0);
225 ap_mpm_pod_close(pod);
230 static void accept_mutex_on(void)
232 apr_status_t rv = apr_proc_mutex_lock(accept_mutex);
233 if (rv != APR_SUCCESS) {
234 const char *msg = "couldn't grab the accept mutex";
236 if (retained->my_generation !=
237 ap_scoreboard_image->global->running_generation) {
238 ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, ap_server_conf, "%s", msg);
242 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, "%s", msg);
243 exit(APEXIT_CHILDFATAL);
248 static void accept_mutex_off(void)
250 apr_status_t rv = apr_proc_mutex_unlock(accept_mutex);
251 if (rv != APR_SUCCESS) {
252 const char *msg = "couldn't release the accept mutex";
254 if (retained->my_generation !=
255 ap_scoreboard_image->global->running_generation) {
256 ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, ap_server_conf, "%s", msg);
257 /* don't exit here... we have a connection to
258 * process, after which point we'll see that the
259 * generation changed and we'll exit cleanly
263 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, "%s", msg);
264 exit(APEXIT_CHILDFATAL);
269 /* On some architectures it's safe to do unserialized accept()s in the single
270 * Listen case. But it's never safe to do it in the case where there's
271 * multiple Listen statements. Define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
272 * when it's safe in the single Listen case.
274 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
275 #define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
277 #define SAFE_ACCEPT(stmt) do {stmt;} while(0)
280 static int prefork_query(int query_code, int *result, apr_status_t *rv)
284 case AP_MPMQ_MAX_DAEMON_USED:
285 *result = ap_daemons_limit;
287 case AP_MPMQ_IS_THREADED:
288 *result = AP_MPMQ_NOT_SUPPORTED;
290 case AP_MPMQ_IS_FORKED:
291 *result = AP_MPMQ_DYNAMIC;
293 case AP_MPMQ_HARD_LIMIT_DAEMONS:
294 *result = server_limit;
296 case AP_MPMQ_HARD_LIMIT_THREADS:
297 *result = HARD_THREAD_LIMIT;
299 case AP_MPMQ_MAX_THREADS:
302 case AP_MPMQ_MIN_SPARE_DAEMONS:
303 *result = ap_daemons_min_free;
305 case AP_MPMQ_MIN_SPARE_THREADS:
308 case AP_MPMQ_MAX_SPARE_DAEMONS:
309 *result = ap_daemons_max_free;
311 case AP_MPMQ_MAX_SPARE_THREADS:
314 case AP_MPMQ_MAX_REQUESTS_DAEMON:
315 *result = ap_max_requests_per_child;
317 case AP_MPMQ_MAX_DAEMONS:
318 *result = ap_daemons_limit;
320 case AP_MPMQ_MPM_STATE:
323 case AP_MPMQ_GENERATION:
324 *result = retained->my_generation;
333 static const char *prefork_get_name(void)
338 /*****************************************************************
339 * Connection structures and accounting...
342 static void just_die(int sig)
347 /* volatile because they're updated from a signal handler */
348 static int volatile shutdown_pending;
349 static int volatile restart_pending;
350 static int volatile die_now = 0;
352 static void stop_listening(int sig)
354 mpm_state = AP_MPMQ_STOPPING;
355 ap_close_listeners();
357 /* For a graceful stop, we want the child to exit when done */
361 static void sig_term(int sig)
363 if (shutdown_pending == 1) {
364 /* Um, is this _probably_ not an error, if the user has
365 * tried to do a shutdown twice quickly, so we won't
366 * worry about reporting it.
370 mpm_state = AP_MPMQ_STOPPING;
371 shutdown_pending = 1;
372 retained->is_graceful = (sig == AP_SIG_GRACEFUL_STOP);
375 /* restart() is the signal handler for SIGHUP and AP_SIG_GRACEFUL
376 * in the parent process, unless running in ONE_PROCESS mode
378 static void restart(int sig)
380 if (restart_pending == 1) {
381 /* Probably not an error - don't bother reporting it */
384 mpm_state = AP_MPMQ_STOPPING;
386 retained->is_graceful = (sig == AP_SIG_GRACEFUL);
389 static void set_signals(void)
391 #ifndef NO_USE_SIGACTION
396 ap_fatal_signal_setup(ap_server_conf, pconf);
399 #ifndef NO_USE_SIGACTION
400 sigemptyset(&sa.sa_mask);
403 sa.sa_handler = sig_term;
404 if (sigaction(SIGTERM, &sa, NULL) < 0)
405 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
406 #ifdef AP_SIG_GRACEFUL_STOP
407 if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0)
408 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
409 "sigaction(" AP_SIG_GRACEFUL_STOP_STRING ")");
412 if (sigaction(SIGINT, &sa, NULL) < 0)
413 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
416 sa.sa_handler = SIG_DFL;
417 if (sigaction(SIGXCPU, &sa, NULL) < 0)
418 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
421 /* For systems following the LFS standard, ignoring SIGXFSZ allows
422 * a write() beyond the 2GB limit to fail gracefully with E2BIG
423 * rather than terminate the process. */
424 sa.sa_handler = SIG_IGN;
425 if (sigaction(SIGXFSZ, &sa, NULL) < 0)
426 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
429 sa.sa_handler = SIG_IGN;
430 if (sigaction(SIGPIPE, &sa, NULL) < 0)
431 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
434 /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
437 sigaddset(&sa.sa_mask, SIGHUP);
438 sigaddset(&sa.sa_mask, AP_SIG_GRACEFUL);
439 sa.sa_handler = restart;
440 if (sigaction(SIGHUP, &sa, NULL) < 0)
441 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
442 if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0)
443 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
447 apr_signal(SIGXCPU, SIG_DFL);
450 apr_signal(SIGXFSZ, SIG_IGN);
454 apr_signal(SIGTERM, sig_term);
456 apr_signal(SIGHUP, restart);
458 #ifdef AP_SIG_GRACEFUL
459 apr_signal(AP_SIG_GRACEFUL, restart);
460 #endif /* AP_SIG_GRACEFUL */
461 #ifdef AP_SIG_GRACEFUL_STOP
462 apr_signal(AP_SIG_GRACEFUL_STOP, sig_term);
463 #endif /* AP_SIG_GRACEFUL */
465 apr_signal(SIGPIPE, SIG_IGN);
471 /*****************************************************************
472 * Child process main loop.
473 * The following vars are static to avoid getting clobbered by longjmp();
474 * they are really private to child_main.
477 static int requests_this_child;
478 static int num_listensocks = 0;
480 static void child_main(int child_num_arg)
483 apr_thread_t *thd = NULL;
484 apr_os_thread_t osthd;
487 apr_allocator_t *allocator;
491 apr_pollset_t *pollset;
493 apr_bucket_alloc_t *bucket_alloc;
494 int last_poll_idx = 0;
495 const char *lockfile;
497 mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
501 my_child_num = child_num_arg;
502 ap_my_pid = getpid();
503 requests_this_child = 0;
505 ap_fatal_signal_child_setup(ap_server_conf);
507 /* Get a sub context for global allocations in this child, so that
508 * we can have cleanups occur when the child exits.
510 apr_allocator_create(&allocator);
511 apr_allocator_max_free_set(allocator, ap_max_mem_free);
512 apr_pool_create_ex(&pchild, pconf, NULL, allocator);
513 apr_allocator_owner_set(allocator, pchild);
514 apr_pool_tag(pchild, "pchild");
517 osthd = apr_os_thread_current();
518 apr_os_thread_put(&thd, &osthd, pchild);
521 apr_pool_create(&ptrans, pchild);
522 apr_pool_tag(ptrans, "transaction");
524 /* needs to be done before we switch UIDs so we have permissions */
525 ap_reopen_scoreboard(pchild, NULL, 0);
526 lockfile = apr_proc_mutex_lockfile(accept_mutex);
527 status = apr_proc_mutex_child_init(&accept_mutex,
530 if (status != APR_SUCCESS) {
531 ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf,
532 "Couldn't initialize cross-process lock in child "
534 lockfile ? lockfile : "none",
535 apr_proc_mutex_name(accept_mutex));
536 clean_child_exit(APEXIT_CHILDFATAL);
539 if (ap_run_drop_privileges(pchild, ap_server_conf)) {
540 clean_child_exit(APEXIT_CHILDFATAL);
543 ap_run_child_init(pchild, ap_server_conf);
545 ap_create_sb_handle(&sbh, pchild, my_child_num, 0);
547 (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
549 /* Set up the pollfd array */
550 status = apr_pollset_create(&pollset, num_listensocks, pchild, 0);
551 if (status != APR_SUCCESS) {
552 ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf,
553 "Couldn't create pollset in child; check system or user limits");
554 clean_child_exit(APEXIT_CHILDSICK); /* assume temporary resource issue */
557 for (lr = ap_listeners, i = num_listensocks; i--; lr = lr->next) {
558 apr_pollfd_t pfd = { 0 };
560 pfd.desc_type = APR_POLL_SOCKET;
562 pfd.reqevents = APR_POLLIN;
563 pfd.client_data = lr;
565 status = apr_pollset_add(pollset, &pfd);
566 if (status != APR_SUCCESS) {
567 ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf,
568 "Couldn't add listener to pollset; check system or user limits");
569 clean_child_exit(APEXIT_CHILDSICK);
572 lr->accept_func = ap_unixd_accept;
575 mpm_state = AP_MPMQ_RUNNING;
577 bucket_alloc = apr_bucket_alloc_create(pchild);
579 /* die_now is set when AP_SIG_GRACEFUL is received in the child;
580 * shutdown_pending is set when SIGTERM is received when running
581 * in single process mode. */
582 while (!die_now && !shutdown_pending) {
583 conn_rec *current_conn;
587 * (Re)initialize this child to a pre-connection state.
590 apr_pool_clear(ptrans);
592 if ((ap_max_requests_per_child > 0
593 && requests_this_child++ >= ap_max_requests_per_child)) {
597 (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
600 * Wait for an acceptable connection to arrive.
603 /* Lock around "accept", if necessary */
604 SAFE_ACCEPT(accept_mutex_on());
606 if (num_listensocks == 1) {
607 /* There is only one listener record, so refer to that one. */
611 /* multiple listening sockets - need to poll */
614 const apr_pollfd_t *pdesc;
616 /* check for termination first so we don't sleep for a while in
617 * poll if already signalled
619 if (die_now /* in graceful stop/restart */
620 || (one_process && shutdown_pending)) {
621 SAFE_ACCEPT(accept_mutex_off());
625 /* timeout == 10 seconds to avoid a hang at graceful restart/stop
626 * caused by the closing of sockets by the signal handler
628 status = apr_pollset_poll(pollset, apr_time_from_sec(10),
630 if (status != APR_SUCCESS) {
631 if (APR_STATUS_IS_TIMEUP(status) ||
632 APR_STATUS_IS_EINTR(status)) {
635 /* Single Unix documents select as returning errnos
636 * EBADF, EINTR, and EINVAL... and in none of those
637 * cases does it make sense to continue. In fact
638 * on Linux 2.0.x we seem to end up with EFAULT
639 * occasionally, and we'd loop forever due to it.
641 ap_log_error(APLOG_MARK, APLOG_ERR, status,
642 ap_server_conf, "apr_pollset_poll: (listen)");
643 SAFE_ACCEPT(accept_mutex_off());
647 /* We can always use pdesc[0], but sockets at position N
648 * could end up completely starved of attention in a very
649 * busy server. Therefore, we round-robin across the
650 * returned set of descriptors. While it is possible that
651 * the returned set of descriptors might flip around and
652 * continue to starve some sockets, we happen to know the
653 * internal pollset implementation retains ordering
654 * stability of the sockets. Thus, the round-robin should
655 * ensure that a socket will eventually be serviced.
657 if (last_poll_idx >= numdesc)
660 /* Grab a listener record from the client_data of the poll
661 * descriptor, and advance our saved index to round-robin
664 * ### hmm... this descriptor might have POLLERR rather
667 lr = pdesc[last_poll_idx++].client_data;
672 /* if we accept() something we don't want to die, so we have to
675 status = lr->accept_func(&csd, lr, ptrans);
677 SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
679 if (status == APR_EGENERAL) {
680 /* resource shortage or should-not-occur occured */
683 else if (status != APR_SUCCESS) {
688 * We now have a connection, so set it up with the appropriate
689 * socket options, file descriptors, and read/write buffers.
692 current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num, sbh, bucket_alloc);
695 current_conn->current_thread = thd;
697 ap_process_connection(current_conn, csd);
698 ap_lingering_close(current_conn);
701 /* Check the pod and the generation number after processing a
702 * connection so that we'll go away if a graceful restart occurred
703 * while we were processing the connection or we are the lucky
704 * idle server process that gets to die.
706 if (ap_mpm_pod_check(pod) == APR_SUCCESS) { /* selected as idle? */
709 else if (retained->my_generation !=
710 ap_scoreboard_image->global->running_generation) { /* restart? */
711 /* yeah, this could be non-graceful restart, in which case the
712 * parent will kill us soon enough, but why bother checking?
717 apr_pool_clear(ptrans); /* kludge to avoid crash in APR reslist cleanup code */
722 static int make_child(server_rec *s, int slot)
726 if (slot + 1 > retained->max_daemons_limit) {
727 retained->max_daemons_limit = slot + 1;
731 apr_signal(SIGHUP, sig_term);
732 /* Don't catch AP_SIG_GRACEFUL in ONE_PROCESS mode :) */
733 apr_signal(SIGINT, sig_term);
735 apr_signal(SIGQUIT, SIG_DFL);
737 apr_signal(SIGTERM, sig_term);
738 prefork_note_child_started(slot, getpid());
743 (void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING,
744 (request_rec *) NULL);
748 /* BS2000 requires a "special" version of fork() before a setuid() call */
749 if ((pid = os_fork(ap_unixd_config.user_name)) == -1) {
751 if ((pid = fork()) == -1) {
753 ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "fork: Unable to fork new process");
755 /* fork didn't succeed. Fix the scoreboard or else
756 * it will say SERVER_STARTING forever and ever
758 (void) ap_update_child_status_from_indexes(slot, 0, SERVER_DEAD,
759 (request_rec *) NULL);
761 /* In case system resources are maxxed out, we don't want
762 * Apache running away with the CPU trying to fork over and
763 * over and over again.
771 #ifdef HAVE_BINDPROCESSOR
772 /* by default AIX binds to a single processor
773 * this bit unbinds children which will then bind to another cpu
775 int status = bindprocessor(BINDPROCESS, (int)getpid(),
776 PROCESSOR_CLASS_ANY);
778 ap_log_error(APLOG_MARK, APLOG_DEBUG, errno,
779 ap_server_conf, "processor unbind failed");
782 RAISE_SIGSTOP(MAKE_CHILD);
784 /* Disable the parent's signal handlers and set up proper handling in
787 apr_signal(SIGHUP, just_die);
788 apr_signal(SIGTERM, just_die);
789 /* The child process just closes listeners on AP_SIG_GRACEFUL.
790 * The pod is used for signalling the graceful restart.
792 apr_signal(AP_SIG_GRACEFUL, stop_listening);
796 prefork_note_child_started(slot, pid);
802 /* start up a bunch of children */
803 static void startup_children(int number_to_start)
807 for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
808 if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
811 if (make_child(ap_server_conf, i) < 0) {
818 static void perform_idle_server_maintenance(apr_pool_t *p)
824 int free_slots[MAX_SPAWN_RATE];
828 /* initialize the free_list */
835 for (i = 0; i < ap_daemons_limit; ++i) {
838 if (i >= retained->max_daemons_limit && free_length == retained->idle_spawn_rate)
840 ws = &ap_scoreboard_image->servers[i][0];
842 if (status == SERVER_DEAD) {
843 /* try to keep children numbers as low as possible */
844 if (free_length < retained->idle_spawn_rate) {
845 free_slots[free_length] = i;
850 /* We consider a starting server as idle because we started it
851 * at least a cycle ago, and if it still hasn't finished starting
852 * then we're just going to swamp things worse by forking more.
853 * So we hopefully won't need to fork more if we count it.
854 * This depends on the ordering of SERVER_READY and SERVER_STARTING.
856 if (status <= SERVER_READY) {
864 retained->max_daemons_limit = last_non_dead + 1;
865 if (idle_count > ap_daemons_max_free) {
866 /* kill off one child... we use the pod because that'll cause it to
867 * shut down gracefully, in case it happened to pick up a request
868 * while we were counting
870 ap_mpm_pod_signal(pod);
871 retained->idle_spawn_rate = 1;
873 else if (idle_count < ap_daemons_min_free) {
874 /* terminate the free list */
875 if (free_length == 0) {
876 /* only report this condition once */
877 if (!retained->maxclients_reported) {
878 ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
879 "server reached MaxRequestWorkers setting, consider"
880 " raising the MaxRequestWorkers setting");
881 retained->maxclients_reported = 1;
883 retained->idle_spawn_rate = 1;
886 if (retained->idle_spawn_rate >= 8) {
887 ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
888 "server seems busy, (you may need "
889 "to increase StartServers, or Min/MaxSpareServers), "
890 "spawning %d children, there are %d idle, and "
891 "%d total children", retained->idle_spawn_rate,
892 idle_count, total_non_dead);
894 for (i = 0; i < free_length; ++i) {
895 make_child(ap_server_conf, free_slots[i]);
897 /* the next time around we want to spawn twice as many if this
898 * wasn't good enough, but not if we've just done a graceful
900 if (retained->hold_off_on_exponential_spawning) {
901 --retained->hold_off_on_exponential_spawning;
903 else if (retained->idle_spawn_rate < MAX_SPAWN_RATE) {
904 retained->idle_spawn_rate *= 2;
909 retained->idle_spawn_rate = 1;
913 /*****************************************************************
914 * Executive routines.
917 static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
920 int remaining_children_to_start;
923 ap_log_pid(pconf, ap_pid_fname);
925 /* Initialize cross-process accept lock */
926 rv = ap_proc_mutex_create(&accept_mutex, NULL, AP_ACCEPT_MUTEX_TYPE, NULL,
928 if (rv != APR_SUCCESS) {
929 mpm_state = AP_MPMQ_STOPPING;
933 if (!retained->is_graceful) {
934 if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
935 mpm_state = AP_MPMQ_STOPPING;
938 /* fix the generation number in the global score; we just got a new,
941 ap_scoreboard_image->global->running_generation = retained->my_generation;
948 make_child(ap_server_conf, 0);
952 if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
953 ap_daemons_max_free = ap_daemons_min_free + 1;
955 /* If we're doing a graceful_restart then we're going to see a lot
956 * of children exiting immediately when we get into the main loop
957 * below (because we just sent them AP_SIG_GRACEFUL). This happens pretty
958 * rapidly... and for each one that exits we'll start a new one until
959 * we reach at least daemons_min_free. But we may be permitted to
960 * start more than that, so we'll just keep track of how many we're
961 * supposed to start up without the 1 second penalty between each fork.
963 remaining_children_to_start = ap_daemons_to_start;
964 if (remaining_children_to_start > ap_daemons_limit) {
965 remaining_children_to_start = ap_daemons_limit;
967 if (!retained->is_graceful) {
968 startup_children(remaining_children_to_start);
969 remaining_children_to_start = 0;
972 /* give the system some time to recover before kicking into
975 retained->hold_off_on_exponential_spawning = 10;
978 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
979 "%s configured -- resuming normal operations",
980 ap_get_server_description());
981 ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
982 "Server built: %s", ap_get_server_built());
983 ap_log_command_line(plog, s);
984 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
985 "Accept mutex: %s (default: %s)",
986 apr_proc_mutex_name(accept_mutex),
987 apr_proc_mutex_defname());
988 restart_pending = shutdown_pending = 0;
990 mpm_state = AP_MPMQ_RUNNING;
992 while (!restart_pending && !shutdown_pending) {
994 apr_exit_why_e exitwhy;
995 int status, processed_status;
996 /* this is a memory leak, but I'll fix it later. */
999 ap_wait_or_timeout(&exitwhy, &status, &pid, pconf, ap_server_conf);
1001 /* XXX: if it takes longer than 1 second for all our children
1002 * to start up and get into IDLE state then we may spawn an
1005 if (pid.pid != -1) {
1006 processed_status = ap_process_child_status(&pid, exitwhy, status);
1007 if (processed_status == APEXIT_CHILDFATAL) {
1008 mpm_state = AP_MPMQ_STOPPING;
1012 /* non-fatal death... note that it's gone in the scoreboard. */
1013 child_slot = ap_find_child_by_pid(&pid);
1014 if (child_slot >= 0) {
1015 (void) ap_update_child_status_from_indexes(child_slot, 0, SERVER_DEAD,
1016 (request_rec *) NULL);
1017 prefork_note_child_killed(child_slot, 0, 0);
1018 if (processed_status == APEXIT_CHILDSICK) {
1019 /* child detected a resource shortage (E[NM]FILE, ENOBUFS, etc)
1020 * cut the fork rate to the minimum
1022 retained->idle_spawn_rate = 1;
1024 else if (remaining_children_to_start
1025 && child_slot < ap_daemons_limit) {
1026 /* we're still doing a 1-for-1 replacement of dead
1027 * children with new children
1029 make_child(ap_server_conf, child_slot);
1030 --remaining_children_to_start;
1032 #if APR_HAS_OTHER_CHILD
1034 else if (apr_proc_other_child_alert(&pid, APR_OC_REASON_DEATH, status) == APR_SUCCESS) {
1038 else if (retained->is_graceful) {
1039 /* Great, we've probably just lost a slot in the
1040 * scoreboard. Somehow we don't know about this
1043 ap_log_error(APLOG_MARK, APLOG_WARNING,
1045 "long lost child came home! (pid %ld)", (long)pid.pid);
1047 /* Don't perform idle maintenance when a child dies,
1048 * only do it when there's a timeout. Remember only a
1049 * finite number of children can die, and it's pretty
1050 * pathological for a lot to die suddenly.
1054 else if (remaining_children_to_start) {
1055 /* we hit a 1 second timeout in which none of the previous
1056 * generation of children needed to be reaped... so assume
1057 * they're all done, and pick up the slack if any is left.
1059 startup_children(remaining_children_to_start);
1060 remaining_children_to_start = 0;
1061 /* In any event we really shouldn't do the code below because
1062 * few of the servers we just started are in the IDLE state
1063 * yet, so we'd mistakenly create an extra server.
1068 perform_idle_server_maintenance(pconf);
1072 mpm_state = AP_MPMQ_STOPPING;
1074 if (shutdown_pending && !retained->is_graceful) {
1075 /* Time to shut down:
1076 * Kill child processes, tell them to call child_exit, etc...
1078 if (ap_unixd_killpg(getpgrp(), SIGTERM) < 0) {
1079 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
1081 ap_reclaim_child_processes(1, /* Start with SIGTERM */
1082 prefork_note_child_killed);
1084 /* cleanup pid file on normal shutdown */
1085 ap_remove_pid(pconf, ap_pid_fname);
1086 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1087 "caught SIGTERM, shutting down");
1090 } else if (shutdown_pending) {
1091 /* Time to perform a graceful shut down:
1092 * Reap the inactive children, and ask the active ones
1093 * to close their listeners, then wait until they are
1096 int active_children;
1097 apr_time_t cutoff = 0;
1099 /* Stop listening */
1100 ap_close_listeners();
1102 /* kill off the idle ones */
1103 ap_mpm_pod_killpg(pod, retained->max_daemons_limit);
1105 /* Send SIGUSR1 to the active children */
1106 active_children = 0;
1107 for (index = 0; index < ap_daemons_limit; ++index) {
1108 if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
1109 /* Ask each child to close its listeners. */
1110 ap_mpm_safe_kill(MPM_CHILD_PID(index), AP_SIG_GRACEFUL);
1115 /* Allow each child which actually finished to exit */
1116 ap_relieve_child_processes(prefork_note_child_killed);
1118 /* cleanup pid file */
1119 ap_remove_pid(pconf, ap_pid_fname);
1120 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1121 "caught " AP_SIG_GRACEFUL_STOP_STRING ", shutting down gracefully");
1123 if (ap_graceful_shutdown_timeout) {
1124 cutoff = apr_time_now() +
1125 apr_time_from_sec(ap_graceful_shutdown_timeout);
1128 /* Don't really exit until each child has finished */
1129 shutdown_pending = 0;
1131 /* Pause for a second */
1134 /* Relieve any children which have now exited */
1135 ap_relieve_child_processes(prefork_note_child_killed);
1137 active_children = 0;
1138 for (index = 0; index < ap_daemons_limit; ++index) {
1139 if (ap_mpm_safe_kill(MPM_CHILD_PID(index), 0) == APR_SUCCESS) {
1140 active_children = 1;
1141 /* Having just one child is enough to stay around */
1145 } while (!shutdown_pending && active_children &&
1146 (!ap_graceful_shutdown_timeout || apr_time_now() < cutoff));
1148 /* We might be here because we received SIGTERM, either
1149 * way, try and make sure that all of our processes are
1152 ap_unixd_killpg(getpgrp(), SIGTERM);
1157 /* we've been told to restart */
1158 apr_signal(SIGHUP, SIG_IGN);
1159 apr_signal(AP_SIG_GRACEFUL, SIG_IGN);
1161 /* not worth thinking about */
1165 /* advance to the next generation */
1166 /* XXX: we really need to make sure this new generation number isn't in
1167 * use by any of the children.
1169 ++retained->my_generation;
1170 ap_scoreboard_image->global->running_generation = retained->my_generation;
1172 if (retained->is_graceful) {
1173 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1174 "Graceful restart requested, doing restart");
1176 /* kill off the idle ones */
1177 ap_mpm_pod_killpg(pod, retained->max_daemons_limit);
1179 /* This is mostly for debugging... so that we know what is still
1180 * gracefully dealing with existing request. This will break
1181 * in a very nasty way if we ever have the scoreboard totally
1182 * file-based (no shared memory)
1184 for (index = 0; index < ap_daemons_limit; ++index) {
1185 if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
1186 ap_scoreboard_image->servers[index][0].status = SERVER_GRACEFUL;
1187 /* Ask each child to close its listeners.
1189 * NOTE: we use the scoreboard, because if we send SIGUSR1
1190 * to every process in the group, this may include CGI's,
1191 * piped loggers, etc. They almost certainly won't handle
1194 ap_mpm_safe_kill(ap_scoreboard_image->parent[index].pid, AP_SIG_GRACEFUL);
1200 if (ap_unixd_killpg(getpgrp(), SIGHUP) < 0) {
1201 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
1203 ap_reclaim_child_processes(0, /* Not when just starting up */
1204 prefork_note_child_killed);
1205 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1206 "SIGHUP received. Attempting to restart");
1212 /* This really should be a post_config hook, but the error log is already
1213 * redirected by that point, so we need to do this in the open_logs phase.
1215 static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
1218 int level_flags = 0;
1223 /* the reverse of pre_config, we want this only the first time around */
1224 if (retained->module_loads == 1) {
1226 level_flags |= APLOG_STARTUP;
1229 if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) {
1230 ap_log_error(APLOG_MARK, APLOG_ALERT | level_flags, 0,
1231 (startup ? NULL : s),
1232 "no listening sockets available, shutting down");
1236 if ((rv = ap_mpm_pod_open(pconf, &pod))) {
1237 ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
1238 (startup ? NULL : s),
1239 "could not open pipe-of-death");
1245 static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
1247 int no_detach, debug, foreground;
1249 const char *userdata_key = "mpm_prefork_module";
1251 mpm_state = AP_MPMQ_STARTING;
1253 debug = ap_exists_config_define("DEBUG");
1256 foreground = one_process = 1;
1261 no_detach = ap_exists_config_define("NO_DETACH");
1262 one_process = ap_exists_config_define("ONE_PROCESS");
1263 foreground = ap_exists_config_define("FOREGROUND");
1266 ap_mutex_register(p, AP_ACCEPT_MUTEX_TYPE, NULL, APR_LOCK_DEFAULT, 0);
1268 /* sigh, want this only the second time around */
1269 retained = ap_retained_data_get(userdata_key);
1271 retained = ap_retained_data_create(userdata_key, sizeof(*retained));
1272 retained->max_daemons_limit = -1;
1273 retained->idle_spawn_rate = 1;
1275 ++retained->module_loads;
1276 if (retained->module_loads == 2) {
1277 if (!one_process && !foreground) {
1278 rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND
1279 : APR_PROC_DETACH_DAEMONIZE);
1280 if (rv != APR_SUCCESS) {
1281 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
1282 "apr_proc_detach failed");
1283 return HTTP_INTERNAL_SERVER_ERROR;
1288 parent_pid = ap_my_pid = getpid();
1290 ap_listen_pre_config();
1291 ap_daemons_to_start = DEFAULT_START_DAEMON;
1292 ap_daemons_min_free = DEFAULT_MIN_FREE_DAEMON;
1293 ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
1294 server_limit = DEFAULT_SERVER_LIMIT;
1295 ap_daemons_limit = server_limit;
1296 ap_extended_status = 0;
1301 static int prefork_check_config(apr_pool_t *p, apr_pool_t *plog,
1302 apr_pool_t *ptemp, server_rec *s)
1306 /* the reverse of pre_config, we want this only the first time around */
1307 if (retained->module_loads == 1) {
1311 if (server_limit > MAX_SERVER_LIMIT) {
1313 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1314 "WARNING: ServerLimit of %d exceeds compile-time "
1315 "limit of", server_limit);
1316 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1317 " %d servers, decreasing to %d.",
1318 MAX_SERVER_LIMIT, MAX_SERVER_LIMIT);
1320 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1321 "ServerLimit of %d exceeds compile-time limit "
1322 "of %d, decreasing to match",
1323 server_limit, MAX_SERVER_LIMIT);
1325 server_limit = MAX_SERVER_LIMIT;
1327 else if (server_limit < 1) {
1329 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1330 "WARNING: ServerLimit of %d not allowed, "
1331 "increasing to 1.", server_limit);
1333 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1334 "ServerLimit of %d not allowed, increasing to 1",
1340 /* you cannot change ServerLimit across a restart; ignore
1343 if (!retained->first_server_limit) {
1344 retained->first_server_limit = server_limit;
1346 else if (server_limit != retained->first_server_limit) {
1347 /* don't need a startup console version here */
1348 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1349 "changing ServerLimit to %d from original value of %d "
1350 "not allowed during restart",
1351 server_limit, retained->first_server_limit);
1352 server_limit = retained->first_server_limit;
1355 if (ap_daemons_limit > server_limit) {
1357 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1358 "WARNING: MaxRequestWorkers of %d exceeds ServerLimit "
1359 "value of", ap_daemons_limit);
1360 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1361 " %d servers, decreasing MaxRequestWorkers to %d.",
1362 server_limit, server_limit);
1363 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1364 " To increase, please see the ServerLimit "
1367 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1368 "MaxRequestWorkers of %d exceeds ServerLimit value "
1369 "of %d, decreasing to match",
1370 ap_daemons_limit, server_limit);
1372 ap_daemons_limit = server_limit;
1374 else if (ap_daemons_limit < 1) {
1376 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1377 "WARNING: MaxRequestWorkers of %d not allowed, "
1378 "increasing to 1.", ap_daemons_limit);
1380 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1381 "MaxRequestWorkers of %d not allowed, increasing to 1",
1384 ap_daemons_limit = 1;
1387 /* ap_daemons_to_start > ap_daemons_limit checked in prefork_run() */
1388 if (ap_daemons_to_start < 0) {
1390 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1391 "WARNING: StartServers of %d not allowed, "
1392 "increasing to 1.", ap_daemons_to_start);
1394 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1395 "StartServers of %d not allowed, increasing to 1",
1396 ap_daemons_to_start);
1398 ap_daemons_to_start = 1;
1401 if (ap_daemons_min_free < 1) {
1403 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1404 "WARNING: MinSpareServers of %d not allowed, "
1405 "increasing to 1", ap_daemons_min_free);
1406 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1407 " to avoid almost certain server failure.");
1408 ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
1409 " Please read the documentation.");
1411 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1412 "MinSpareServers of %d not allowed, increasing to 1",
1413 ap_daemons_min_free);
1415 ap_daemons_min_free = 1;
1418 /* ap_daemons_max_free < ap_daemons_min_free + 1 checked in prefork_run() */
1423 static void prefork_hooks(apr_pool_t *p)
1425 /* Our open_logs hook function must run before the core's, or stderr
1426 * will be redirected to a file, and the messages won't print to the
1429 static const char *const aszSucc[] = {"core.c", NULL};
1431 ap_hook_open_logs(prefork_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST);
1432 /* we need to set the MPM state before other pre-config hooks use MPM query
1433 * to retrieve it, so register as REALLY_FIRST
1435 ap_hook_pre_config(prefork_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
1436 ap_hook_check_config(prefork_check_config, NULL, NULL, APR_HOOK_MIDDLE);
1437 ap_hook_mpm(prefork_run, NULL, NULL, APR_HOOK_MIDDLE);
1438 ap_hook_mpm_query(prefork_query, NULL, NULL, APR_HOOK_MIDDLE);
1439 ap_hook_mpm_get_name(prefork_get_name, NULL, NULL, APR_HOOK_MIDDLE);
1442 static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
1444 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1449 ap_daemons_to_start = atoi(arg);
1453 static const char *set_min_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
1455 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1460 ap_daemons_min_free = atoi(arg);
1464 static const char *set_max_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
1466 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1471 ap_daemons_max_free = atoi(arg);
1475 static const char *set_max_clients (cmd_parms *cmd, void *dummy, const char *arg)
1477 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1481 if (!strcasecmp(cmd->cmd->name, "MaxClients")) {
1482 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
1483 "MaxClients is deprecated, use MaxRequestWorkers "
1486 ap_daemons_limit = atoi(arg);
1490 static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
1492 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1497 server_limit = atoi(arg);
1501 static const command_rec prefork_cmds[] = {
1503 AP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF,
1504 "Number of child processes launched at server startup"),
1505 AP_INIT_TAKE1("MinSpareServers", set_min_free_servers, NULL, RSRC_CONF,
1506 "Minimum number of idle children, to handle request spikes"),
1507 AP_INIT_TAKE1("MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF,
1508 "Maximum number of idle children"),
1509 AP_INIT_TAKE1("MaxClients", set_max_clients, NULL, RSRC_CONF,
1510 "Deprecated name of MaxRequestWorkers"),
1511 AP_INIT_TAKE1("MaxRequestWorkers", set_max_clients, NULL, RSRC_CONF,
1512 "Maximum number of children alive at the same time"),
1513 AP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF,
1514 "Maximum value of MaxRequestWorkers for this run of Apache"),
1515 AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND,
1519 AP_DECLARE_MODULE(mpm_prefork) = {
1521 NULL, /* hook to run before apache parses args */
1522 NULL, /* create per-directory config structure */
1523 NULL, /* merge per-directory config structures */
1524 NULL, /* create per-server config structure */
1525 NULL, /* merge per-server config structures */
1526 prefork_cmds, /* command apr_table_t */
1527 prefork_hooks, /* register hooks */