/[apache]/trunk/dist/2.2/patches/21_all_itk-20070425-00.patch
Gentoo

Contents of /trunk/dist/2.2/patches/21_all_itk-20070425-00.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20