/[apache]/trunk/dist/2.2/patches/21_all_itk-20061030-01.patch
Gentoo

Contents of /trunk/dist/2.2/patches/21_all_itk-20061030-01.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 105 - (show annotations) (download)
Fri Jan 26 17:37:51 2007 UTC (7 years, 11 months ago) by phreak
File size: 64835 byte(s)
Adding the itk patch back, as UPSTREAM released a new patch for 2.2.0 (which applies fine to 2.2.4).
1 Index: httpd-2.2.4/server/mpm/config.m4
2 ===================================================================
3 --- httpd-2.2.4.orig/server/mpm/config.m4
4 +++ httpd-2.2.4/server/mpm/config.m4
5 @@ -1,7 +1,7 @@
6 AC_MSG_CHECKING(which MPM to use)
7 AC_ARG_WITH(mpm,
8 APACHE_HELP_STRING(--with-mpm=MPM,Choose the process model for Apache to use.
9 - MPM={beos|event|worker|prefork|mpmt_os2}),[
10 + MPM={beos|event|worker|prefork|mpmt_os2|itk}),[
11 APACHE_MPM=$withval
12 ],[
13 if test "x$APACHE_MPM" = "x"; then
14 @@ -23,7 +23,7 @@ ap_mpm_is_threaded ()
15
16 ap_mpm_is_experimental ()
17 {
18 - if test "$apache_cv_mpm" = "event" ; then
19 + if test "$apache_cv_mpm" = "event" -o "$apache_cv_mpm" = "itk" ; then
20 return 0
21 else
22 return 1
23 @@ -63,6 +63,8 @@ MPM_NAME=$apache_cv_mpm
24 if ap_mpm_is_experimental; then
25 AC_MSG_WARN(You have selected an EXPERIMENTAL MPM. Be warned!)
26 MPM_SUBDIR_NAME=experimental/$MPM_NAME
27 +
28 + AC_CHECK_LIB(cap, cap_init)
29 else
30 MPM_SUBDIR_NAME=$MPM_NAME
31 fi
32 Index: httpd-2.2.4/server/mpm/experimental/itk/Makefile.in
33 ===================================================================
34 --- /dev/null
35 +++ httpd-2.2.4/server/mpm/experimental/itk/Makefile.in
36 @@ -0,0 +1,5 @@
37 +
38 +LTLIBRARY_NAME = libitk.la
39 +LTLIBRARY_SOURCES = itk.c
40 +
41 +include $(top_srcdir)/build/ltlib.mk
42 Index: httpd-2.2.4/server/mpm/experimental/itk/config.m4
43 ===================================================================
44 --- /dev/null
45 +++ httpd-2.2.4/server/mpm/experimental/itk/config.m4
46 @@ -0,0 +1,3 @@
47 +if test "$MPM_NAME" = "itk" ; then
48 + APACHE_FAST_OUTPUT(server/mpm/$MPM_SUBDIR_NAME/Makefile)
49 +fi
50 Index: httpd-2.2.4/server/mpm/experimental/itk/itk.c
51 ===================================================================
52 --- /dev/null
53 +++ httpd-2.2.4/server/mpm/experimental/itk/itk.c
54 @@ -0,0 +1,1650 @@
55 +/* Licensed to the Apache Software Foundation (ASF) under one or more
56 + * contributor license agreements. See the NOTICE file distributed with
57 + * this work for additional information regarding copyright ownership.
58 + * The ASF licenses this file to You under the Apache License, Version 2.0
59 + * (the "License"); you may not use this file except in compliance with
60 + * the License. You may obtain a copy of the License at
61 + *
62 + * http://www.apache.org/licenses/LICENSE-2.0
63 + *
64 + * Unless required by applicable law or agreed to in writing, software
65 + * distributed under the License is distributed on an "AS IS" BASIS,
66 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67 + * See the License for the specific language governing permissions and
68 + * limitations under the License.
69 + *
70 + * Portions copyright 2005-2006 Steinar H. Gunderson <sgunderson@bigfoot.com>.
71 + * Licensed under the same terms as the rest of Apache.
72 + */
73 +
74 +#include "apr.h"
75 +#include "apr_portable.h"
76 +#include "apr_strings.h"
77 +#include "apr_thread_proc.h"
78 +#include "apr_signal.h"
79 +
80 +# define _DBG(text,par...) \
81 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, \
82 + "(itkmpm: pid=%d uid=%d) %s(): " text, \
83 + getpid(), getuid(), __FUNCTION__, par)
84 +
85 +#define APR_WANT_STDIO
86 +#define APR_WANT_STRFUNC
87 +#include "apr_want.h"
88 +
89 +#if APR_HAVE_UNISTD_H
90 +#include <unistd.h>
91 +#endif
92 +#if APR_HAVE_SYS_TYPES_H
93 +#include <sys/types.h>
94 +#endif
95 +
96 +#define CORE_PRIVATE
97 +
98 +#include "ap_config.h"
99 +#include "httpd.h"
100 +#include "mpm_default.h"
101 +#include "http_main.h"
102 +#include "http_log.h"
103 +#include "http_config.h"
104 +#include "http_core.h" /* for get_remote_host */
105 +#include "http_connection.h"
106 +#include "http_protocol.h" /* for ap_hook_post_read_request */
107 +#include "scoreboard.h"
108 +#include "ap_mpm.h"
109 +#include "unixd.h"
110 +#include "mpm_common.h"
111 +#include "ap_listen.h"
112 +#include "ap_mmn.h"
113 +#include "apr_poll.h"
114 +
115 +#ifdef HAVE_BSTRING_H
116 +#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
117 +#endif
118 +#ifdef HAVE_TIME_H
119 +#include <time.h>
120 +#endif
121 +#ifdef HAVE_SYS_PROCESSOR_H
122 +#include <sys/processor.h> /* for bindprocessor() */
123 +#endif
124 +
125 +#if HAVE_LIBCAP
126 +#include <sys/capability.h>
127 +#endif
128 +
129 +#include <signal.h>
130 +#include <sys/times.h>
131 +
132 +/* Limit on the total --- clients will be locked out if more servers than
133 + * this are needed. It is intended solely to keep the server from crashing
134 + * when things get out of hand.
135 + *
136 + * We keep a hard maximum number of servers, for two reasons --- first off,
137 + * in case something goes seriously wrong, we want to stop the fork bomb
138 + * short of actually crashing the machine we're running on by filling some
139 + * kernel table. Secondly, it keeps the size of the scoreboard file small
140 + * enough that we can read the whole thing without worrying too much about
141 + * the overhead.
142 + */
143 +#ifndef DEFAULT_SERVER_LIMIT
144 +#define DEFAULT_SERVER_LIMIT 256
145 +#endif
146 +
147 +/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want
148 + * some sort of compile-time limit to help catch typos.
149 + */
150 +#ifndef MAX_SERVER_LIMIT
151 +#define MAX_SERVER_LIMIT 200000
152 +#endif
153 +
154 +#ifndef HARD_THREAD_LIMIT
155 +#define HARD_THREAD_LIMIT 1
156 +#endif
157 +
158 +/* config globals */
159 +
160 +int ap_threads_per_child=0; /* Worker threads per child */
161 +static apr_proc_mutex_t *accept_mutex;
162 +static int ap_daemons_to_start=0;
163 +static int ap_daemons_min_free=0;
164 +static int ap_daemons_max_free=0;
165 +static int ap_daemons_limit=0; /* MaxClients */
166 +static int server_limit = DEFAULT_SERVER_LIMIT;
167 +static int first_server_limit = 0;
168 +static int changed_limit_at_restart;
169 +static int mpm_state = AP_MPMQ_STARTING;
170 +static ap_pod_t *pod;
171 +
172 +/*
173 + * The max child slot ever assigned, preserved across restarts. Necessary
174 + * to deal with MaxClients changes across AP_SIG_GRACEFUL restarts. We
175 + * use this value to optimize routines that have to scan the entire scoreboard.
176 + */
177 +int ap_max_daemons_limit = -1;
178 +server_rec *ap_server_conf;
179 +
180 +/* one_process --- debugging mode variable; can be set from the command line
181 + * with the -X flag. If set, this gets you the child_main loop running
182 + * in the process which originally started up (no detach, no make_child),
183 + * which is a pretty nice debugging environment. (You'll get a SIGHUP
184 + * early in standalone_main; just continue through. This is the server
185 + * trying to kill off any child processes which it might have lying
186 + * around --- Apache doesn't keep track of their pids, it just sends
187 + * SIGHUP to the process group, ignoring it in the root process.
188 + * Continue through and you'll be fine.).
189 + */
190 +
191 +static int one_process = 0;
192 +
193 +static apr_pool_t *pconf; /* Pool for config stuff */
194 +static apr_pool_t *pchild; /* Pool for httpd child stuff */
195 +
196 +static pid_t ap_my_pid; /* it seems silly to call getpid all the time */
197 +static pid_t parent_pid;
198 +#ifndef MULTITHREAD
199 +static int my_child_num;
200 +#endif
201 +ap_generation_t volatile ap_my_generation=0;
202 +
203 +#ifdef TPF
204 +int tpf_child = 0;
205 +char tpf_server_name[INETD_SERVNAME_LENGTH+1];
206 +#endif /* TPF */
207 +
208 +static volatile int die_now = 0;
209 +
210 +typedef struct
211 +{
212 + uid_t uid;
213 + gid_t gid;
214 + char *username;
215 + int max_clients_vhost;
216 +} itk_server_conf;
217 +
218 +module AP_MODULE_DECLARE_DATA mpm_itk_module;
219 +
220 +#ifdef GPROF
221 +/*
222 + * change directory for gprof to plop the gmon.out file
223 + * configure in httpd.conf:
224 + * GprofDir $RuntimeDir/ -> $ServerRoot/$RuntimeDir/gmon.out
225 + * GprofDir $RuntimeDir/% -> $ServerRoot/$RuntimeDir/gprof.$pid/gmon.out
226 + */
227 +static void chdir_for_gprof(void)
228 +{
229 + core_server_config *sconf =
230 + ap_get_module_config(ap_server_conf->module_config, &core_module);
231 + char *dir = sconf->gprof_dir;
232 + const char *use_dir;
233 +
234 + if(dir) {
235 + apr_status_t res;
236 + char *buf = NULL ;
237 + int len = strlen(sconf->gprof_dir) - 1;
238 + if(*(dir + len) == '%') {
239 + dir[len] = '\0';
240 + buf = ap_append_pid(pconf, dir, "gprof.");
241 + }
242 + use_dir = ap_server_root_relative(pconf, buf ? buf : dir);
243 + res = apr_dir_make(use_dir,
244 + APR_UREAD | APR_UWRITE | APR_UEXECUTE |
245 + APR_GREAD | APR_GEXECUTE |
246 + APR_WREAD | APR_WEXECUTE, pconf);
247 + if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
248 + ap_log_error(APLOG_MARK, APLOG_ERR, res, ap_server_conf,
249 + "gprof: error creating directory %s", dir);
250 + }
251 + }
252 + else {
253 + use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
254 + }
255 +
256 + chdir(use_dir);
257 +}
258 +#else
259 +#define chdir_for_gprof()
260 +#endif
261 +
262 +/* XXX - I don't know if TPF will ever use this module or not, so leave
263 + * the ap_check_signals calls in but disable them - manoj */
264 +#define ap_check_signals()
265 +
266 +/* a clean exit from a child with proper cleanup */
267 +static void clean_child_exit(int code) __attribute__ ((noreturn));
268 +static void clean_child_exit(int code)
269 +{
270 + mpm_state = AP_MPMQ_STOPPING;
271 +
272 + if (pchild) {
273 + apr_pool_destroy(pchild);
274 + }
275 + ap_mpm_pod_close(pod);
276 + chdir_for_gprof();
277 + exit(code);
278 +}
279 +
280 +static void accept_mutex_on(void)
281 +{
282 + apr_status_t rv = apr_proc_mutex_lock(accept_mutex);
283 + if (rv != APR_SUCCESS) {
284 + const char *msg = "couldn't grab the accept mutex";
285 +
286 + if (ap_my_generation !=
287 + ap_scoreboard_image->global->running_generation) {
288 + ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, "%s", msg);
289 + clean_child_exit(0);
290 + }
291 + else {
292 + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "%s", msg);
293 + exit(APEXIT_CHILDFATAL);
294 + }
295 + }
296 +}
297 +
298 +static void accept_mutex_off(void)
299 +{
300 + apr_status_t rv = apr_proc_mutex_unlock(accept_mutex);
301 + if (rv != APR_SUCCESS) {
302 + const char *msg = "couldn't release the accept mutex";
303 +
304 + if (ap_my_generation !=
305 + ap_scoreboard_image->global->running_generation) {
306 + ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, "%s", msg);
307 + /* don't exit here... we have a connection to
308 + * process, after which point we'll see that the
309 + * generation changed and we'll exit cleanly
310 + */
311 + }
312 + else {
313 + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "%s", msg);
314 + exit(APEXIT_CHILDFATAL);
315 + }
316 + }
317 +}
318 +
319 +/* On some architectures it's safe to do unserialized accept()s in the single
320 + * Listen case. But it's never safe to do it in the case where there's
321 + * multiple Listen statements. Define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
322 + * when it's safe in the single Listen case.
323 + */
324 +#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
325 +#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
326 +#else
327 +#define SAFE_ACCEPT(stmt) do {stmt;} while(0)
328 +#endif
329 +
330 +AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
331 +{
332 + switch(query_code){
333 + case AP_MPMQ_MAX_DAEMON_USED:
334 + *result = ap_daemons_limit;
335 + return APR_SUCCESS;
336 + case AP_MPMQ_IS_THREADED:
337 + *result = AP_MPMQ_NOT_SUPPORTED;
338 + return APR_SUCCESS;
339 + case AP_MPMQ_IS_FORKED:
340 + *result = AP_MPMQ_DYNAMIC;
341 + return APR_SUCCESS;
342 + case AP_MPMQ_HARD_LIMIT_DAEMONS:
343 + *result = server_limit;
344 + return APR_SUCCESS;
345 + case AP_MPMQ_HARD_LIMIT_THREADS:
346 + *result = HARD_THREAD_LIMIT;
347 + return APR_SUCCESS;
348 + case AP_MPMQ_MAX_THREADS:
349 + *result = 0;
350 + return APR_SUCCESS;
351 + case AP_MPMQ_MIN_SPARE_DAEMONS:
352 + *result = ap_daemons_min_free;
353 + return APR_SUCCESS;
354 + case AP_MPMQ_MIN_SPARE_THREADS:
355 + *result = 0;
356 + return APR_SUCCESS;
357 + case AP_MPMQ_MAX_SPARE_DAEMONS:
358 + *result = ap_daemons_max_free;
359 + return APR_SUCCESS;
360 + case AP_MPMQ_MAX_SPARE_THREADS:
361 + *result = 0;
362 + return APR_SUCCESS;
363 + case AP_MPMQ_MAX_REQUESTS_DAEMON:
364 + *result = ap_max_requests_per_child;
365 + return APR_SUCCESS;
366 + case AP_MPMQ_MAX_DAEMONS:
367 + *result = server_limit;
368 + return APR_SUCCESS;
369 + case AP_MPMQ_MPM_STATE:
370 + *result = mpm_state;
371 + return APR_SUCCESS;
372 + }
373 + return APR_ENOTIMPL;
374 +}
375 +
376 +#if defined(NEED_WAITPID)
377 +/*
378 + Systems without a real waitpid sometimes lose a child's exit while waiting
379 + for another. Search through the scoreboard for missing children.
380 + */
381 +int reap_children(int *exitcode, apr_exit_why_e *status)
382 +{
383 + int n, pid;
384 +
385 + for (n = 0; n < ap_max_daemons_limit; ++n) {
386 + if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD &&
387 + kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) {
388 + ap_update_child_status_from_indexes(n, 0, SERVER_DEAD, NULL);
389 + /* just mark it as having a successful exit status */
390 + *status = APR_PROC_EXIT;
391 + *exitcode = 0;
392 + return(pid);
393 + }
394 + }
395 + return 0;
396 +}
397 +#endif
398 +
399 +/*****************************************************************
400 + * Connection structures and accounting...
401 + */
402 +
403 +static void just_die(int sig)
404 +{
405 + clean_child_exit(0);
406 +}
407 +
408 +static void stop_listening(int sig)
409 +{
410 + ap_close_listeners();
411 +
412 + /* For a graceful stop, we want the child to exit when done */
413 + die_now = 1;
414 +}
415 +
416 +/* volatile just in case */
417 +static int volatile shutdown_pending;
418 +static int volatile restart_pending;
419 +static int volatile is_graceful;
420 +
421 +static void sig_term(int sig)
422 +{
423 + if (shutdown_pending == 1) {
424 + /* Um, is this _probably_ not an error, if the user has
425 + * tried to do a shutdown twice quickly, so we won't
426 + * worry about reporting it.
427 + */
428 + return;
429 + }
430 + shutdown_pending = 1;
431 + is_graceful = (sig == AP_SIG_GRACEFUL_STOP);
432 +}
433 +
434 +/* restart() is the signal handler for SIGHUP and AP_SIG_GRACEFUL
435 + * in the parent process, unless running in ONE_PROCESS mode
436 + */
437 +static void restart(int sig)
438 +{
439 + if (restart_pending == 1) {
440 + /* Probably not an error - don't bother reporting it */
441 + return;
442 + }
443 + restart_pending = 1;
444 + is_graceful = (sig == AP_SIG_GRACEFUL);
445 +}
446 +
447 +static void set_signals(void)
448 +{
449 +#ifndef NO_USE_SIGACTION
450 + struct sigaction sa;
451 +#endif
452 +
453 + if (!one_process) {
454 + ap_fatal_signal_setup(ap_server_conf, pconf);
455 + }
456 +
457 +#ifndef NO_USE_SIGACTION
458 + sigemptyset(&sa.sa_mask);
459 + sa.sa_flags = 0;
460 +
461 + sa.sa_handler = sig_term;
462 + if (sigaction(SIGTERM, &sa, NULL) < 0)
463 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
464 +#ifdef AP_SIG_GRACEFUL_STOP
465 + if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0)
466 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
467 + "sigaction(" AP_SIG_GRACEFUL_STOP_STRING ")");
468 +#endif
469 +#ifdef SIGINT
470 + if (sigaction(SIGINT, &sa, NULL) < 0)
471 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
472 +#endif
473 +#ifdef SIGXCPU
474 + sa.sa_handler = SIG_DFL;
475 + if (sigaction(SIGXCPU, &sa, NULL) < 0)
476 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
477 +#endif
478 +#ifdef SIGXFSZ
479 + sa.sa_handler = SIG_DFL;
480 + if (sigaction(SIGXFSZ, &sa, NULL) < 0)
481 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
482 +#endif
483 +#ifdef SIGPIPE
484 + sa.sa_handler = SIG_IGN;
485 + if (sigaction(SIGPIPE, &sa, NULL) < 0)
486 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
487 +#endif
488 +
489 + /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
490 + * processing one
491 + */
492 + sigaddset(&sa.sa_mask, SIGHUP);
493 + sigaddset(&sa.sa_mask, AP_SIG_GRACEFUL);
494 + sa.sa_handler = restart;
495 + if (sigaction(SIGHUP, &sa, NULL) < 0)
496 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
497 + if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0)
498 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
499 +#else
500 + if (!one_process) {
501 +#ifdef SIGXCPU
502 + apr_signal(SIGXCPU, SIG_DFL);
503 +#endif /* SIGXCPU */
504 +#ifdef SIGXFSZ
505 + apr_signal(SIGXFSZ, SIG_DFL);
506 +#endif /* SIGXFSZ */
507 + }
508 +
509 + apr_signal(SIGTERM, sig_term);
510 +#ifdef SIGHUP
511 + apr_signal(SIGHUP, restart);
512 +#endif /* SIGHUP */
513 +#ifdef AP_SIG_GRACEFUL
514 + apr_signal(AP_SIG_GRACEFUL, restart);
515 +#endif /* AP_SIG_GRACEFUL */
516 +#ifdef AP_SIG_GRACEFUL_STOP
517 + apr_signal(AP_SIG_GRACEFUL_STOP, sig_term);
518 +#endif /* AP_SIG_GRACEFUL */
519 +#ifdef SIGPIPE
520 + apr_signal(SIGPIPE, SIG_IGN);
521 +#endif /* SIGPIPE */
522 +
523 +#endif
524 +}
525 +
526 +/*****************************************************************
527 + * Child process main loop.
528 + * The following vars are static to avoid getting clobbered by longjmp();
529 + * they are really private to child_main.
530 + */
531 +
532 +static int requests_this_child;
533 +static int num_listensocks = 0;
534 +
535 +
536 +int ap_graceful_stop_signalled(void)
537 +{
538 + /* not ever called anymore... */
539 + return 0;
540 +}
541 +
542 +
543 +static void child_main(int child_num_arg)
544 +{
545 + apr_pool_t *ptrans;
546 + apr_allocator_t *allocator;
547 + apr_status_t status;
548 + int i;
549 + ap_listen_rec *lr;
550 + apr_pollset_t *pollset;
551 + ap_sb_handle_t *sbh;
552 + apr_bucket_alloc_t *bucket_alloc;
553 +#if HAVE_LIBCAP
554 + cap_t caps;
555 + cap_value_t suidcaps[] = {
556 + CAP_SETUID,
557 + CAP_SETGID
558 + };
559 +#endif
560 +
561 + int last_poll_idx = 0;
562 +
563 + mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
564 + * child initializes
565 + */
566 +
567 + my_child_num = child_num_arg;
568 + ap_my_pid = getpid();
569 + requests_this_child = 0;
570 +
571 + ap_fatal_signal_child_setup(ap_server_conf);
572 +
573 + /* Get a sub context for global allocations in this child, so that
574 + * we can have cleanups occur when the child exits.
575 + */
576 + apr_allocator_create(&allocator);
577 + apr_allocator_max_free_set(allocator, ap_max_mem_free);
578 + apr_pool_create_ex(&pchild, pconf, NULL, allocator);
579 + apr_allocator_owner_set(allocator, pchild);
580 +
581 + apr_pool_create(&ptrans, pchild);
582 + apr_pool_tag(ptrans, "transaction");
583 +
584 + /* needs to be done before we switch UIDs so we have permissions */
585 + ap_reopen_scoreboard(pchild, NULL, 0);
586 + status = apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname, pchild);
587 + if (status != APR_SUCCESS) {
588 + ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf,
589 + "Couldn't initialize cross-process lock in child "
590 + "(%s) (%d)", ap_lock_fname, ap_accept_lock_mech);
591 + clean_child_exit(APEXIT_CHILDFATAL);
592 + }
593 +
594 + ap_run_child_init(pchild, ap_server_conf);
595 +
596 + ap_create_sb_handle(&sbh, pchild, my_child_num, 0);
597 +
598 + (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
599 +
600 + /* Set up the pollfd array */
601 + /* ### check the status */
602 + (void) apr_pollset_create(&pollset, num_listensocks, pchild, 0);
603 +
604 + for (lr = ap_listeners, i = num_listensocks; i--; lr = lr->next) {
605 + apr_pollfd_t pfd = { 0 };
606 +
607 + pfd.desc_type = APR_POLL_SOCKET;
608 + pfd.desc.s = lr->sd;
609 + pfd.reqevents = APR_POLLIN;
610 + pfd.client_data = lr;
611 +
612 + /* ### check the status */
613 + (void) apr_pollset_add(pollset, &pfd);
614 + }
615 +
616 +#if HAVE_LIBCAP
617 + /* Drop as many privileges as we can. We'll still
618 + * access files with uid=0, and we can setuid() to anything, but
619 + * at least there's tons of other evilness (like loading kernel
620 + * modules) we can't do directly. (The setuid() capability will
621 + * go away automatically when we setuid() or exec() -- the former
622 + * is likely to come first.)
623 + */
624 + caps = cap_init();
625 + cap_clear(caps);
626 + cap_set_flag(caps, CAP_PERMITTED, sizeof(suidcaps)/sizeof(cap_value_t), suidcaps, CAP_SET);
627 + cap_set_flag(caps, CAP_EFFECTIVE, sizeof(suidcaps)/sizeof(cap_value_t), suidcaps, CAP_SET);
628 + cap_set_proc(caps);
629 + cap_free(caps);
630 +#endif
631 +
632 + mpm_state = AP_MPMQ_RUNNING;
633 +
634 + bucket_alloc = apr_bucket_alloc_create(pchild);
635 +
636 + while (!die_now) {
637 + conn_rec *current_conn;
638 + void *csd;
639 +
640 + /*
641 + * (Re)initialize this child to a pre-connection state.
642 + */
643 +
644 + apr_pool_clear(ptrans);
645 +
646 + if ((ap_max_requests_per_child > 0
647 + && requests_this_child++ >= ap_max_requests_per_child)) {
648 + clean_child_exit(0);
649 + }
650 +
651 + (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
652 +
653 + /*
654 + * Wait for an acceptable connection to arrive.
655 + */
656 +
657 + /* Lock around "accept", if necessary */
658 + SAFE_ACCEPT(accept_mutex_on());
659 +
660 + if (num_listensocks == 1) {
661 + /* There is only one listener record, so refer to that one. */
662 + lr = ap_listeners;
663 + }
664 + else {
665 + /* multiple listening sockets - need to poll */
666 + for (;;) {
667 + apr_int32_t numdesc;
668 + const apr_pollfd_t *pdesc;
669 +
670 + /* timeout == -1 == wait forever */
671 + status = apr_pollset_poll(pollset, -1, &numdesc, &pdesc);
672 + if (status != APR_SUCCESS) {
673 + if (APR_STATUS_IS_EINTR(status)) {
674 + if (one_process && shutdown_pending) {
675 + return;
676 + }
677 + continue;
678 + }
679 + /* Single Unix documents select as returning errnos
680 + * EBADF, EINTR, and EINVAL... and in none of those
681 + * cases does it make sense to continue. In fact
682 + * on Linux 2.0.x we seem to end up with EFAULT
683 + * occasionally, and we'd loop forever due to it.
684 + */
685 + ap_log_error(APLOG_MARK, APLOG_ERR, status,
686 + ap_server_conf, "apr_pollset_poll: (listen)");
687 + clean_child_exit(1);
688 + }
689 +
690 + /* We can always use pdesc[0], but sockets at position N
691 + * could end up completely starved of attention in a very
692 + * busy server. Therefore, we round-robin across the
693 + * returned set of descriptors. While it is possible that
694 + * the returned set of descriptors might flip around and
695 + * continue to starve some sockets, we happen to know the
696 + * internal pollset implementation retains ordering
697 + * stability of the sockets. Thus, the round-robin should
698 + * ensure that a socket will eventually be serviced.
699 + */
700 + if (last_poll_idx >= numdesc)
701 + last_poll_idx = 0;
702 +
703 + /* Grab a listener record from the client_data of the poll
704 + * descriptor, and advance our saved index to round-robin
705 + * the next fetch.
706 + *
707 + * ### hmm... this descriptor might have POLLERR rather
708 + * ### than POLLIN
709 + */
710 + lr = pdesc[last_poll_idx++].client_data;
711 + goto got_fd;
712 + }
713 + }
714 + got_fd:
715 + /* if we accept() something we don't want to die, so we have to
716 + * defer the exit
717 + */
718 + status = lr->accept_func(&csd, lr, ptrans);
719 +
720 + SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
721 +
722 + if (status == APR_EGENERAL) {
723 + /* resource shortage or should-not-occur occured */
724 + clean_child_exit(1);
725 + }
726 + else if (status != APR_SUCCESS) {
727 + continue;
728 + }
729 +
730 + /*
731 + * We now have a connection, so set it up with the appropriate
732 + * socket options, file descriptors, and read/write buffers.
733 + */
734 + {
735 + pid_t pid = fork();
736 + int status;
737 + switch (pid) {
738 + case -1:
739 + ap_log_error(APLOG_MARK, APLOG_ERR, errno, NULL, "fork: Unable to fork new process");
740 + break;
741 + case 0: /* child */
742 + apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname, pchild);
743 + current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num, sbh, bucket_alloc);
744 + if (current_conn) {
745 + ap_process_connection(current_conn, csd);
746 + ap_lingering_close(current_conn);
747 + }
748 + exit(0);
749 + default: /* parent; just wait for child to be done */
750 + if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) {
751 + if (WIFSIGNALED(status)) {
752 + ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, "child died with signal %u", WTERMSIG(status));
753 + } else if (WEXITSTATUS(status) != 0) {
754 + ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, "child exited with non-zero exit status %u", WEXITSTATUS(status));
755 + } else {
756 + ap_log_error(APLOG_MARK, APLOG_ERR, errno, NULL, "waitpid() failed");
757 + }
758 + clean_child_exit(1);
759 + }
760 + break;
761 + }
762 + }
763 +
764 + /* Check the pod and the generation number after processing a
765 + * connection so that we'll go away if a graceful restart occurred
766 + * while we were processing the connection or we are the lucky
767 + * idle server process that gets to die.
768 + */
769 + if (ap_mpm_pod_check(pod) == APR_SUCCESS) { /* selected as idle? */
770 + die_now = 1;
771 + }
772 + else if (ap_my_generation !=
773 + ap_scoreboard_image->global->running_generation) { /* restart? */
774 + /* yeah, this could be non-graceful restart, in which case the
775 + * parent will kill us soon enough, but why bother checking?
776 + */
777 + die_now = 1;
778 + }
779 +
780 + /* if we have already setuid(), die (we can't be used anyhow) */
781 + if (getuid())
782 + die_now = 1;
783 + }
784 + clean_child_exit(0);
785 +}
786 +
787 +
788 +static int make_child(server_rec *s, int slot)
789 +{
790 + int pid;
791 +
792 + if (slot + 1 > ap_max_daemons_limit) {
793 + ap_max_daemons_limit = slot + 1;
794 + }
795 +
796 + if (one_process) {
797 + apr_signal(SIGHUP, sig_term);
798 + /* Don't catch AP_SIG_GRACEFUL in ONE_PROCESS mode :) */
799 + apr_signal(SIGINT, sig_term);
800 +#ifdef SIGQUIT
801 + apr_signal(SIGQUIT, SIG_DFL);
802 +#endif
803 + apr_signal(SIGTERM, sig_term);
804 + child_main(slot);
805 + return 0;
806 + }
807 +
808 + (void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING,
809 + (request_rec *) NULL);
810 +
811 +
812 +#ifdef _OSD_POSIX
813 + /* BS2000 requires a "special" version of fork() before a setuid() call */
814 + if ((pid = os_fork(unixd_config.user_name)) == -1) {
815 +#elif defined(TPF)
816 + if ((pid = os_fork(s, slot)) == -1) {
817 +#else
818 + if ((pid = fork()) == -1) {
819 +#endif
820 + ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "fork: Unable to fork new process");
821 +
822 + /* fork didn't succeed. Fix the scoreboard or else
823 + * it will say SERVER_STARTING forever and ever
824 + */
825 + (void) ap_update_child_status_from_indexes(slot, 0, SERVER_DEAD,
826 + (request_rec *) NULL);
827 +
828 + /* In case system resources are maxxed out, we don't want
829 + * Apache running away with the CPU trying to fork over and
830 + * over and over again.
831 + */
832 + sleep(10);
833 +
834 + return -1;
835 + }
836 +
837 + if (!pid) {
838 +#ifdef HAVE_BINDPROCESSOR
839 + /* by default AIX binds to a single processor
840 + * this bit unbinds children which will then bind to another cpu
841 + */
842 + int status = bindprocessor(BINDPROCESS, (int)getpid(),
843 + PROCESSOR_CLASS_ANY);
844 + if (status != OK) {
845 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
846 + ap_server_conf, "processor unbind failed %d", status);
847 + }
848 +#endif
849 + RAISE_SIGSTOP(MAKE_CHILD);
850 + AP_MONCONTROL(1);
851 + /* Disable the parent's signal handlers and set up proper handling in
852 + * the child.
853 + */
854 + apr_signal(SIGHUP, just_die);
855 + apr_signal(SIGTERM, just_die);
856 + /* The child process just closes listeners on AP_SIG_GRACEFUL.
857 + * The pod is used for signalling the graceful restart.
858 + */
859 + apr_signal(AP_SIG_GRACEFUL, stop_listening);
860 + child_main(slot);
861 + }
862 +
863 + ap_scoreboard_image->parent[slot].pid = pid;
864 +
865 + return 0;
866 +}
867 +
868 +
869 +/* start up a bunch of children */
870 +static void startup_children(int number_to_start)
871 +{
872 + int i;
873 +
874 + for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
875 + if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
876 + continue;
877 + }
878 + if (make_child(ap_server_conf, i) < 0) {
879 + break;
880 + }
881 + --number_to_start;
882 + }
883 +}
884 +
885 +
886 +/*
887 + * idle_spawn_rate is the number of children that will be spawned on the
888 + * next maintenance cycle if there aren't enough idle servers. It is
889 + * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
890 + * without the need to spawn.
891 + */
892 +static int idle_spawn_rate = 1;
893 +#ifndef MAX_SPAWN_RATE
894 +#define MAX_SPAWN_RATE (32)
895 +#endif
896 +static int hold_off_on_exponential_spawning;
897 +
898 +static void perform_idle_server_maintenance(apr_pool_t *p)
899 +{
900 + int i;
901 + int to_kill;
902 + int idle_count;
903 + worker_score *ws;
904 + int free_length;
905 + int free_slots[MAX_SPAWN_RATE];
906 + int last_non_dead;
907 + int total_non_dead;
908 +
909 + /* initialize the free_list */
910 + free_length = 0;
911 +
912 + to_kill = -1;
913 + idle_count = 0;
914 + last_non_dead = -1;
915 + total_non_dead = 0;
916 +
917 + for (i = 0; i < ap_daemons_limit; ++i) {
918 + int status;
919 +
920 + if (i >= ap_max_daemons_limit && free_length == idle_spawn_rate)
921 + break;
922 + ws = &ap_scoreboard_image->servers[i][0];
923 + status = ws->status;
924 + if (status == SERVER_DEAD) {
925 + /* try to keep children numbers as low as possible */
926 + if (free_length < idle_spawn_rate) {
927 + free_slots[free_length] = i;
928 + ++free_length;
929 + }
930 + }
931 + else {
932 + /* We consider a starting server as idle because we started it
933 + * at least a cycle ago, and if it still hasn't finished starting
934 + * then we're just going to swamp things worse by forking more.
935 + * So we hopefully won't need to fork more if we count it.
936 + * This depends on the ordering of SERVER_READY and SERVER_STARTING.
937 + */
938 + if (status <= SERVER_READY) {
939 + ++ idle_count;
940 + /* always kill the highest numbered child if we have to...
941 + * no really well thought out reason ... other than observing
942 + * the server behaviour under linux where lower numbered children
943 + * tend to service more hits (and hence are more likely to have
944 + * their data in cpu caches).
945 + */
946 + to_kill = i;
947 + }
948 +
949 + ++total_non_dead;
950 + last_non_dead = i;
951 + }
952 + }
953 + ap_max_daemons_limit = last_non_dead + 1;
954 + if (idle_count > ap_daemons_max_free) {
955 + /* kill off one child... we use the pod because that'll cause it to
956 + * shut down gracefully, in case it happened to pick up a request
957 + * while we were counting
958 + */
959 + ap_mpm_pod_signal(pod);
960 + idle_spawn_rate = 1;
961 + }
962 + else if (idle_count < ap_daemons_min_free) {
963 + /* terminate the free list */
964 + if (free_length == 0) {
965 + /* only report this condition once */
966 + static int reported = 0;
967 +
968 + if (!reported) {
969 + ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
970 + "server reached MaxClients setting, consider"
971 + " raising the MaxClients setting");
972 + reported = 1;
973 + }
974 + idle_spawn_rate = 1;
975 + }
976 + else {
977 + if (idle_spawn_rate >= 8) {
978 + ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
979 + "server seems busy, (you may need "
980 + "to increase StartServers, or Min/MaxSpareServers), "
981 + "spawning %d children, there are %d idle, and "
982 + "%d total children", idle_spawn_rate,
983 + idle_count, total_non_dead);
984 + }
985 + for (i = 0; i < free_length; ++i) {
986 +#ifdef TPF
987 + if (make_child(ap_server_conf, free_slots[i]) == -1) {
988 + if(free_length == 1) {
989 + shutdown_pending = 1;
990 + ap_log_error(APLOG_MARK, APLOG_EMERG, 0, ap_server_conf,
991 + "No active child processes: shutting down");
992 + }
993 + }
994 +#else
995 + make_child(ap_server_conf, free_slots[i]);
996 +#endif /* TPF */
997 + }
998 + /* the next time around we want to spawn twice as many if this
999 + * wasn't good enough, but not if we've just done a graceful
1000 + */
1001 + if (hold_off_on_exponential_spawning) {
1002 + --hold_off_on_exponential_spawning;
1003 + }
1004 + else if (idle_spawn_rate < MAX_SPAWN_RATE) {
1005 + idle_spawn_rate *= 2;
1006 + }
1007 + }
1008 + }
1009 + else {
1010 + idle_spawn_rate = 1;
1011 + }
1012 +}
1013 +
1014 +/*****************************************************************
1015 + * Executive routines.
1016 + */
1017 +
1018 +int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
1019 +{
1020 + int index;
1021 + int remaining_children_to_start;
1022 + apr_status_t rv;
1023 +
1024 + ap_log_pid(pconf, ap_pid_fname);
1025 +
1026 + first_server_limit = server_limit;
1027 + if (changed_limit_at_restart) {
1028 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1029 + "WARNING: Attempt to change ServerLimit "
1030 + "ignored during restart");
1031 + changed_limit_at_restart = 0;
1032 + }
1033 +
1034 + /* Initialize cross-process accept lock */
1035 + ap_lock_fname = apr_psprintf(_pconf, "%s.%" APR_PID_T_FMT,
1036 + ap_server_root_relative(_pconf, ap_lock_fname),
1037 + ap_my_pid);
1038 +
1039 + rv = apr_proc_mutex_create(&accept_mutex, ap_lock_fname,
1040 + ap_accept_lock_mech, _pconf);
1041 + if (rv != APR_SUCCESS) {
1042 + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
1043 + "Couldn't create accept lock (%s) (%d)",
1044 + ap_lock_fname, ap_accept_lock_mech);
1045 + mpm_state = AP_MPMQ_STOPPING;
1046 + return 1;
1047 + }
1048 +
1049 +#if APR_USE_SYSVSEM_SERIALIZE
1050 + if (ap_accept_lock_mech == APR_LOCK_DEFAULT ||
1051 + ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
1052 +#else
1053 + if (ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
1054 +#endif
1055 + rv = unixd_set_proc_mutex_perms(accept_mutex);
1056 + if (rv != APR_SUCCESS) {
1057 + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
1058 + "Couldn't set permissions on cross-process lock; "
1059 + "check User and Group directives");
1060 + mpm_state = AP_MPMQ_STOPPING;
1061 + return 1;
1062 + }
1063 + }
1064 +
1065 + if (!is_graceful) {
1066 + if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
1067 + mpm_state = AP_MPMQ_STOPPING;
1068 + return 1;
1069 + }
1070 + /* fix the generation number in the global score; we just got a new,
1071 + * cleared scoreboard
1072 + */
1073 + ap_scoreboard_image->global->running_generation = ap_my_generation;
1074 + }
1075 +
1076 + set_signals();
1077 +
1078 + if (one_process) {
1079 + AP_MONCONTROL(1);
1080 + make_child(ap_server_conf, 0);
1081 + }
1082 + else {
1083 + if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
1084 + ap_daemons_max_free = ap_daemons_min_free + 1;
1085 +
1086 + /* If we're doing a graceful_restart then we're going to see a lot
1087 + * of children exiting immediately when we get into the main loop
1088 + * below (because we just sent them AP_SIG_GRACEFUL). This happens pretty
1089 + * rapidly... and for each one that exits we'll start a new one until
1090 + * we reach at least daemons_min_free. But we may be permitted to
1091 + * start more than that, so we'll just keep track of how many we're
1092 + * supposed to start up without the 1 second penalty between each fork.
1093 + */
1094 + remaining_children_to_start = ap_daemons_to_start;
1095 + if (remaining_children_to_start > ap_daemons_limit) {
1096 + remaining_children_to_start = ap_daemons_limit;
1097 + }
1098 + if (!is_graceful) {
1099 + startup_children(remaining_children_to_start);
1100 + remaining_children_to_start = 0;
1101 + }
1102 + else {
1103 + /* give the system some time to recover before kicking into
1104 + * exponential mode
1105 + */
1106 + hold_off_on_exponential_spawning = 10;
1107 + }
1108 +
1109 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1110 + "%s configured -- resuming normal operations",
1111 + ap_get_server_version());
1112 + ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
1113 + "Server built: %s", ap_get_server_built());
1114 +#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
1115 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1116 + "AcceptMutex: %s (default: %s)",
1117 + apr_proc_mutex_name(accept_mutex),
1118 + apr_proc_mutex_defname());
1119 +#endif
1120 + restart_pending = shutdown_pending = 0;
1121 +
1122 + mpm_state = AP_MPMQ_RUNNING;
1123 +
1124 + while (!restart_pending && !shutdown_pending) {
1125 + int child_slot;
1126 + apr_exit_why_e exitwhy;
1127 + int status, processed_status;
1128 + /* this is a memory leak, but I'll fix it later. */
1129 + apr_proc_t pid;
1130 +
1131 + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
1132 +
1133 + /* XXX: if it takes longer than 1 second for all our children
1134 + * to start up and get into IDLE state then we may spawn an
1135 + * extra child
1136 + */
1137 + if (pid.pid != -1) {
1138 + processed_status = ap_process_child_status(&pid, exitwhy, status);
1139 + if (processed_status == APEXIT_CHILDFATAL) {
1140 + mpm_state = AP_MPMQ_STOPPING;
1141 + return 1;
1142 + }
1143 +
1144 + /* non-fatal death... note that it's gone in the scoreboard. */
1145 + child_slot = find_child_by_pid(&pid);
1146 + if (child_slot >= 0) {
1147 + (void) ap_update_child_status_from_indexes(child_slot, 0, SERVER_DEAD,
1148 + (request_rec *) NULL);
1149 + if (processed_status == APEXIT_CHILDSICK) {
1150 + /* child detected a resource shortage (E[NM]FILE, ENOBUFS, etc)
1151 + * cut the fork rate to the minimum
1152 + */
1153 + idle_spawn_rate = 1;
1154 + }
1155 + else if (remaining_children_to_start
1156 + && child_slot < ap_daemons_limit) {
1157 + /* we're still doing a 1-for-1 replacement of dead
1158 + * children with new children
1159 + */
1160 + make_child(ap_server_conf, child_slot);
1161 + --remaining_children_to_start;
1162 + }
1163 +#if APR_HAS_OTHER_CHILD
1164 + }
1165 + else if (apr_proc_other_child_alert(&pid, APR_OC_REASON_DEATH, status) == APR_SUCCESS) {
1166 + /* handled */
1167 +#endif
1168 + }
1169 + else if (is_graceful) {
1170 + /* Great, we've probably just lost a slot in the
1171 + * scoreboard. Somehow we don't know about this
1172 + * child.
1173 + */
1174 + ap_log_error(APLOG_MARK, APLOG_WARNING,
1175 + 0, ap_server_conf,
1176 + "long lost child came home! (pid %ld)", (long)pid.pid);
1177 + }
1178 + /* Don't perform idle maintenance when a child dies,
1179 + * only do it when there's a timeout. Remember only a
1180 + * finite number of children can die, and it's pretty
1181 + * pathological for a lot to die suddenly.
1182 + */
1183 + continue;
1184 + }
1185 + else if (remaining_children_to_start) {
1186 + /* we hit a 1 second timeout in which none of the previous
1187 + * generation of children needed to be reaped... so assume
1188 + * they're all done, and pick up the slack if any is left.
1189 + */
1190 + startup_children(remaining_children_to_start);
1191 + remaining_children_to_start = 0;
1192 + /* In any event we really shouldn't do the code below because
1193 + * few of the servers we just started are in the IDLE state
1194 + * yet, so we'd mistakenly create an extra server.
1195 + */
1196 + continue;
1197 + }
1198 +
1199 + perform_idle_server_maintenance(pconf);
1200 +#ifdef TPF
1201 + shutdown_pending = os_check_server(tpf_server_name);
1202 + ap_check_signals();
1203 + sleep(1);
1204 +#endif /*TPF */
1205 + }
1206 + } /* one_process */
1207 +
1208 + mpm_state = AP_MPMQ_STOPPING;
1209 +
1210 + if (shutdown_pending && !is_graceful) {
1211 + /* Time to shut down:
1212 + * Kill child processes, tell them to call child_exit, etc...
1213 + */
1214 + if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
1215 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
1216 + }
1217 + ap_reclaim_child_processes(1); /* Start with SIGTERM */
1218 +
1219 + /* cleanup pid file on normal shutdown */
1220 + {
1221 + const char *pidfile = NULL;
1222 + pidfile = ap_server_root_relative (pconf, ap_pid_fname);
1223 + if ( pidfile != NULL && unlink(pidfile) == 0)
1224 + ap_log_error(APLOG_MARK, APLOG_INFO,
1225 + 0, ap_server_conf,
1226 + "removed PID file %s (pid=%ld)",
1227 + pidfile, (long)getpid());
1228 + }
1229 +
1230 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1231 + "caught SIGTERM, shutting down");
1232 +
1233 + return 1;
1234 + } else if (shutdown_pending) {
1235 + /* Time to perform a graceful shut down:
1236 + * Reap the inactive children, and ask the active ones
1237 + * to close their listeners, then wait until they are
1238 + * all done to exit.
1239 + */
1240 + int active_children;
1241 + apr_time_t cutoff = 0;
1242 +
1243 + /* Stop listening */
1244 + ap_close_listeners();
1245 +
1246 + /* kill off the idle ones */
1247 + ap_mpm_pod_killpg(pod, ap_max_daemons_limit);
1248 +
1249 + /* Send SIGUSR1 to the active children */
1250 + active_children = 0;
1251 + for (index = 0; index < ap_daemons_limit; ++index) {
1252 + if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
1253 + /* Ask each child to close its listeners. */
1254 + kill(MPM_CHILD_PID(index), AP_SIG_GRACEFUL);
1255 + active_children++;
1256 + }
1257 + }
1258 +
1259 + /* Allow each child which actually finished to exit */
1260 + ap_relieve_child_processes();
1261 +
1262 + /* cleanup pid file */
1263 + {
1264 + const char *pidfile = NULL;
1265 + pidfile = ap_server_root_relative (pconf, ap_pid_fname);
1266 + if ( pidfile != NULL && unlink(pidfile) == 0)
1267 + ap_log_error(APLOG_MARK, APLOG_INFO,
1268 + 0, ap_server_conf,
1269 + "removed PID file %s (pid=%ld)",
1270 + pidfile, (long)getpid());
1271 + }
1272 +
1273 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1274 + "caught " AP_SIG_GRACEFUL_STOP_STRING ", shutting down gracefully");
1275 +
1276 + if (ap_graceful_shutdown_timeout) {
1277 + cutoff = apr_time_now() +
1278 + apr_time_from_sec(ap_graceful_shutdown_timeout);
1279 + }
1280 +
1281 + /* Don't really exit until each child has finished */
1282 + shutdown_pending = 0;
1283 + do {
1284 + /* Pause for a second */
1285 + sleep(1);
1286 +
1287 + /* Relieve any children which have now exited */
1288 + ap_relieve_child_processes();
1289 +
1290 + active_children = 0;
1291 + for (index = 0; index < ap_daemons_limit; ++index) {
1292 + if (MPM_CHILD_PID(index) != 0) {
1293 + if (kill(MPM_CHILD_PID(index), 0) == 0) {
1294 + active_children = 1;
1295 + /* Having just one child is enough to stay around */
1296 + break;
1297 + }
1298 + }
1299 + }
1300 + } while (!shutdown_pending && active_children &&
1301 + (!ap_graceful_shutdown_timeout || apr_time_now() < cutoff));
1302 +
1303 + /* We might be here because we received SIGTERM, either
1304 + * way, try and make sure that all of our processes are
1305 + * really dead.
1306 + */
1307 + unixd_killpg(getpgrp(), SIGTERM);
1308 +
1309 + return 1;
1310 + }
1311 +
1312 + /* we've been told to restart */
1313 + apr_signal(SIGHUP, SIG_IGN);
1314 + apr_signal(AP_SIG_GRACEFUL, SIG_IGN);
1315 + if (one_process) {
1316 + /* not worth thinking about */
1317 + return 1;
1318 + }
1319 +
1320 + /* advance to the next generation */
1321 + /* XXX: we really need to make sure this new generation number isn't in
1322 + * use by any of the children.
1323 + */
1324 + ++ap_my_generation;
1325 + ap_scoreboard_image->global->running_generation = ap_my_generation;
1326 +
1327 + if (is_graceful) {
1328 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1329 + "Graceful restart requested, doing restart");
1330 +
1331 + /* kill off the idle ones */
1332 + ap_mpm_pod_killpg(pod, ap_max_daemons_limit);
1333 +
1334 + /* This is mostly for debugging... so that we know what is still
1335 + * gracefully dealing with existing request. This will break
1336 + * in a very nasty way if we ever have the scoreboard totally
1337 + * file-based (no shared memory)
1338 + */
1339 + for (index = 0; index < ap_daemons_limit; ++index) {
1340 + if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
1341 + ap_scoreboard_image->servers[index][0].status = SERVER_GRACEFUL;
1342 + /* Ask each child to close its listeners.
1343 + *
1344 + * NOTE: we use the scoreboard, because if we send SIGUSR1
1345 + * to every process in the group, this may include CGI's,
1346 + * piped loggers, etc. They almost certainly won't handle
1347 + * it gracefully.
1348 + */
1349 + kill(ap_scoreboard_image->parent[index].pid, AP_SIG_GRACEFUL);
1350 + }
1351 + }
1352 + }
1353 + else {
1354 + /* Kill 'em off */
1355 + if (unixd_killpg(getpgrp(), SIGHUP) < 0) {
1356 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
1357 + }
1358 + ap_reclaim_child_processes(0); /* Not when just starting up */
1359 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1360 + "SIGHUP received. Attempting to restart");
1361 + }
1362 +
1363 + return 0;
1364 +}
1365 +
1366 +/* This really should be a post_config hook, but the error log is already
1367 + * redirected by that point, so we need to do this in the open_logs phase.
1368 + */
1369 +static int itk_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
1370 +{
1371 + apr_status_t rv;
1372 +
1373 + pconf = p;
1374 + ap_server_conf = s;
1375 +
1376 + if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) {
1377 + ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0,
1378 + NULL, "no listening sockets available, shutting down");
1379 + return DONE;
1380 + }
1381 +
1382 + if ((rv = ap_mpm_pod_open(pconf, &pod))) {
1383 + ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL,
1384 + "Could not open pipe-of-death.");
1385 + return DONE;
1386 + }
1387 + return OK;
1388 +}
1389 +
1390 +static int itk_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
1391 +{
1392 + static int restart_num = 0;
1393 + int no_detach, debug, foreground;
1394 + apr_status_t rv;
1395 +
1396 + mpm_state = AP_MPMQ_STARTING;
1397 +
1398 + debug = ap_exists_config_define("DEBUG");
1399 +
1400 + if (debug) {
1401 + foreground = one_process = 1;
1402 + no_detach = 0;
1403 + }
1404 + else
1405 + {
1406 + no_detach = ap_exists_config_define("NO_DETACH");
1407 + one_process = ap_exists_config_define("ONE_PROCESS");
1408 + foreground = ap_exists_config_define("FOREGROUND");
1409 + }
1410 +
1411 + /* sigh, want this only the second time around */
1412 + if (restart_num++ == 1) {
1413 + is_graceful = 0;
1414 +
1415 + if (!one_process && !foreground) {
1416 + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND
1417 + : APR_PROC_DETACH_DAEMONIZE);
1418 + if (rv != APR_SUCCESS) {
1419 + ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
1420 + "apr_proc_detach failed");
1421 + return HTTP_INTERNAL_SERVER_ERROR;
1422 + }
1423 + }
1424 +
1425 + parent_pid = ap_my_pid = getpid();
1426 + }
1427 +
1428 + unixd_pre_config(ptemp);
1429 + ap_listen_pre_config();
1430 + ap_daemons_to_start = DEFAULT_START_DAEMON;
1431 + ap_daemons_min_free = DEFAULT_MIN_FREE_DAEMON;
1432 + ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
1433 + ap_daemons_limit = server_limit;
1434 + ap_pid_fname = DEFAULT_PIDLOG;
1435 + ap_lock_fname = DEFAULT_LOCKFILE;
1436 + ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
1437 + ap_extended_status = 0;
1438 +#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
1439 + ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
1440 +#endif
1441 +
1442 + apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
1443 +
1444 + return OK;
1445 +}
1446 +
1447 +static int itk_post_read(request_rec *r)
1448 +{
1449 + uid_t wanted_uid;
1450 + gid_t wanted_gid;
1451 + const char *wanted_username;
1452 +
1453 + itk_server_conf *sconf =
1454 + (itk_server_conf *) ap_get_module_config(r->server->module_config, &mpm_itk_module);
1455 +
1456 + /* Enforce MaxClientsVhost. */
1457 + if (sconf->max_clients_vhost > 0) {
1458 + int i, num_other_servers = 0;
1459 + for (i = 0; i < ap_daemons_limit; ++i) {
1460 + worker_score *ws = &ap_scoreboard_image->servers[i][0];
1461 + if (ws->status >= SERVER_BUSY_READ && strncmp(ws->vhost, r->server->server_hostname, 31) == 0)
1462 + ++num_other_servers;
1463 + }
1464 +
1465 + if (num_other_servers > sconf->max_clients_vhost) {
1466 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, \
1467 + "MaxClientsVhost reached for %s, refusing client.",
1468 + r->server->server_hostname);
1469 + return HTTP_SERVICE_UNAVAILABLE;
1470 + }
1471 + }
1472 +
1473 + strncpy(ap_scoreboard_image->servers[my_child_num][0].vhost, r->server->server_hostname, 31);
1474 + ap_scoreboard_image->servers[my_child_num][0].vhost[31] = 0;
1475 +
1476 + wanted_uid = sconf->uid;
1477 + wanted_gid = sconf->gid;
1478 + wanted_username = sconf->username;
1479 +
1480 + if (wanted_uid == -1 || wanted_gid == -1) {
1481 + wanted_uid = unixd_config.user_id;
1482 + wanted_gid = unixd_config.group_id;
1483 + wanted_username = unixd_config.user_name;
1484 + }
1485 +
1486 + if (wanted_uid != -1 && wanted_gid != -1 && (getuid() != wanted_uid || getgid() != wanted_gid)) {
1487 + int err = 0;
1488 + if (setgid(wanted_gid)) {
1489 + _DBG("setgid(): %s", strerror(errno));
1490 + err = 1;
1491 + } else if (initgroups(wanted_username, wanted_gid)) {
1492 + _DBG("initgroups(): %s", strerror(errno));
1493 + err = 1;
1494 + } else if (setuid(wanted_uid)) {
1495 + _DBG("setuid(): %s", strerror(errno));
1496 + err = 1;
1497 + }
1498 +
1499 + /*
1500 + * Most likely a case of switching uid/gid within a persistent
1501 + * connection; the RFCs allow us to just close the connection
1502 + * at anytime, so we excercise our right. :-)
1503 + */
1504 + if (err) {
1505 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, \
1506 + "Couldn't set uid/gid, closing connection.");
1507 + ap_lingering_close(r->connection);
1508 + exit(0);
1509 + }
1510 + }
1511 + return OK;
1512 +}
1513 +
1514 +static void itk_hooks(apr_pool_t *p)
1515 +{
1516 + /* The itk open_logs phase must run before the core's, or stderr
1517 + * will be redirected to a file, and the messages won't print to the
1518 + * console.
1519 + */
1520 + static const char *const aszSucc[] = {"core.c", NULL};
1521 +
1522 +#ifdef AUX3
1523 + (void) set42sig();
1524 +#endif
1525 +
1526 + ap_hook_open_logs(itk_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
1527 + /* we need to set the MPM state before other pre-config hooks use MPM query
1528 + * to retrieve it, so register as REALLY_FIRST
1529 + */
1530 + ap_hook_pre_config(itk_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
1531 +
1532 + /* set the uid as fast as possible */
1533 + ap_hook_post_read_request(itk_post_read, NULL, NULL, APR_HOOK_REALLY_FIRST);
1534 +}
1535 +
1536 +static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
1537 +{
1538 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1539 + if (err != NULL) {
1540 + return err;
1541 + }
1542 +
1543 + ap_daemons_to_start = atoi(arg);
1544 + return NULL;
1545 +}
1546 +
1547 +static const char *set_min_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
1548 +{
1549 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1550 + if (err != NULL) {
1551 + return err;
1552 + }
1553 +
1554 + ap_daemons_min_free = atoi(arg);
1555 + if (ap_daemons_min_free <= 0) {
1556 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1557 + "WARNING: detected MinSpareServers set to non-positive.");
1558 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1559 + "Resetting to 1 to avoid almost certain Apache failure.");
1560 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1561 + "Please read the documentation.");
1562 + ap_daemons_min_free = 1;
1563 + }
1564 +
1565 + return NULL;
1566 +}
1567 +
1568 +static const char *set_max_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
1569 +{
1570 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1571 + if (err != NULL) {
1572 + return err;
1573 + }
1574 +
1575 + ap_daemons_max_free = atoi(arg);
1576 + return NULL;
1577 +}
1578 +
1579 +static const char *set_max_clients (cmd_parms *cmd, void *dummy, const char *arg)
1580 +{
1581 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1582 + if (err != NULL) {
1583 + return err;
1584 + }
1585 +
1586 + ap_daemons_limit = atoi(arg);
1587 + if (ap_daemons_limit > server_limit) {
1588 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1589 + "WARNING: MaxClients of %d exceeds ServerLimit value "
1590 + "of %d servers,", ap_daemons_limit, server_limit);
1591 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1592 + " lowering MaxClients to %d. To increase, please "
1593 + "see the ServerLimit", server_limit);
1594 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1595 + " directive.");
1596 + ap_daemons_limit = server_limit;
1597 + }
1598 + else if (ap_daemons_limit < 1) {
1599 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1600 + "WARNING: Require MaxClients > 0, setting to 1");
1601 + ap_daemons_limit = 1;
1602 + }
1603 + return NULL;
1604 +}
1605 +
1606 +static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
1607 +{
1608 + int tmp_server_limit;
1609 +
1610 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1611 + if (err != NULL) {
1612 + return err;
1613 + }
1614 +
1615 + tmp_server_limit = atoi(arg);
1616 + /* you cannot change ServerLimit across a restart; ignore
1617 + * any such attempts
1618 + */
1619 + if (first_server_limit &&
1620 + tmp_server_limit != server_limit) {
1621 + /* how do we log a message? the error log is a bit bucket at this
1622 + * point; we'll just have to set a flag so that ap_mpm_run()
1623 + * logs a warning later
1624 + */
1625 + changed_limit_at_restart = 1;
1626 + return NULL;
1627 + }
1628 + server_limit = tmp_server_limit;
1629 +
1630 + if (server_limit > MAX_SERVER_LIMIT) {
1631 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1632 + "WARNING: ServerLimit of %d exceeds compile time limit "
1633 + "of %d servers,", server_limit, MAX_SERVER_LIMIT);
1634 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1635 + " lowering ServerLimit to %d.", MAX_SERVER_LIMIT);
1636 + server_limit = MAX_SERVER_LIMIT;
1637 + }
1638 + else if (server_limit < 1) {
1639 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1640 + "WARNING: Require ServerLimit > 0, setting to 1");
1641 + server_limit = 1;
1642 + }
1643 + return NULL;
1644 +}
1645 +
1646 +static const char *assign_user_id (cmd_parms *cmd, void *dummy, const char *user_name, const char *group_name)
1647 +{
1648 + itk_server_conf *sconf =
1649 + (itk_server_conf *) ap_get_module_config(cmd->server->module_config, &mpm_itk_module);
1650 + sconf->username = strdup(user_name);
1651 + sconf->uid = ap_uname2id(user_name);
1652 + sconf->gid = ap_gname2id(group_name);
1653 + return NULL;
1654 +}
1655 +
1656 +static const char *set_max_clients_vhost (cmd_parms *cmd, void *dummy, const char *arg)
1657 +{
1658 + itk_server_conf *sconf =
1659 + (itk_server_conf *) ap_get_module_config(cmd->server->module_config, &mpm_itk_module);
1660 + sconf->max_clients_vhost = atoi(arg);
1661 + return NULL;
1662 +}
1663 +
1664 +static const command_rec itk_cmds[] = {
1665 +UNIX_DAEMON_COMMANDS,
1666 +LISTEN_COMMANDS,
1667 +AP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF,
1668 + "Number of child processes launched at server startup"),
1669 +AP_INIT_TAKE1("MinSpareServers", set_min_free_servers, NULL, RSRC_CONF,
1670 + "Minimum number of idle children, to handle request spikes"),
1671 +AP_INIT_TAKE1("MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF,
1672 + "Maximum number of idle children"),
1673 +AP_INIT_TAKE1("MaxClients", set_max_clients, NULL, RSRC_CONF,
1674 + "Maximum number of children alive at the same time"),
1675 +AP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF,
1676 + "Maximum value of MaxClients for this run of Apache"),
1677 +AP_INIT_TAKE2("AssignUserID", assign_user_id, NULL, RSRC_CONF,
1678 + "Tie a virtual host to a specific child process."),
1679 +AP_INIT_TAKE1("MaxClientsVHost", set_max_clients_vhost, NULL, RSRC_CONF,
1680 + "Maximum number of children alive at the same time for this virtual host."),
1681 +AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND,
1682 +{ NULL }
1683 +};
1684 +
1685 +/* == allocate a private server config structure == */
1686 +static void *itk_create_config(apr_pool_t *p, server_rec *s)
1687 +{
1688 + itk_server_conf *c = (itk_server_conf *)
1689 + apr_pcalloc(p, sizeof(itk_server_conf));
1690 + c->uid = c->gid = -1;
1691 + c->max_clients_vhost = -1;
1692 + return c;
1693 +}
1694 +
1695 +module AP_MODULE_DECLARE_DATA mpm_itk_module = {
1696 + MPM20_MODULE_STUFF,
1697 + ap_mpm_rewrite_args, /* hook to run before apache parses args */
1698 + NULL, /* create per-directory config structure */
1699 + NULL, /* merge per-directory config structures */
1700 + itk_create_config, /* create per-server config structure */
1701 + NULL, /* merge per-server config structures */
1702 + itk_cmds, /* command apr_table_t */
1703 + itk_hooks, /* register hooks */
1704 +};
1705 Index: httpd-2.2.4/server/mpm/experimental/itk/mpm.h
1706 ===================================================================
1707 --- /dev/null
1708 +++ httpd-2.2.4/server/mpm/experimental/itk/mpm.h
1709 @@ -0,0 +1,65 @@
1710 +/* Licensed to the Apache Software Foundation (ASF) under one or more
1711 + * contributor license agreements. See the NOTICE file distributed with
1712 + * this work for additional information regarding copyright ownership.
1713 + * The ASF licenses this file to You under the Apache License, Version 2.0
1714 + * (the "License"); you may not use this file except in compliance with
1715 + * the License. You may obtain a copy of the License at
1716 + *
1717 + * http://www.apache.org/licenses/LICENSE-2.0
1718 + *
1719 + * Unless required by applicable law or agreed to in writing, software
1720 + * distributed under the License is distributed on an "AS IS" BASIS,
1721 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1722 + * See the License for the specific language governing permissions and
1723 + * limitations under the License.
1724 + *
1725 + * Portions copyright 2005-2006 Steinar H. Gunderson <sgunderson@bigfoot.com>.
1726 + * Licensed under the same terms as the rest of Apache.
1727 + */
1728 +
1729 +/**
1730 + * @file itk/mpm.h
1731 + * @brief ITK MPM (setuid per-vhost, no threads)
1732 + *
1733 + * @defgroup APACHE_MPM_ITK Apache ITK
1734 + * @ingroup APACHE_MPM APACHE_OS_UNIX
1735 + * @{
1736 + */
1737 +
1738 +#include "httpd.h"
1739 +#include "mpm_default.h"
1740 +#include "scoreboard.h"
1741 +#include "unixd.h"
1742 +
1743 +#ifndef APACHE_MPM_ITK_H
1744 +#define APACHE_MPM_ITK_H
1745 +
1746 +#define ITK_MPM
1747 +
1748 +#define MPM_NAME "ITK"
1749 +
1750 +#define AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
1751 +#define AP_MPM_WANT_WAIT_OR_TIMEOUT
1752 +#define AP_MPM_WANT_PROCESS_CHILD_STATUS
1753 +#define AP_MPM_WANT_SET_PIDFILE
1754 +#define AP_MPM_WANT_SET_SCOREBOARD
1755 +#define AP_MPM_WANT_SET_LOCKFILE
1756 +#define AP_MPM_WANT_SET_MAX_REQUESTS
1757 +#define AP_MPM_WANT_SET_COREDUMPDIR
1758 +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
1759 +#define AP_MPM_WANT_SIGNAL_SERVER
1760 +#define AP_MPM_WANT_SET_MAX_MEM_FREE
1761 +#define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
1762 +#define AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN
1763 +#define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
1764 +
1765 +#define AP_MPM_USES_POD 1
1766 +#define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
1767 +#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
1768 +#define MPM_ACCEPT_FUNC unixd_accept
1769 +
1770 +extern int ap_threads_per_child;
1771 +extern int ap_max_daemons_limit;
1772 +extern server_rec *ap_server_conf;
1773 +#endif /* APACHE_MPM_ITK_H */
1774 +/** @} */
1775 Index: httpd-2.2.4/server/mpm/experimental/itk/mpm_default.h
1776 ===================================================================
1777 --- /dev/null
1778 +++ httpd-2.2.4/server/mpm/experimental/itk/mpm_default.h
1779 @@ -0,0 +1,77 @@
1780 +/* Licensed to the Apache Software Foundation (ASF) under one or more
1781 + * contributor license agreements. See the NOTICE file distributed with
1782 + * this work for additional information regarding copyright ownership.
1783 + * The ASF licenses this file to You under the Apache License, Version 2.0
1784 + * (the "License"); you may not use this file except in compliance with
1785 + * the License. You may obtain a copy of the License at
1786 + *
1787 + * http://www.apache.org/licenses/LICENSE-2.0
1788 + *
1789 + * Unless required by applicable law or agreed to in writing, software
1790 + * distributed under the License is distributed on an "AS IS" BASIS,
1791 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1792 + * See the License for the specific language governing permissions and
1793 + * limitations under the License.
1794 + *
1795 + * Portions copyright 2005-2006 Steinar H. Gunderson <sgunderson@bigfoot.com>.
1796 + * Licensed under the same terms as the rest of Apache.
1797 + */
1798 +
1799 +/**
1800 + * @file itk/mpm_default.h
1801 + * @brief Prefork MPM defaults
1802 + *
1803 + * @addtogroup APACHE_MPM_ITK
1804 + * @{
1805 + */
1806 +
1807 +#ifndef APACHE_MPM_DEFAULT_H
1808 +#define APACHE_MPM_DEFAULT_H
1809 +
1810 +/* Number of servers to spawn off by default --- also, if fewer than
1811 + * this free when the caretaker checks, it will spawn more.
1812 + */
1813 +#ifndef DEFAULT_START_DAEMON
1814 +#define DEFAULT_START_DAEMON 5
1815 +#endif
1816 +
1817 +/* Maximum number of *free* server processes --- more than this, and
1818 + * they will die off.
1819 + */
1820 +
1821 +#ifndef DEFAULT_MAX_FREE_DAEMON
1822 +#define DEFAULT_MAX_FREE_DAEMON 10
1823 +#endif
1824 +
1825 +/* Minimum --- fewer than this, and more will be created */
1826 +
1827 +#ifndef DEFAULT_MIN_FREE_DAEMON
1828 +#define DEFAULT_MIN_FREE_DAEMON 5
1829 +#endif
1830 +
1831 +/* File used for accept locking, when we use a file */
1832 +#ifndef DEFAULT_LOCKFILE
1833 +#define DEFAULT_LOCKFILE DEFAULT_REL_RUNTIMEDIR "/accept.lock"
1834 +#endif
1835 +
1836 +/* Where the main/parent process's pid is logged */
1837 +#ifndef DEFAULT_PIDLOG
1838 +#define DEFAULT_PIDLOG DEFAULT_REL_RUNTIMEDIR "/httpd.pid"
1839 +#endif
1840 +
1841 +/*
1842 + * Interval, in microseconds, between scoreboard maintenance.
1843 + */
1844 +#ifndef SCOREBOARD_MAINTENANCE_INTERVAL
1845 +#define SCOREBOARD_MAINTENANCE_INTERVAL 1000000
1846 +#endif
1847 +
1848 +/* Number of requests to try to handle in a single process. If <= 0,
1849 + * the children don't die off.
1850 + */
1851 +#ifndef DEFAULT_MAX_REQUESTS_PER_CHILD
1852 +#define DEFAULT_MAX_REQUESTS_PER_CHILD 10000
1853 +#endif
1854 +
1855 +#endif /* AP_MPM_DEFAULT_H */
1856 +/** @} */

  ViewVC Help
Powered by ViewVC 1.1.20