1 diff -Nur httpd-2.0.48/server/mpm/config.m4 httpd-2.0.48-metuxmpm-r8/server/mpm/config.m4
2 --- httpd-2.0.48/server/mpm/config.m4 2003-03-11 00:07:52.000000000 -0700
3 +++ httpd-2.0.48-metuxmpm-r8/server/mpm/config.m4 2004-03-19 10:03:32.132460289 -0700
5 AC_MSG_CHECKING(which MPM to use)
7 APACHE_HELP_STRING(--with-mpm=MPM,Choose the process model for Apache to use.
8 - MPM={beos|worker|prefork|mpmt_os2|perchild|leader|threadpool}),[
9 + MPM={beos|worker|prefork|mpmt_os2|perchild|leader|threadpool|metuxmpm}),[
12 if test "x$APACHE_MPM" = "x"; then
15 apache_cv_mpm=$APACHE_MPM
17 -if test "$apache_cv_mpm" = "worker" -o "$apache_cv_mpm" = "perchild" -o "$apache_cv_mpm" = "leader" -o "$apache_cv_mpm" = "threadpool" ; then
18 +if test "$apache_cv_mpm" = "worker" -o "$apache_cv_mpm" = "perchild" -o "$apache_cv_mpm" = "metuxmpm" -o "$apache_cv_mpm" = "leader" -o "$apache_cv_mpm" = "threadpool" ; then
19 APR_CHECK_APR_DEFINE(APR_HAS_THREADS)
21 if test "x$ac_cv_define_APR_HAS_THREADS" = "xno"; then
23 APACHE_FAST_OUTPUT(server/mpm/Makefile)
25 MPM_NAME=$apache_cv_mpm
26 -if test "$MPM_NAME" = "leader" -o "$MPM_NAME" = "threadpool" -o "$MPM_NAME" = "perchild"; then
27 +if test "$MPM_NAME" = "leader" -o "$MPM_NAME" = "threadpool" -o "$MPM_NAME" = "perchild" -o "$MPM_NAME" = "metuxmpm"; then
28 AC_MSG_WARN(You have selected an EXPERIMENTAL MPM. Be warned!)
29 MPM_SUBDIR_NAME=experimental/$MPM_NAME
31 diff -Nur httpd-2.0.48/server/mpm/experimental/metuxmpm/Makefile.in httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/Makefile.in
32 --- httpd-2.0.48/server/mpm/experimental/metuxmpm/Makefile.in 1969-12-31 17:00:00.000000000 -0700
33 +++ httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/Makefile.in 2004-03-19 10:03:32.132460289 -0700
36 +LTLIBRARY_NAME = libmetuxmpm.la
37 +LTLIBRARY_SOURCES = metuxmpm.c
39 +include $(top_srcdir)/build/ltlib.mk
40 diff -Nur httpd-2.0.48/server/mpm/experimental/metuxmpm/config5.m4 httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/config5.m4
41 --- httpd-2.0.48/server/mpm/experimental/metuxmpm/config5.m4 1969-12-31 17:00:00.000000000 -0700
42 +++ httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/config5.m4 2004-03-19 10:03:32.133460146 -0700
44 +dnl ## XXX - Need a more thorough check of the proper flags to use
46 +if test "$MPM_NAME" = "metuxmpm" ; then
47 + AC_CHECK_FUNCS(pthread_kill)
48 + APACHE_FAST_OUTPUT(server/mpm/$MPM_SUBDIR_NAME/Makefile)
50 diff -Nur httpd-2.0.48/server/mpm/experimental/metuxmpm/metuxmpm.c httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/metuxmpm.c
51 --- httpd-2.0.48/server/mpm/experimental/metuxmpm/metuxmpm.c 1969-12-31 17:00:00.000000000 -0700
52 +++ httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/metuxmpm.c 2004-03-19 10:57:21.869478056 -0700
54 +/* ====================================================================
55 + * The Apache Software License, Version 1.1
57 + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
60 + * Redistribution and use in source and binary forms, with or without
61 + * modification, are permitted provided that the following conditions
64 + * 1. Redistributions of source code must retain the above copyright
65 + * notice, this list of conditions and the following disclaimer.
67 + * 2. Redistributions in binary form must reproduce the above copyright
68 + * notice, this list of conditions and the following disclaimer in
69 + * the documentation and/or other materials provided with the
72 + * 3. The end-user documentation included with the redistribution,
73 + * if any, must include the following acknowledgment:
74 + * "This product includes software developed by the
75 + * Apache Software Foundation (http://www.apache.org/)."
76 + * Alternately, this acknowledgment may appear in the software itself,
77 + * if and wherever such third-party acknowledgments normally appear.
79 + * 4. The names "Apache" and "Apache Software Foundation" must
80 + * not be used to endorse or promote products derived from this
81 + * software without prior written permission. For written
82 + * permission, please contact apache@apache.org.
84 + * 5. Products derived from this software may not be called "Apache",
85 + * nor may "Apache" appear in their name, without prior written
86 + * permission of the Apache Software Foundation.
88 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
90 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
91 + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
92 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
93 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
94 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
95 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
96 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
97 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
98 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 + * ====================================================================
102 + * This software consists of voluntary contributions made by many
103 + * individuals on behalf of the Apache Software Foundation. For more
104 + * information on the Apache Software Foundation, please see
105 + * <http://www.apache.org/>.
107 + * Portions of this software are based upon public domain software
108 + * originally written at the National Center for Supercomputing Applications,
109 + * University of Illinois, Urbana-Champaign.
113 + + replace pipe_of_death by an generic command interface
114 + + also use this interface for child->child communications
115 + + add support for runtime configuration over this if.
116 + + what to do w/ unassigned vhosts ? who should handle them ?
117 + perhaps we shoudda add an DefaultProcessor option ?
118 + + test, test, test, and test, especially under high load.
119 + + what about persistent links w/ changing vhost ?
120 + should the client then give it back to the multiplexer ?
121 + + add timeouts in multiplexer to prevent local dos attacks
122 + + think about possible vulnarabilities. note that the vhost's user
123 + could ptrace the processor child and play nice games with it.
126 +/* -- build configuration -- manly for debugging -- */
128 +/* #define MPM_METUXMPM_DEBUG */
130 +#define MPM_THREAD_ACCEPT_LOCK
132 +#include "apr_hash.h"
133 +#include "apr_strings.h"
134 +#include "apr_pools.h"
135 +#include "apr_portable.h"
136 +#include "apr_file_io.h"
137 +#include "apr_signal.h"
139 +#define APR_WANT_IOVEC
140 +#include "apr_want.h"
142 +#if APR_HAVE_UNISTD_H
145 +#if APR_HAVE_SYS_SOCKET_H
146 +#include <sys/socket.h>
149 +#if !APR_HAS_THREADS
150 +#error The metuxmpm MPM requires APR threads, but they are unavailable.
153 +#define CORE_PRIVATE
155 +#include "ap_config.h"
157 +#include "http_main.h"
158 +#include "http_log.h"
159 +#include "http_config.h" /* for read_config */
160 +#include "http_core.h" /* for get_remote_host */
161 +#include "http_protocol.h"
162 +#include "http_connection.h"
165 +#include "mpm_common.h"
166 +#include "ap_listen.h"
167 +#include "mpm_default.h"
169 +#include "scoreboard.h"
170 +#include "util_filter.h"
171 +#include "apr_poll.h"
173 +#include "util_ebcdic.h"
178 +#ifdef HAVE_SYS_POLL_H
179 +#include <sys/poll.h>
182 +/* ### should be APR-ized */
185 +#include <sys/stat.h>
188 +#ifdef HAVE_SYS_PROCESSOR_H
189 +#include <sys/processor.h> /* for bindprocessor() */
192 +#ifdef MPM_METUXMPM_DEBUG
193 +# define _DBG(text,par...) \
194 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, \
195 + "(metuxmpm: pid=%d uid=%d) %s(): " text, \
196 + getpid(), getuid(), __FUNCTION__, ##par, 0)
198 +# define _TRACE_CALL(text,par...) _DBG("calling " text, ##par)
199 +# define _TRACE_RET(text,par...) _DBG("returned from " text, ##par)
201 +# define _DBG(text,par...)
202 +# define _TRACE_RET(text,par...)
203 +# define _TRACE_CALL(text,par...)
204 +#endif /* MPM_METUXMPM_DEBUG */
206 +/* char of death - for signalling children to die */
207 +#define AP_metuxmpm_CHAR_OF_DEATH '!'
209 +#define metuxmpm_SERVER_CONF(cf) \
210 + ((metuxmpm_server_conf *) ap_get_module_config(cf,&mpm_metuxmpm_module))
214 + * Define some magic numbers that we use for the state of the incomming
215 + * request. These must be < 0 so they don't collide with a file descriptor.
217 +#define AP_metuxmpm_THISCHILD -1
218 +#define AP_metuxmpm_OTHERCHILD -2
220 +/* Limit on the threads per process. Clients will be locked out if more than
221 + * this * server_limit are needed.
223 + * We keep this for one reason it keeps the size of the scoreboard file small
224 + * enough that we can read the whole thing without worrying too much about
227 +#ifndef DEFAULT_THREAD_LIMIT
228 +#define DEFAULT_THREAD_LIMIT 64
231 +/* Admin can't tune ThreadLimit beyond MAX_THREAD_LIMIT. We want
232 + * some sort of compile-time limit to help catch typos.
234 +#ifndef MAX_THREAD_LIMIT
235 +#define MAX_THREAD_LIMIT 20000
238 +/* Limit on the total --- clients will be locked out if more servers than
239 + * this are needed. It is intended solely to keep the server from crashing
240 + * when things get out of hand.
242 + * We keep a hard maximum number of servers, for two reasons --- first off,
243 + * in case something goes seriously wrong, we want to stop the fork bomb
244 + * short of actually crashing the machine we're running on by filling some
245 + * kernel table. Secondly, it keeps the size of the scoreboard file small
246 + * enough that we can read the whole thing without worrying too much about
249 +#ifndef DEFAULT_SERVER_LIMIT
250 +#define DEFAULT_SERVER_LIMIT 256
253 +/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want
254 + * some sort of compile-time limit to help catch typos.
256 +#ifndef MAX_SERVER_LIMIT
257 +#define MAX_SERVER_LIMIT 20000
261 + * Actual definitions of config globals
264 +static int threads_to_start = 0; /* Worker threads per child */
265 +static int min_spare_threads = 0;
266 +static int max_spare_threads = 0;
267 +static int max_threads = 0;
268 +static int server_limit = DEFAULT_SERVER_LIMIT;
269 +static int first_server_limit;
270 +static int thread_limit = DEFAULT_THREAD_LIMIT;
271 +static int first_thread_limit;
272 +static int changed_limit_at_restart;
273 +static int num_childs = 0;
274 +static int workers_may_exit = 0;
275 +static int requests_this_child;
276 +static int num_listensocks = 0;
277 +static ap_pod_t *pod;
278 +static jmp_buf jmpbuffer;
279 +static int thread_overflow_reported = 0;
281 +/* === configuration stuff === */
282 +/* the server limit is also the size of the server table */
283 +static int cf_server_limit = DEFAULT_SERVER_LIMIT;
285 +/* -- server process information -- */
290 + int input; /* The socket descriptor */
291 + int output; /* The socket descriptor */
293 + int id; /* index in child_info_table */
294 + const char *chroot_dir; /* can be null */
297 +#define CHILD_TYPE_MULTIPLEXER 1
298 +#define CHILD_TYPE_PROCESSOR 2
302 + const char *sockname; /* The base name for the socket */
303 + const char *fullsockname; /* socket base name + extension */
304 + child_info_t* child; /* The client which processes this server */
305 +} metuxmpm_server_conf;
314 +/* Tables used to determine the user and group each child process should
315 + * run as. The hash table is used to correlate a server name with a child
318 +static int child_info_table_size;
319 +static child_info_t *child_info_table;
320 +static thread_info_t *thread_info_table;
321 +struct ap_ctable *ap_child_table;
324 + * The max child slot ever assigned, preserved across restarts. Necessary
325 + * to deal with NumServers changes across AP_SIG_GRACEFUL restarts. We
326 + * use this value to optimize routines that have to scan the entire child
329 + * XXX - It might not be worth keeping this code in. There aren't very
330 + * many child processes in this MPM.
332 +int ap_max_daemons_limit = -1;
333 +int ap_threads_per_child; /* XXX not part of API! axe it! */
335 +module AP_MODULE_DECLARE_DATA mpm_metuxmpm_module;
337 +/* -- replace the pipe-of-death by an control socket -- */
338 +static apr_file_t *pipe_of_death_in = NULL;
339 +static apr_file_t *pipe_of_death_out = NULL;
340 +static apr_thread_mutex_t *pipe_of_death_mutex;
342 +/* *Non*-shared http_main globals... */
344 +server_rec *ap_server_conf;
346 +/* one_process --- debugging mode variable; can be set from the command line
347 + * with the -X flag. If set, this gets you the child_main loop running
348 + * in the process which originally started up (no detach, no make_child),
349 + * which is a pretty nice debugging environment. (You'll get a SIGHUP
350 + * early in standalone_main; just continue through. This is the server
351 + * trying to kill off any child processes which it might have lying
352 + * around --- Apache doesn't keep track of their pids, it just sends
353 + * SIGHUP to the process group, ignoring it in the root process.
354 + * Continue through and you'll be fine.).
357 +static int one_process = 0;
359 +#ifdef DEBUG_SIGSTOP
360 +int raise_sigstop_flags;
363 +static apr_pool_t *pconf; /* Pool for config stuff */
364 +static apr_pool_t *pchild; /* Pool for httpd child stuff */
365 +static apr_pool_t *thread_pool_parent; /* Parent of per-thread pools */
366 +static apr_thread_mutex_t *thread_pool_parent_mutex;
368 +static int child_num;
369 +static unsigned int my_pid; /* Linux getpid() doesn't work except in
370 + main thread. Use this instead */
372 +/* -- stack w/ free thread slot IDs */
373 +static int *worker_thread_free_ids;
374 +static apr_threadattr_t *worker_thread_attr;
376 +/* Keep track of the number of idle worker threads */
377 +static int idle_thread_count;
378 +static apr_thread_mutex_t *idle_thread_count_mutex;
380 +/* Locks for accept serialization */
381 +#ifdef NO_SERIALIZED_ACCEPT
383 +#define ACCEPT_PROC_MUTEX_INIT APR_SUCCESS
384 +#define ACCEPT_PROC_MUTEX_LOCK APR_SUCCESS
385 +#define ACCEPT_PROC_MUTEX_UNLOCK APR_SUCCESS
386 +#define ACCEPT_PROC_MUTEX_CREATE APR_SUCCESS
390 +static apr_proc_mutex_t *process_accept_mutex;
392 +#define ACCEPT_PROC_MUTEX_LOCK (apr_proc_mutex_lock(process_accept_mutex))
393 +#define ACCEPT_PROC_MUTEX_UNLOCK (apr_proc_mutex_unlock(process_accept_mutex))
394 +#define ACCEPT_PROC_MUTEX_CREATE (apr_proc_mutex_create(&process_accept_mutex,ap_lock_fname, ap_accept_lock_mech,_pconf))
395 +#define ACCEPT_PROC_MUTEX_INIT (apr_proc_mutex_child_init(&process_accept_mutex, ap_lock_fname, pchild));
397 +#endif /* NO_SERIALIZED_ACCEPT */
399 +static apr_thread_mutex_t *thread_accept_mutex;
401 +#ifdef MPM_metuxmpm_THREAD_ACCEPT_LOCK
403 +#define THREAD_ACCEPT_LOCK \
404 + _DBG("locking thread_accept_mutex",0); \
405 + apr_thread_mutex_lock(thread_accept_mutex); \
406 + _DBG("got thread_accept_mutex locked",0);
408 +#define THREAD_ACCEPT_UNLOCK \
409 + _DBG("unlocking thread_accept_mutex",0); \
410 + apr_thread_mutex_unlock(thread_accept_mutex); \
411 + _DBG("got thread_accept_mutex unlocked",0);
414 +#define THREAD_ACCEPT_LOCK \
415 + _DBG("omitted locking thread_accept_mutex",0);
417 +#define THREAD_ACCEPT_UNLOCK \
418 + _DBG("omitted unlocking thread_accept_mutex",0);
421 +/* == Keep track of the number of worker threads currently active == */
422 +static int worker_thread_count = 0;
423 +static apr_thread_mutex_t *worker_thread_count_mutex;
425 +static inline int worker_thread_count_get ()
428 + apr_thread_mutex_lock(worker_thread_count_mutex);
429 + x = worker_thread_count;
430 + apr_thread_mutex_unlock(worker_thread_count_mutex);
431 + _DBG("worker_thread_count=%d", x);
435 +static inline int worker_thread_count_add ( int x )
438 + apr_thread_mutex_lock(worker_thread_count_mutex);
439 + worker_thread_count += x;
440 + y = worker_thread_count;
441 + apr_thread_mutex_unlock(worker_thread_count_mutex);
442 + _DBG("worker_thread_count=%d (+%d)", y, x);
446 +/* ------------------------------------------------------------------- */
448 +AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
450 + switch(query_code){
451 + case AP_MPMQ_MAX_DAEMON_USED:
452 + *result = ap_max_daemons_limit;
453 + return APR_SUCCESS;
454 + case AP_MPMQ_IS_THREADED:
455 + *result = AP_MPMQ_DYNAMIC;
456 + return APR_SUCCESS;
457 + case AP_MPMQ_IS_FORKED:
458 + *result = AP_MPMQ_STATIC;
459 + return APR_SUCCESS;
460 + case AP_MPMQ_HARD_LIMIT_DAEMONS:
461 + *result = cf_server_limit;
462 + return APR_SUCCESS;
463 + case AP_MPMQ_HARD_LIMIT_THREADS:
464 + *result = thread_limit;
465 + return APR_SUCCESS;
466 + case AP_MPMQ_MAX_THREADS:
467 + *result = max_threads;
468 + return APR_SUCCESS;
469 + case AP_MPMQ_MIN_SPARE_DAEMONS:
471 + return APR_SUCCESS;
472 + case AP_MPMQ_MIN_SPARE_THREADS:
473 + *result = min_spare_threads;
474 + return APR_SUCCESS;
475 + case AP_MPMQ_MAX_SPARE_DAEMONS:
477 + return APR_SUCCESS;
478 + case AP_MPMQ_MAX_SPARE_THREADS:
479 + *result = max_spare_threads;
480 + return APR_SUCCESS;
481 + case AP_MPMQ_MAX_REQUESTS_DAEMON:
482 + *result = ap_max_requests_per_child;
483 + return APR_SUCCESS;
484 + case AP_MPMQ_MAX_DAEMONS:
485 + *result = num_childs;
486 + return APR_SUCCESS;
488 + return APR_ENOTIMPL;
491 +/* a clean exit from a child with proper cleanup */
492 +static inline int clean_child_exit(int code)
494 + if (pchild) apr_pool_destroy(pchild);
498 +/* handle all varieties of core dumping signals */
499 +static void sig_coredump(int sig)
501 + chdir(ap_coredump_dir);
502 + apr_signal(sig, SIG_DFL);
503 + kill(getpid(), sig);
504 + /* At this point we've got sig blocked, because we're still inside
505 + * the signal handler. When we leave the signal handler it will
506 + * be unblocked, and we'll take the signal... and coredump or whatever
507 + * is appropriate for this particular Unix. In addition the parent
508 + * will see the real signal we received -- whereas if we called
509 + * abort() here, the parent would only see SIGABRT.
513 +static void just_die(int sig)
515 + clean_child_exit(0);
518 +/*****************************************************************
519 + * Connection structures and accounting...
522 +/* volatile just in case */
523 +static int volatile shutdown_pending;
524 +static int volatile restart_pending;
525 +static int volatile is_graceful;
526 +static int volatile child_fatal;
527 +/* we don't currently track ap_my_generation, but mod_status
528 + * references it so it must be defined */
529 +ap_generation_t volatile ap_my_generation=0;
532 + * ap_start_shutdown() and ap_start_restart(), below, are a first stab at
533 + * functions to initiate shutdown or restart without relying on signals.
534 + * Previously this was initiated in sig_term() and restart() signal handlers,
535 + * but we want to be able to start a shutdown/restart from other sources --
536 + * e.g. on Win32, from the service manager. Now the service manager can
537 + * call ap_start_shutdown() or ap_start_restart() as appropiate. Note that
538 + * these functions can also be called by the child processes, since global
539 + * variables are no longer used to pass on the required action to the parent.
541 + * These should only be called from the parent process itself, since the
542 + * parent process will use the shutdown_pending and restart_pending variables
543 + * to determine whether to shutdown or restart. The child process should
544 + * call signal_parent() directly to tell the parent to die -- this will
545 + * cause neither of those variable to be set, which the parent will
546 + * assume means something serious is wrong (which it will be, for the
547 + * child to force an exit) and so do an exit anyway.
550 +static void ap_start_shutdown(void)
552 + if (shutdown_pending == 1)
554 + /* Um, is this _probably_ not an error, if the user has
555 + * tried to do a shutdown twice quickly, so we won't
556 + * worry about reporting it.
560 + shutdown_pending = 1;
563 +/* do a graceful restart if graceful == 1 */
564 +static void ap_start_restart(int graceful)
566 + if (restart_pending == 1)
568 + /* Probably not an error - don't bother reporting it */
571 + restart_pending = 1;
572 + is_graceful = graceful;
575 +static void sig_term(int sig)
577 + ap_start_shutdown();
580 +static void restart(int sig)
582 + ap_start_restart(sig == AP_SIG_GRACEFUL);
585 +static void set_signals(void)
587 +#ifndef NO_USE_SIGACTION
588 + struct sigaction sa;
590 + sigemptyset(&sa.sa_mask);
593 + if (!one_process) {
594 + sa.sa_handler = sig_coredump;
595 +#if defined(SA_ONESHOT)
596 + sa.sa_flags = SA_ONESHOT;
597 +#elif defined(SA_RESETHAND)
598 + sa.sa_flags = SA_RESETHAND;
600 + if (sigaction(SIGSEGV, &sa, NULL) < 0)
601 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
602 + "sigaction(SIGSEGV)");
604 + if (sigaction(SIGBUS, &sa, NULL) < 0)
605 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
606 + "sigaction(SIGBUS)");
609 + if (sigaction(SIGABORT, &sa, NULL) < 0)
610 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
611 + "sigaction(SIGABORT)");
614 + if (sigaction(SIGABRT, &sa, NULL) < 0)
615 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
616 + "sigaction(SIGABRT)");
619 + if (sigaction(SIGILL, &sa, NULL) < 0)
620 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
621 + "sigaction(SIGILL)");
625 + sa.sa_handler = sig_term;
626 + if (sigaction(SIGTERM, &sa, NULL) < 0)
627 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
628 + "sigaction(SIGTERM)");
630 + if (sigaction(SIGINT, &sa, NULL) < 0)
631 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
632 + "sigaction(SIGINT)");
635 + sa.sa_handler = SIG_DFL;
636 + if (sigaction(SIGXCPU, &sa, NULL) < 0)
637 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
638 + "sigaction(SIGXCPU)");
641 + sa.sa_handler = SIG_DFL;
642 + if (sigaction(SIGXFSZ, &sa, NULL) < 0)
643 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
644 + "sigaction(SIGXFSZ)");
647 + sa.sa_handler = SIG_IGN;
648 + if (sigaction(SIGPIPE, &sa, NULL) < 0)
649 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
650 + "sigaction(SIGPIPE)");
653 + /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
654 + * processing one */
655 + sigaddset(&sa.sa_mask, SIGHUP);
656 + sigaddset(&sa.sa_mask, AP_SIG_GRACEFUL);
657 + sa.sa_handler = restart;
658 + if (sigaction(SIGHUP, &sa, NULL) < 0)
659 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
660 + "sigaction(SIGHUP)");
661 + if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0)
662 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
663 + "sigaction(" AP_SIG_GRACEFUL_STRING ")");
667 + apr_signal(SIGSEGV, sig_coredump);
669 + apr_signal(SIGBUS, sig_coredump);
672 + apr_signal(SIGABORT, sig_coredump);
673 +#endif /* SIGABORT */
675 + apr_signal(SIGABRT, sig_coredump);
676 +#endif /* SIGABRT */
678 + apr_signal(SIGILL, sig_coredump);
681 + apr_signal(SIGXCPU, SIG_DFL);
682 +#endif /* SIGXCPU */
684 + apr_signal(SIGXFSZ, SIG_DFL);
685 +#endif /* SIGXFSZ */
688 + apr_signal(SIGTERM, sig_term);
690 + apr_signal(SIGHUP, restart);
692 +#ifdef AP_SIG_GRACEFUL
693 + apr_signal(AP_SIG_GRACEFUL, restart);
694 +#endif /* AP_SIG_GRACEFUL */
696 + apr_signal(SIGPIPE, SIG_IGN);
697 +#endif /* SIGPIPE */
702 +/*****************************************************************
703 + * Here follows a long bunch of generic server bookkeeping stuff...
706 +int ap_graceful_stop_signalled(void)
708 + /* XXX - Does this really work? - Manoj */
709 + return is_graceful;
712 +/*****************************************************************
713 + * Child process main loop.
716 +static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id,
717 + apr_bucket_alloc_t *bucket_alloc)
719 + conn_rec *current_conn;
722 + int thread_num = conn_id % thread_limit;
723 + ap_sb_handle_t *sbh;
725 + if ((rv = apr_os_sock_get(&sock_fd, sock)) != APR_SUCCESS)
727 + ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "apr_os_sock_get");
730 + _DBG("thread_num=%d sock=%ld sock_fd=%d\n", thread_num, sock, sock_fd);
732 + switch (child_info_table[child_num].type)
734 + case CHILD_TYPE_MULTIPLEXER:
735 + _DBG("type=MULTIPLEXER %d",child_num);
737 + case CHILD_TYPE_PROCESSOR:
738 + _DBG("type=PROCESSOR %d",child_num);
741 + _DBG("type UNKNOWN! %d",child_num);
744 + if (sock_fd >= FD_SETSIZE)
746 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
747 + "new file descriptor %d is too large; you probably need "
748 + "to rebuild Apache with a larger FD_SETSIZE "
750 + sock_fd, FD_SETSIZE);
751 + apr_socket_close(sock);
752 + _DBG("thread_num=%d: exiting with error", thread_num);
756 + if (thread_info_table[thread_num].sock_fd < 0)
758 + ap_sock_disable_nagle(sock);
761 + ap_create_sb_handle(&sbh, p, conn_id / thread_limit, thread_num);
762 + _TRACE_CALL("ap_run_create_connection() [thread_num=%d]", thread_num);
763 + current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id,
764 + sbh, bucket_alloc);
765 + _TRACE_RET("ap_run_create_connection() [thread_num=%d]", thread_num);
768 + _TRACE_CALL("ap_process_connection() [thread_num=%d]", thread_num);
769 + ap_process_connection(current_conn, sock);
770 + _TRACE_RET("ap_process_connection() [thread_num=%d]", thread_num);
771 + _TRACE_CALL("ap_lingering_close() [thread_num=%d]", thread_num);
772 + ap_lingering_close(current_conn);
773 + _TRACE_RET("ap_lingering_close() [thread_num=%d]", thread_num);
777 +static metuxmpm_process_connection(conn_rec *conn)
779 + ap_filter_t *filter;
780 + apr_bucket_brigade *bb;
783 + _DBG("function entered",0);
785 + /* -- fetch our sockets from the pool -- */
786 + apr_pool_userdata_get((void **)&bb, "metuxmpm_SOCKETS", conn->pool);
789 + /* -- find the 'core' filter and give the socket data to it -- */
790 + for (filter = conn->output_filters; filter != NULL; filter = filter->next)
792 + if (!strcmp(filter->frec->name, "core")) break;
794 + if (filter != NULL)
797 + net->in_ctx = apr_palloc(conn->pool, sizeof(*net->in_ctx));
798 + net->in_ctx->b = bb;
801 + _DBG("leaving (DECLINED)", 0);
806 +static void *worker_thread_proc(apr_thread_t *, void *);
808 +/* Starts a thread as long as we're below max_threads */
809 +static int start_thread(void)
811 + apr_thread_t *thread;
815 + cnt = worker_thread_count_get ();
817 + _DBG("thread count currently: %d", cnt);
819 + if (cnt < max_threads - 1)
821 + _TRACE_CALL("apr_thread_create()",0);
822 + rc = apr_thread_create(&thread, worker_thread_attr, worker_thread_proc,
823 + &worker_thread_free_ids[worker_thread_count], pchild);
824 + _TRACE_RET("apr_thread_create()",0);
825 + if (rc != APR_SUCCESS)
827 + ap_log_error(APLOG_MARK, APLOG_ALERT, rc, ap_server_conf,
828 + "apr_thread_create: unable to create worker thread");
829 + /* In case system resources are maxxed out, we don't want
830 + Apache running away with the CPU trying to fork over and
831 + over and over again if we exit. */
833 + workers_may_exit = 1;
834 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
837 + worker_thread_count_add ( 1 );
838 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
843 + /* we already have too many threads running */
844 + _DBG("too many running threads. aborting",0);
845 + if (!thread_overflow_reported)
847 + ap_log_error(APLOG_MARK, APLOG_ERR, 0,
849 + "server reached MaxThreadsPerChild setting, "
850 + "consider raising the MaxThreadsPerChild or "
851 + "NumServers settings");
852 + thread_overflow_reported = 1;
854 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
858 +/* Sets workers_may_exit if we received a character on the pipe_of_death */
859 +static apr_status_t check_pipe_of_death
867 + char pipe_read_char;
870 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
872 + if (workers_may_exit) return APR_SUCCESS;
874 + apr_thread_mutex_lock(pipe_of_death_mutex);
875 + ret = apr_recv(lr->sd, &pipe_read_char, &n);
876 + if (APR_STATUS_IS_EAGAIN(ret))
878 + /* It lost the lottery. It must continue to suffer
879 + * through a life of servitude. */
883 + if (pipe_read_char != AP_metuxmpm_CHAR_OF_DEATH)
885 + _DBG("got wrong char %c", pipe_read_char);
886 + return APR_SUCCESS;
888 + /* It won the lottery (or something else is very
889 + * wrong). Embrace death with open arms. */
890 + workers_may_exit = 1;
891 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
893 + apr_thread_mutex_unlock(pipe_of_death_mutex);
894 + return APR_SUCCESS;
897 +static apr_status_t receive_from_multiplexer
899 + void **trans_sock, /* will be filled out w/ the received socket */
900 + ap_listen_rec *lr, /* listener to receive from */
901 + apr_pool_t *ptrans /* transaction wide pool */
905 + struct cmsghdr *cmsg;
906 + char headers[HUGE_STRING_LEN];
908 + apr_size_t bodypart_len;
909 + struct iovec iov[2];
911 + apr_os_sock_t ctrl_sock_fd;
912 + apr_os_sock_t trans_sock_fd;
914 + /* -- bucket's, brigades and their allocators */
915 + apr_bucket_alloc_t *alloc = apr_bucket_alloc_create(ptrans);
916 + apr_bucket_brigade *bb = apr_brigade_create(ptrans, alloc);
917 + apr_bucket *bucket;
919 + /* prepare the buffers for receiving data from remote side */
920 + iov[0].iov_base = &bodypart_len;
921 + iov[0].iov_len = sizeof(bodypart_len);
922 + iov[1].iov_base = headers;
923 + iov[1].iov_len = HUGE_STRING_LEN;
925 + cmsg = apr_palloc(ptrans, sizeof(*cmsg) + sizeof(trans_sock_fd));
926 + cmsg->cmsg_len = sizeof(*cmsg) + sizeof(trans_sock_fd);
928 + msg.msg_name = NULL;
929 + msg.msg_namelen = 0;
931 + msg.msg_iovlen = 2;
932 + msg.msg_control = cmsg;
933 + msg.msg_controllen = cmsg->cmsg_len;
935 + /* -- receive data from socket -- */
936 + apr_os_sock_get(&ctrl_sock_fd, lr->sd);
937 + _DBG("receiving from sock_fd=%d", ctrl_sock_fd);
938 + ret = recvmsg(ctrl_sock_fd, &msg, 0);
940 + /* -- extract socket from the cmsg -- */
941 + memcpy(&trans_sock_fd, CMSG_DATA(cmsg), sizeof(trans_sock_fd));
942 + apr_os_sock_put((apr_socket_t **)trans_sock, &trans_sock_fd, ptrans);
943 + apr_os_sock_get(&fd_tmp, *trans_sock);
946 + _DBG("trans_sock=%ld fdx=%d sock_fd=%d",
947 + *trans_sock, trans_sock_fd, fd_tmp);
949 + _DBG("headers=\"%s\"", headers);
951 + /* -- store received data into an brigade and add
952 + it to the current transaction's pool -- */
953 + bucket = apr_bucket_eos_create(alloc);
954 + APR_BRIGADE_INSERT_HEAD(bb, bucket);
955 + bucket = apr_bucket_socket_create(*trans_sock, alloc);
956 + APR_BRIGADE_INSERT_HEAD(bb, bucket);
958 + /* Receive the bodypart (if there is one) and insert it in the brigade */
959 + if (bodypart_len) {
960 + _DBG("Receiving the bodypart (bodypart_len=%d)", bodypart_len);
961 + bodypart = apr_palloc(ptrans, bodypart_len);
962 + ret = recv(ctrl_sock_fd, bodypart, HUGE_STRING_LEN, 0);
964 + _DBG("bodypart=\"%s\"", bodypart);
965 + bucket = apr_bucket_heap_create(bodypart,
966 + bodypart_len, NULL, alloc);
967 + APR_BRIGADE_INSERT_HEAD(bb, bucket);
969 + _DBG("There is no bodypart",0);
972 + bucket = apr_bucket_heap_create(headers,
973 + strlen(headers), NULL, alloc);
974 + /* DS: I really don't like that strlen here */
976 + APR_BRIGADE_INSERT_HEAD(bb, bucket);
978 + apr_pool_userdata_set(bb, "metuxmpm_SOCKETS", NULL, ptrans);
979 + _DBG("returning 0",0);
983 +/* idle_thread_count should be incremented before starting a worker_thread */
985 +static void *worker_thread_proc(apr_thread_t *thd, void *arg)
987 + apr_socket_t *sock;
988 + apr_pool_t *tpool; /* Pool for this thread */
989 + apr_pool_t *ptrans; /* Pool for per-transaction stuff */
991 + int thread_num = *((int *) arg);
992 + long conn_id = child_num * thread_limit + thread_num;
993 + apr_pollfd_t *pollset;
995 + ap_listen_rec *lr_walk;
998 + apr_bucket_alloc_t *bucket_alloc;
1000 + _DBG("function starting",0);
1002 + /* === allocate thread pools etc === */
1003 + apr_thread_mutex_lock(thread_pool_parent_mutex);
1004 + apr_pool_create(&tpool, thread_pool_parent);
1005 + apr_thread_mutex_unlock(thread_pool_parent_mutex);
1006 + apr_pool_create(&ptrans, tpool);
1008 + (void) ap_update_child_status_from_indexes(child_num, thread_num,
1010 + (request_rec *) NULL);
1012 + bucket_alloc = apr_bucket_alloc_create(apr_thread_pool_get(thd));
1014 + apr_thread_mutex_lock(idle_thread_count_mutex);
1015 + if (idle_thread_count < max_spare_threads)
1017 + idle_thread_count++;
1018 + _DBG("idle_thread_count: %d", idle_thread_count);
1019 + apr_thread_mutex_unlock(idle_thread_count_mutex);
1023 + _DBG("too many idle threads: %d (max %d)", idle_thread_count, max_spare_threads );
1024 + apr_thread_mutex_unlock(idle_thread_count_mutex);
1028 + while (!workers_may_exit)
1030 + apr_int16_t event;
1032 + _DBG("loop. conn_id=%d req_max=%d req_remain=%d",
1033 + conn_id, ap_max_requests_per_child, requests_this_child);
1035 + ((ap_max_requests_per_child != 0) &&
1036 + (requests_this_child < 1) && (workers_may_exit=1));
1038 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
1039 + if (workers_may_exit) goto worker_out;
1041 + (void) ap_update_child_status_from_indexes(child_num, thread_num,
1043 + (request_rec *) NULL);
1045 + THREAD_ACCEPT_LOCK;
1047 + /* -- setup pollset -- */
1048 + /* NOTE: we do _not_ do this upwards anylonger */
1049 + apr_poll_setup(&pollset, num_listensocks, tpool);
1050 + apr_poll_setup(&pollset, num_listensocks, ptrans);
1051 + for(lr_walk = ap_listeners; lr_walk != NULL; lr_walk = lr_walk->next)
1054 + apr_poll_socket_add(pollset, lr_walk->sd, APR_POLLIN);
1055 + apr_os_sock_get(&fd, lr_walk->sd);
1056 + _DBG("adding fd %d to pollset", fd);
1059 + if (workers_may_exit) goto worker_out;
1060 + _TRACE_CALL("apr_poll()",0);
1061 + srv = apr_poll(pollset, num_listensocks, &n, -1);
1062 + _TRACE_RET("apr_poll()",0);
1064 + if (srv != APR_SUCCESS)
1066 + if (APR_STATUS_IS_EINTR(srv))
1068 + _DBG("apr_poll() has been interrupted", 0);
1069 + THREAD_ACCEPT_UNLOCK;
1073 + /* apr_poll() will only return errors in catastrophic
1074 + * circumstances. Let's try exiting gracefully, for now. */
1075 + ap_log_error(APLOG_MARK, APLOG_ERR, srv, (const server_rec *)
1076 + ap_server_conf, "apr_poll: (listen)");
1077 + workers_may_exit = 1;
1078 + _DBG("poll error!",0);
1079 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
1080 + THREAD_ACCEPT_UNLOCK;
1084 + /* find a listener */
1085 + _DBG("looking for an listener",0);
1086 + for (lr_walk=ap_listeners; lr_walk!=NULL; lr_walk = lr_walk->next)
1089 + apr_os_sock_get(&fd_tmp, lr_walk->sd);
1090 + _DBG(" ... trying w/ fd=%d", fd_tmp);
1091 + apr_poll_revents_get(&event, lr_walk->sd, pollset);
1092 + if (event & (APR_POLLIN))
1094 + THREAD_ACCEPT_UNLOCK;
1097 + if (event & (APR_POLLERR))
1099 + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
1100 + "got POLLERR in line 870");
1104 + THREAD_ACCEPT_UNLOCK;
1105 + _DBG("WARN: did not find the right listener",0);
1110 + _DBG("input available ... resetting socket.",0);
1111 + sock = NULL; /* important! */
1113 + _TRACE_CALL("accept_func()",0);
1114 + rv = lr_walk->accept_func((void*)&sock, lr_walk, ptrans);
1115 + _TRACE_RET("accept_func()",0);
1117 + if (rv == APR_EGENERAL)
1119 + /* E[NM]FILE, ENOMEM, etc */
1120 + _DBG("there was some error." ,0);
1121 + workers_may_exit = 1;
1122 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
1126 + apr_thread_mutex_lock(idle_thread_count_mutex);
1127 + if (idle_thread_count > min_spare_threads)
1129 + idle_thread_count--;
1133 + if (!start_thread())
1135 + idle_thread_count--;
1138 + apr_thread_mutex_unlock(idle_thread_count_mutex);
1140 + if (!setjmp(thread_info_table[thread_num].jmpbuffer))
1142 + _DBG("marked jmpbufffer",0);
1143 + _TRACE_CALL("process_socket()",0);
1144 + process_socket(ptrans, sock, conn_id, bucket_alloc);
1145 + _TRACE_RET("process_socket()",0);
1149 + _DBG("landed from longjmp",0);
1150 + thread_info_table[thread_num].sock_fd = AP_metuxmpm_THISCHILD;
1152 + requests_this_child--;
1153 + apr_pool_clear(ptrans);
1156 + _DBG("thread loop finished",0);
1158 + _DBG("this thread's work is done ... workers_may_exit=%d",workers_may_exit);
1160 + /* == think about it == */
1161 + apr_thread_mutex_lock(idle_thread_count_mutex);
1162 + idle_thread_count--;
1163 + apr_thread_mutex_unlock(idle_thread_count_mutex);
1166 + apr_thread_mutex_lock(thread_pool_parent_mutex);
1167 + ap_update_child_status_from_indexes(child_num, thread_num, SERVER_DEAD,
1168 + (request_rec *) NULL);
1169 + apr_pool_destroy(tpool);
1170 + apr_thread_mutex_unlock(thread_pool_parent_mutex);
1172 + thread_cnt = worker_thread_count_add ( -1 );
1173 + worker_thread_free_ids[thread_cnt] = thread_num;
1176 + /* All the threads have exited, now finish the shutdown process
1177 + * by signalling the sigwait thread */
1178 + _DBG("all workers have quit. killing myself (%d) with SIGTERM", my_pid);
1179 + kill(my_pid, SIGTERM);
1183 + _DBG("this is not the time to die - %d threads are still alive", thread_cnt);
1184 + _DBG("WATCH: workers_may_exit=%d", workers_may_exit);
1187 + apr_bucket_alloc_destroy(bucket_alloc);
1188 + _DBG("leaving. good bye",0);
1194 +/* Set group privileges.
1196 + * Note that we use the username as set in the config files, rather than
1197 + * the lookup of to uid --- the same uid may have multiple passwd entries,
1198 + * with different sets of groups for each.
1201 +static int set_group_privs(uid_t uid, gid_t gid)
1207 + /* Get username if passed as a uid */
1209 + struct passwd *ent;
1211 + if ((ent = getpwuid(uid)) == NULL)
1213 + ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1214 + "getpwuid: couldn't determine user name from uid %u, "
1215 + "you probably need to modify the User directive",
1220 + name = ent->pw_name;
1223 + * Set the GID before initgroups(), since on some platforms
1224 + * setgid() is known to zap the group list.
1226 + if (setgid(gid) == -1)
1228 + ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1229 + "setgid: unable to set group id to Group %u",
1234 + /* Reset `groups' attributes. */
1236 + if (initgroups(name, gid) == -1)
1238 + ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1239 + "initgroups: unable to set groups for User %s "
1240 + "and Group %u", name, (unsigned)gid);
1248 +static int metuxmpm_setup_child(int childnum)
1250 + child_info_t *ug = &child_info_table[childnum];
1252 + if (ug->uid == -1 && ug->gid == -1) {
1253 + return unixd_setup_child();
1255 + if (set_group_privs(ug->uid, ug->gid)) {
1258 + /* Only try to switch if we're running as root */
1262 + os_init_job_environment(server_conf, unixd_config.user_name,
1263 + one_process) != 0 ||
1265 + setuid(ug->uid) == -1)) {
1266 + ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1267 + "setuid: unable to change to uid: %ld",
1274 +static int check_signal(int signum)
1276 + _DBG("signum=%d", signum);
1286 +typedef struct metuxmpm_header
1292 +/* Send a single HTTP header field to the client. Note that this function
1293 + * is used in calls to table_do(), so their interfaces are co-dependent.
1294 + * In other words, don't change this one without checking table_do in alloc.c.
1295 + * It returns true unless there was a write error of some kind.
1297 +static int metuxmpm_header_field(metuxmpm_header *h,
1298 + const char *fieldname, const char *fieldval)
1300 + apr_pstrcat(h->p, h->headers, fieldname, ": ", fieldval, CRLF, NULL);
1304 +static inline ap_listen_rec* listen_add ( apr_pool_t* pool, apr_socket_t *sock, void* accept_func )
1306 + ap_listen_rec *lr_walk, *lr_new;
1308 + _DBG("function started",0);
1309 + /* -- create an new listener for this child -- */
1310 + lr_new = apr_palloc(pool, sizeof(*lr_new));
1311 + lr_new->sd = sock;
1312 + lr_new->active = 1;
1313 + lr_new->accept_func = accept_func;
1314 + lr_new->next = NULL;
1316 + /* -- add the new listener_rec into the list -- */
1317 + /* FIXME: should we somehow lock this list ? */
1318 + if (lr_walk = ap_listeners)
1320 + while (lr_walk->next) lr_walk = lr_walk->next;
1321 + lr_walk->next = lr_new;
1325 + ap_listeners = lr_walk = lr_new;
1327 + num_listensocks++;
1331 +static inline void listen_clear ()
1333 + ap_listen_rec *lr_walk;
1335 + _DBG("function started",0);
1337 + /* FIXME: should we somehow lock this list ? */
1338 + while (ap_listeners)
1340 + lr_walk = ap_listeners->next;
1341 + apr_socket_close(ap_listeners->sd);
1342 + ap_listeners = lr_walk;
1344 + num_listensocks=0;
1347 +/* -- main routine of an child process -- */
1348 +static void child_main(int child_num_arg)
1352 + apr_socket_t *sock = NULL;
1354 + my_pid = getpid();
1355 + child_num = child_num_arg;
1357 + _DBG("sock_fd_in=%d sock_fd_out=%d", child_info_table[child_num].input, child_info_table[child_num].output );
1359 + /* -- allocate an new pool for us -- */
1360 + apr_pool_create(&pchild, pconf);
1361 + if (child_info_table[child_num].chroot_dir){
1362 + _DBG("chroot to %s",child_info_table[child_num].chroot_dir);
1363 + if (chroot(child_info_table[child_num].chroot_dir)){
1364 + _DBG("chroot failure %s",child_info_table[child_num].chroot_dir);
1369 + switch (child_info_table[child_num].type)
1371 + case CHILD_TYPE_MULTIPLEXER:
1372 + _DBG("MULTIPLEXER %d", child_num);
1375 + case CHILD_TYPE_PROCESSOR:
1376 + _DBG("PROCESSOR %d", child_num);
1378 + /* -- create new listener to receive from multiplexer -- */
1379 + apr_os_sock_put(&sock, &child_info_table[child_num].input, pconf);
1381 + listen_add ( pconf, sock, receive_from_multiplexer );
1385 + _DBG("unspecified child type for %d sleeping a while ...", child_num);
1389 + /*stuff to do before we switch id's, so we have permissions.*/
1391 + /* -- init child process (uid switching etc) -- */
1392 + (metuxmpm_setup_child(child_num) && clean_child_exit(APEXIT_CHILDFATAL));
1393 + ap_run_child_init(pchild, ap_server_conf);
1395 + /*done with init critical section */
1397 + apr_setup_signal_thread();
1399 + requests_this_child = ap_max_requests_per_child;
1401 + /* Setup worker threads */
1403 + _DBG("setting up worker threads ... " ,0);
1404 + ((threads_to_start > max_threads) && (threads_to_start = max_threads));
1405 + idle_thread_count = threads_to_start;
1406 + workers_may_exit = 0;
1407 + worker_thread_count = 0;
1408 + worker_thread_free_ids = (int *)apr_pcalloc(pchild, thread_limit * sizeof(int));
1409 + for (i = 0; i < max_threads; i++)
1411 + worker_thread_free_ids[i] = i;
1413 + apr_pool_create(&thread_pool_parent, pchild);
1414 + apr_thread_mutex_create(&thread_pool_parent_mutex,
1415 + APR_THREAD_MUTEX_DEFAULT, pchild);
1416 + apr_thread_mutex_create(&idle_thread_count_mutex,
1417 + APR_THREAD_MUTEX_DEFAULT, pchild);
1418 + apr_thread_mutex_create(&worker_thread_count_mutex,
1419 + APR_THREAD_MUTEX_DEFAULT, pchild);
1420 + apr_thread_mutex_create(&pipe_of_death_mutex,
1421 + APR_THREAD_MUTEX_DEFAULT, pchild);
1422 + apr_thread_mutex_create(&thread_accept_mutex,
1423 + APR_THREAD_MUTEX_DEFAULT, pchild);
1425 + apr_threadattr_create(&worker_thread_attr, pchild);
1426 + apr_threadattr_detach_set(worker_thread_attr, 1);
1428 + /* We are creating worker threads right now */
1429 + for (i=0; i < threads_to_start; i++)
1431 + /* start_thread shouldn't fail here */
1432 + _TRACE_CALL("start_thread()",0);
1433 + if (!start_thread()) break;
1434 + _TRACE_RET("start_thread()",0);
1437 + _TRACE_CALL("apr_signal_thread()",0);
1438 + apr_signal_thread(check_signal);
1439 + _TRACE_RET("apr_signal_thread",0);
1442 +static int make_child(server_rec *s, int slot)
1446 + switch (child_info_table[slot].type)
1448 + case CHILD_TYPE_MULTIPLEXER: break;
1449 + case CHILD_TYPE_PROCESSOR: break;
1451 + _DBG("no valid client in slot %d", slot);
1456 + if (slot + 1 > ap_max_daemons_limit)
1458 + ap_max_daemons_limit = slot + 1;
1461 + (void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING,
1462 + (request_rec *) NULL);
1464 + if ((pid = fork()) == -1)
1466 + ap_log_error(APLOG_MARK, APLOG_ERR, errno, s,
1467 + "fork: Unable to fork new process");
1468 + /* In case system resources are maxxed out, we don't want
1469 + * Apache running away with the CPU trying to fork over and
1470 + * over and over again. */
1478 +#ifdef HAVE_BINDPROCESSOR
1479 + /* By default, AIX binds to a single processor. This bit unbinds
1480 + * children which will then bind to another CPU.
1482 + int status = bindprocessor(BINDPROCESS, (int)getpid(),
1483 + PROCESSOR_CLASS_ANY);
1484 + if (status != OK) {
1485 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
1486 + ap_server_conf, "processor unbind failed %d", status);
1490 + RAISE_SIGSTOP(MAKE_CHILD);
1492 + /* XXX - For an unthreaded server, a signal handler will be necessary
1493 + * apr_signal(SIGTERM, just_die);
1496 + clean_child_exit(0);
1499 + ap_scoreboard_image->parent[slot].pid = pid;
1501 + ap_child_table[slot].pid = pid;
1502 + ap_child_table[slot].status = SERVER_ALIVE;
1507 +/* start up a bunch of children */
1508 +static int startup_children(int number_to_start)
1512 + for (i = 0; number_to_start && i < num_childs; ++i)
1514 + if (ap_child_table[i].pid) continue;
1515 + if (make_child(ap_server_conf, i) < 0) break;
1516 + --number_to_start;
1518 + return number_to_start;
1523 + * spawn_rate is the number of children that will be spawned on the
1524 + * next maintenance cycle if there aren't enough servers. It is
1525 + * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
1526 + * without the need to spawn.
1528 +static int spawn_rate = 1;
1529 +#ifndef MAX_SPAWN_RATE
1530 +#define MAX_SPAWN_RATE (32)
1532 +static int hold_off_on_exponential_spawning;
1534 +static void perform_child_maintenance(void)
1538 + int free_slots[MAX_SPAWN_RATE];
1539 + int last_non_dead = -1;
1541 + /* initialize the free_list */
1544 + for (i = 0; i < num_childs; ++i)
1546 + if (ap_child_table[i].pid == 0)
1548 + if (free_length < spawn_rate)
1550 + free_slots[free_length] = i;
1556 + last_non_dead = i;
1559 + if (i >= ap_max_daemons_limit && free_length >= spawn_rate)
1564 + ap_max_daemons_limit = last_non_dead + 1;
1566 + if (free_length > 0)
1568 + for (i = 0; i < free_length; ++i)
1570 + _TRACE_CALL("make_child()",0);
1571 + make_child(ap_server_conf, free_slots[i]);
1572 + _TRACE_RET("make_child()",0);
1574 + /* the next time around we want to spawn twice as many if this
1575 + * wasn't good enough, but not if we've just done a graceful
1577 + if (hold_off_on_exponential_spawning)
1579 + --hold_off_on_exponential_spawning;
1581 + else if (spawn_rate < MAX_SPAWN_RATE)
1592 +static void server_main_loop(int remaining_children_to_start)
1594 + apr_exit_why_e exitwhy;
1601 + while (!restart_pending && !shutdown_pending)
1603 + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
1605 + if (pid.pid != -1)
1607 + if (ap_process_child_status(&pid, exitwhy, status)==APEXIT_CHILDFATAL)
1609 + _DBG("shutdown pending ...",0);
1610 + shutdown_pending = 1;
1614 + /* non-fatal death... note that it's gone in the child table and
1615 + * clean out the status table. */
1616 + _DBG("child has #%d died ...", child_slot);
1618 + for (i = 0; i < ap_max_daemons_limit; ++i)
1620 + if (ap_child_table[i].pid == pid.pid)
1626 + if (child_slot >= 0)
1628 + ap_child_table[child_slot].pid = 0;
1629 + ap_update_child_status_from_indexes(child_slot, i, SERVER_DEAD,
1630 + (request_rec *) NULL);
1633 + if (remaining_children_to_start && (child_slot < num_childs))
1635 + /* we're still doing a 1-for-1 replacement of dead
1636 + * children with new children
1638 + _DBG("replacing by new child ...",0);
1639 + make_child(ap_server_conf, child_slot);
1640 + --remaining_children_to_start;
1642 +#if APR_HAS_OTHER_CHILD
1644 + else if (apr_proc_other_child_read(&pid, status) == 0)
1649 + else if (is_graceful)
1651 + /* Great, we've probably just lost a slot in the
1652 + * child table. Somehow we don't know about this
1655 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
1657 + "long lost child came home! (pid %ld)",
1660 + /* Don't perform idle maintenance when a child dies,
1661 + * only do it when there's a timeout. Remember only a
1662 + * finite number of children can die, and it's pretty
1663 + * pathological for a lot to die suddenly.
1667 + else if (remaining_children_to_start)
1669 + /* we hit a 1 second timeout in which none of the previous
1670 + * generation of children needed to be reaped... so assume
1671 + * they're all done, and pick up the slack if any is left.
1673 + _TRACE_CALL("startup_children()",0);
1674 + remaining_children_to_start = startup_children(remaining_children_to_start);
1675 + _TRACE_RET("startup_children()",0);
1676 + /* In any event we really shouldn't do the code below because
1677 + * few of the servers we just started are in the IDLE state
1678 + * yet, so we'd mistakenly create an extra server.
1683 + perform_child_maintenance();
1687 +int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
1689 + int remaining_children_to_start;
1693 + apr_size_t one = 1;
1694 + apr_socket_t *sock = NULL;
1696 + ap_log_pid(pconf, ap_pid_fname);
1698 + first_server_limit = server_limit;
1699 + first_thread_limit = thread_limit;
1700 + if (changed_limit_at_restart)
1702 + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1703 + "WARNING: Attempt to change ServerLimit or ThreadLimit "
1704 + "ignored during restart");
1705 + changed_limit_at_restart = 0;
1708 + ap_server_conf = s;
1710 + /* Initialize cross-process accept lock */
1711 + ap_lock_fname = apr_psprintf(_pconf, "%s.%u",
1712 + ap_server_root_relative(_pconf, ap_lock_fname),
1714 + rv = ACCEPT_PROC_MUTEX_CREATE;
1715 + if (rv != APR_SUCCESS)
1717 + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
1718 + "Couldn't create cross-process lock");
1724 + if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK)
1729 + /* Initialize the child table */
1732 + for (i = 0; i < server_limit; i++)
1734 + ap_child_table[i].pid = 0;
1738 + /* We need to put the new listeners at the end of the ap_listeners
1739 + * list. If we don't, then the pool will be cleared before the
1740 + * open_logs phase is called for the second time, and ap_listeners
1741 + * will have only invalid data. If that happens, then the sockets
1742 + * that we opened using make_sock() will be lost, and the server
1745 + apr_os_file_get(&fd, pipe_of_death_in);
1746 + apr_os_sock_put(&sock, &fd, pconf);
1748 + listen_add ( pconf, sock, check_pipe_of_death );
1751 + /* If we're doing a graceful_restart then we're going to see a lot
1752 + * of children exiting immediately when we get into the main loop
1753 + * below (because we just sent them AP_SIG_GRACEFUL). This happens
1754 + * pretty rapidly... and for each one that exits we'll start a new one
1755 + * until we reach at least daemons_min_free. But we may be permitted to
1756 + * start more than that, so we'll just keep track of how many we're
1757 + * supposed to start up without the 1 second penalty between each fork.
1759 + remaining_children_to_start = num_childs;
1760 + if (!is_graceful) {
1761 + remaining_children_to_start = \
1762 + startup_children(remaining_children_to_start);
1765 + /* give the system some time to recover before kicking into
1766 + * exponential mode */
1767 + hold_off_on_exponential_spawning = 10;
1770 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
1771 + "%s configured -- resuming normal operations",
1772 + ap_get_server_version());
1773 + ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
1774 + "Server built: %s", ap_get_server_built());
1775 +#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
1776 +#ifdef NO_SERIALIZED_ACCEPT
1777 + _DBG("AcceptMutex: n/a (compiled w/ NO_SERIALIZED_ACCEPT)", 0 );
1778 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1779 + "AcceptMutex: n/a (compiled w/ NO_SERIALIZED_ACCEPT)" );
1781 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1782 + "AcceptMutex: %s (default: %s)",
1783 + apr_proc_mutex_name(process_accept_mutex),
1784 + apr_proc_mutex_defname());
1787 + restart_pending = shutdown_pending = 0;
1789 + server_main_loop(remaining_children_to_start);
1791 + if (shutdown_pending)
1793 + /* Time to gracefully shut down:
1794 + * Kill child processes, tell them to call child_exit, etc...
1796 + if (unixd_killpg(getpgrp(), SIGTERM) < 0)
1798 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
1799 + "killpg SIGTERM");
1801 + ap_reclaim_child_processes(1); /* Start with SIGTERM */
1805 + /* cleanup pid file on normal shutdown */
1806 + const char *pidfile = NULL;
1807 + pidfile = ap_server_root_relative (pconf, ap_pid_fname);
1808 + if (pidfile != NULL && unlink(pidfile) == 0) {
1809 + ap_log_error(APLOG_MARK, APLOG_INFO, 0,
1811 + "removed PID file %s (pid=%ld)",
1812 + pidfile, (long)getpid());
1815 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
1816 + ap_server_conf, "caught SIGTERM, shutting down");
1821 + /* we've been told to restart */
1822 + apr_signal(SIGHUP, SIG_IGN);
1824 + if (one_process) return 1; /* not worth thinking about */
1828 + char char_of_death = AP_metuxmpm_CHAR_OF_DEATH;
1830 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
1831 + ap_server_conf, AP_SIG_GRACEFUL_STRING " received. "
1832 + "Doing graceful restart");
1834 + /* This is mostly for debugging... so that we know what is still
1835 + * gracefully dealing with existing request.
1838 + for (i = 0; i < num_childs; ++i)
1840 + ((ap_child_table[i].pid) && (ap_child_table[i].status = SERVER_DYING));
1843 + /* give the children the signal to die */
1844 + for (i = 0; i < num_childs;)
1846 + if ((rv = apr_file_write(pipe_of_death_out, &char_of_death,&one)) != APR_SUCCESS)
1848 + if (APR_STATUS_IS_EINTR(rv)) continue;
1849 + ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
1850 + "write pipe_of_death");
1857 + /* Kill 'em all. Since the child acts the same on the parents SIGTERM
1858 + * and a SIGHUP, we may as well use the same signal, because some user
1859 + * pthreads are stealing signals from us left and right.
1861 + if (unixd_killpg(getpgrp(), SIGTERM) < 0)
1863 + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
1864 + "killpg SIGTERM");
1866 + ap_reclaim_child_processes(1); /* Start with SIGTERM */
1867 + ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
1868 + ap_server_conf, "SIGHUP received. Attempting to restart");
1873 +/* This really should be a post_config hook, but the error log is already
1874 + * redirected by that point, so we need to do this in the open_logs phase.
1876 +static int metuxmpm_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
1881 + ap_server_conf = s;
1883 + _DBG("port=%d", ap_server_conf->port);
1885 + if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) {
1886 + ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0,
1887 + NULL, "metuxmpm_open_logs(): no listening sockets available, shutting down");
1891 + ap_log_pid(pconf, ap_pid_fname);
1893 + if ((rv = ap_mpm_pod_open(pconf, &pod))) {
1894 + ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL,
1895 + "Could not open pipe-of-death.");
1899 + if ((rv = apr_file_pipe_create(&pipe_of_death_in, &pipe_of_death_out,
1900 + pconf)) != APR_SUCCESS) {
1901 + ap_log_error(APLOG_MARK, APLOG_ERR, rv,
1902 + (const server_rec*) ap_server_conf,
1903 + "apr_file_pipe_create (apipe_of_death)");
1906 + if ((rv = apr_file_pipe_timeout_set(pipe_of_death_in, 0)) != APR_SUCCESS) {
1907 + ap_log_error(APLOG_MARK, APLOG_ERR, rv,
1908 + (const server_rec*) ap_server_conf,
1909 + "apr_file_pipe_timeout_set (pipe_of_death)");
1916 +static int metuxmpm_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
1918 + static int restart_num = 0;
1919 + int no_detach, debug, foreground;
1920 + ap_directive_t *pdir;
1922 + int tmp_server_limit = DEFAULT_SERVER_LIMIT;
1923 + int tmp_thread_limit = DEFAULT_THREAD_LIMIT;
1926 + debug = ap_exists_config_define("DEBUG");
1929 + foreground = one_process = 1;
1933 + one_process = ap_exists_config_define("ONE_PROCESS");
1934 + no_detach = ap_exists_config_define("NO_DETACH");
1935 + foreground = ap_exists_config_define("FOREGROUND");
1940 + foreground = 0; */
1942 + /* sigh, want this only the second time around */
1943 + if (restart_num++ == 1)
1947 + if (!one_process && !foreground)
1949 + rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND
1950 + : APR_PROC_DETACH_DAEMONIZE);
1951 + if (rv != APR_SUCCESS) {
1952 + ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
1953 + "apr_proc_detach failed");
1954 + return HTTP_INTERNAL_SERVER_ERROR;
1958 + my_pid = getpid();
1961 + unixd_pre_config(ptemp);
1962 + ap_listen_pre_config();
1963 +// num_childs = DEFAULT_NUM_DAEMON;
1965 + threads_to_start = DEFAULT_START_THREAD;
1966 + min_spare_threads = DEFAULT_MIN_SPARE_THREAD;
1967 + max_spare_threads = DEFAULT_MAX_SPARE_THREAD;
1968 + max_threads = thread_limit;
1969 + ap_pid_fname = DEFAULT_PIDLOG;
1970 + ap_lock_fname = DEFAULT_LOCKFILE;
1971 + ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
1973 + apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
1975 + /* we need to know ServerLimit and ThreadLimit before we start processing
1976 + * the tree because we need to already have allocated child_info_table
1978 + for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next)
1980 + if (!strcasecmp(pdir->directive, "ServerLimit"))
1982 + if (atoi(pdir->args) > tmp_server_limit)
1984 + tmp_server_limit = atoi(pdir->args);
1985 + if (tmp_server_limit > MAX_SERVER_LIMIT)
1987 + tmp_server_limit = MAX_SERVER_LIMIT;
1991 + else if (!strcasecmp(pdir->directive, "ThreadLimit"))
1993 + if (atoi(pdir->args) > tmp_thread_limit)
1995 + tmp_thread_limit = atoi(pdir->args);
1996 + if (tmp_thread_limit > MAX_THREAD_LIMIT)
1998 + tmp_thread_limit = MAX_THREAD_LIMIT;
2004 + /* -- now setup the child information table -- */
2005 + child_info_table = (child_info_t *)apr_pcalloc(p, tmp_server_limit * sizeof(child_info_t));
2006 + child_info_table_size = tmp_server_limit; /* FIXME: remove tmp_server_limit */
2007 + for (i = 0; i < tmp_server_limit; i++)
2009 + child_info_table[i].uid = -1;
2010 + child_info_table[i].gid = -1;
2011 + child_info_table[i].input = -1;
2012 + child_info_table[i].output = -1;
2013 + child_info_table[i].type = -1;
2014 + child_info_table[i].id = i;
2022 +static int pass_request(request_rec *r)
2025 + struct msghdr msg;
2026 + struct cmsghdr *cmsg;
2028 + char *bodypart = NULL;
2029 + struct iovec iov[2];
2030 + conn_rec *c = r->connection;
2031 + apr_bucket_brigade *bb = apr_brigade_create(r->pool, c->bucket_alloc);
2032 + apr_bucket_brigade *bodypart_bb = NULL;
2033 + apr_size_t len = 0;
2034 + apr_size_t bodypart_len = 0;
2035 + metuxmpm_header h;
2036 + apr_bucket *bucket;
2037 + const apr_array_header_t *headers_in_array;
2038 + const apr_table_entry_t *headers_in;
2041 + apr_socket_t *thesock = ap_get_module_config(r->connection->conn_config, &core_module);
2042 + metuxmpm_server_conf *sconf = metuxmpm_SERVER_CONF(r->server->module_config);
2044 + if ((!r->the_request) || (!strlen(r->the_request)))
2046 + _DBG("empty request. dropping it (%ld)", r->the_request);
2050 + if (!sconf->child)
2052 + _DBG("server %s in child %d has no child_info assiocated",
2053 + r->hostname, child_num);
2057 + _DBG("passing request to another child. Vhost: %s, child %d %d",
2058 + apr_table_get(r->headers_in, "Host"), child_num, sconf->child->output);
2059 + _DBG("r->the_request=\"%s\" len=%d", r->the_request, strlen(r->the_request));
2061 + ap_get_brigade(r->connection->input_filters, bb, AP_MODE_EXHAUSTIVE, APR_NONBLOCK_READ, len);
2063 + /* Scan the brigade looking for heap-buckets */
2065 + _DBG("Scanning the brigade",0);
2066 + bucket = APR_BRIGADE_FIRST(bb);
2067 + while (bucket != APR_BRIGADE_SENTINEL(bb) &&
2068 + APR_BUCKET_IS_HEAP(bucket)) {
2069 + _DBG("HEAP BUCKET is found, length=%d", bucket->length);
2070 + bucket = APR_BUCKET_NEXT(bucket);
2071 + if (!APR_BUCKET_IS_HEAP(bucket)) {
2072 + _DBG("NON-HEAP BUCKET is found, extracting the part of brigade before it",0);
2074 + bb = apr_brigade_split(bodypart_bb, bucket);
2075 + /* Do we need to apr_destroy_brigade(bb) here?
2076 + * Yeah, I know we do apr_pool_destroy(r->pool) before return, but
2077 + * ap_get_brigade is in non-blocking mode (however len is zero).
2079 + if (apr_brigade_pflatten(bodypart_bb, &bodypart, &bodypart_len, r->pool) != APR_SUCCESS) {
2080 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2081 + "Unable to flatten brigade, declining request");
2082 + apr_pool_destroy(r->pool);
2085 + _DBG("Brigade is flattened as bodypart (bodypart_len=%d)", bodypart_len);
2088 + _DBG("Scanning is finished",0);
2090 + apr_os_sock_get(&sock_fd, thesock);
2094 + headers_in_array = apr_table_elts(r->headers_in);
2095 + headers_in = (const apr_table_entry_t *) headers_in_array->elts;
2097 + h.headers = apr_pstrcat(h.p, r->the_request, CRLF, NULL);
2098 + for (counter = 0; counter < headers_in_array->nelts; counter++) {
2099 + if (headers_in[counter].key == NULL
2100 + || headers_in[counter].val == NULL) {
2103 + h.headers = apr_pstrcat(h.p, h.headers, headers_in[counter].key, ": ",
2104 + headers_in[counter].val, CRLF, NULL);
2107 + h.headers = apr_pstrcat(h.p, h.headers, CRLF, NULL);
2108 + ap_xlate_proto_to_ascii(h.headers, strlen(h.headers));
2110 + iov[0].iov_base = &bodypart_len;
2111 + iov[0].iov_len = sizeof(bodypart_len);
2112 + iov[1].iov_base = h.headers;
2113 + iov[1].iov_len = strlen(h.headers) + 1;
2115 + msg.msg_name = NULL;
2116 + msg.msg_namelen = 0;
2117 + msg.msg_iov = iov;
2118 + msg.msg_iovlen = 2;
2120 + cmsg = apr_palloc(r->pool, sizeof(*cmsg) + sizeof(sock_fd));
2121 + cmsg->cmsg_len = sizeof(*cmsg) + sizeof(sock_fd);
2122 + cmsg->cmsg_level = SOL_SOCKET;
2123 + cmsg->cmsg_type = SCM_RIGHTS;
2125 + memcpy(CMSG_DATA(cmsg), &sock_fd, sizeof(sock_fd));
2127 + msg.msg_control = cmsg;
2128 + msg.msg_controllen = cmsg->cmsg_len;
2130 + _DBG("Writing message to %d, passing sock_fd: %d", sconf->child->output, sock_fd);
2131 + _DBG("headers=\"%s\"", h.headers);
2132 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2133 + "Writing message to %d, passing sd: %d", sconf->child->output, sock_fd);
2135 + if ((rv = sendmsg(sconf->child->output, &msg, 0)) == -1)
2137 + apr_pool_destroy(r->pool);
2138 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2139 + "Writing message failed %d %d", rv, errno);
2143 + _DBG("Writing message succeeded %d", rv);
2144 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2145 + "Writing message succeeded %d", rv);
2147 + if (bodypart_len) {
2148 + _DBG("Passing bodypart (bodypart_len=%d) \"%s\"", bodypart_len, bodypart);
2149 + if ((rv = send(sconf->child->output, bodypart, bodypart_len, 0)) == -1) {
2150 + apr_pool_destroy(r->pool);
2151 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2152 + "Writing message failed %d %d", rv, errno);
2155 + _DBG("Writing message succeeded %d", rv);
2156 + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2157 + "Writing message succeeded %d", rv);
2159 + _DBG("No bodypart",0);
2162 + /* -- close the socket at our site -- */
2163 + apr_socket_close(thesock);
2164 + /* DS: What is the purpose of this?
2165 + * apr_socket_close(sconf->child->output) seems more reasonable
2167 + _DBG("closing socket %d at our side", sock_fd);
2168 + apr_pool_destroy(r->pool);
2172 +static int metuxmpm_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *server_list)
2175 + server_rec *sr_walk;
2176 + metuxmpm_server_conf *sconf;
2178 + for (sr_walk = server_list; sr_walk; sr_walk = sr_walk->next)
2180 + sconf = metuxmpm_SERVER_CONF(sr_walk->module_config);
2183 + _DBG("server \"%s\" child=%d fd_in=%d fd_out=%d",
2184 + sr_walk->server_hostname,
2186 + sconf->child->input,
2187 + sconf->child->output );
2191 + _DBG("server \"%s\" has no child assiocated.",
2192 + sr_walk->server_hostname);
2196 + thread_info_table = (thread_info_t *)apr_pcalloc(p, thread_limit * sizeof(thread_info_t));
2197 + for (i = 0; i < thread_limit; i++)
2199 + thread_info_table[i].sock_fd = AP_metuxmpm_THISCHILD;
2200 + thread_info_table[i].status = 0;
2202 + ap_child_table = (ap_ctable *)apr_pcalloc(p, server_limit * sizeof(ap_ctable));
2207 +static int metuxmpm_post_read(request_rec *r)
2209 + int thread_num = r->connection->id % thread_limit;
2210 + metuxmpm_server_conf *sconf = metuxmpm_SERVER_CONF(r->server->module_config);
2212 + if (!strlen(r->the_request))
2214 + _DBG("corrupt request. aborting",0);
2218 + if (thread_info_table[thread_num].sock_fd != AP_metuxmpm_THISCHILD)
2220 + apr_socket_t *sock = NULL;
2222 + apr_os_sock_put(&sock, &thread_info_table[thread_num].sock_fd,
2223 + r->connection->pool);
2224 + ap_sock_disable_nagle(sock);
2225 + ap_set_module_config(r->connection->conn_config, &core_module, sock);
2226 + _DBG("not the right socket? ",0);
2230 + switch (child_info_table[child_num].type)
2232 + case CHILD_TYPE_MULTIPLEXER:
2234 + _DBG("MULTIPLEXER => Determining if request should be passed. "
2235 + "Child Num: %d, dest-child: %d, hostname from server: %s r->hostname=%s r->the_request=\"%s\"",
2236 + child_num, sconf->child->id, r->server->server_hostname, r->hostname, r->the_request);
2238 + if (sconf->child->id != child_num)
2240 + _DBG("Passing request.",0);
2241 + if (pass_request(r) == -1)
2243 + ap_log_error(APLOG_MARK, APLOG_ERR, 0,
2244 + ap_server_conf, "Could not pass request to proper "
2245 + "child, request will not be honoured.");
2248 + _DBG("doing longjmp",0);
2249 + longjmp(thread_info_table[thread_num].jmpbuffer, 1);
2250 + _DBG("request declined at our site",0);
2252 + _DBG("OUH! we should never reach this point",0);
2254 + _DBG("eeeh?! the server is assigned to the multiplexer! ... dropping request",0);
2257 + case CHILD_TYPE_PROCESSOR:
2259 + _DBG("PROCESSOR %d", child_num );
2260 + if (sconf->child->id != child_num)
2262 + _DBG("hmmpf! this server is not assigned to us! what did the mux have smoked ?!",0);
2264 + _DBG("request for %s / (server %s) seems to be for us", r->hostname, r->server->server_hostname );
2269 + _DBG("unspecified child type %d in %d, dropping request", child_info_table[child_num].type, child_num );
2273 + _DBG("THIS POINT SHOULD NOT BE REACHED!",0);
2277 +static void metuxmpm_hooks(apr_pool_t *p)
2279 + /* The metuxmpm open_logs phase must run before the core's, or stderr
2280 + * will be redirected to a file, and the messages won't print to the
2283 + static const char *const aszSucc[] = {"core.c", NULL};
2286 + ap_hook_open_logs(metuxmpm_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
2287 + ap_hook_pre_config(metuxmpm_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
2288 + ap_hook_post_config(metuxmpm_post_config, NULL, NULL, APR_HOOK_MIDDLE);
2290 + /* Both of these must be run absolutely first. If this request isn't for
2291 + * this server then we need to forward it to the proper child. No sense
2292 + * tying up this server running more post_read request hooks if it is
2293 + * just going to be forwarded along. The process_connection hook allows
2294 + * metuxmpm to receive the passed request correctly, by automatically
2295 + * filling in the core_input_filter's ctx pointer.
2297 + ap_hook_post_read_request(metuxmpm_post_read, NULL, NULL,
2298 + APR_HOOK_REALLY_FIRST);
2299 + ap_hook_process_connection(metuxmpm_process_connection, NULL, NULL,
2300 + APR_HOOK_REALLY_FIRST);
2303 +//static const char *cf_NumServers(cmd_parms *cmd, void *dummy,
2304 +// const char *arg)
2306 +// const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2307 +// if (err != NULL) return err;
2309 +// num_childs = atoi(arg);
2310 +// if (num_childs > server_limit) {
2311 +// ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2312 +// "WARNING: NumServers of %d exceeds ServerLimit value "
2313 +// "of %d servers,", num_childs, server_limit);
2314 +// ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2315 +// " lowering NumServers to %d. To increase, please "
2316 +// "see the", server_limit);
2317 +// ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2318 +// " ServerLimit directive.");
2319 +// num_childs = server_limit;
2321 +// else if (num_childs < 1)
2323 +// ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2324 +// "WARNING: Require NumServers > 0, setting to 1");
2330 +static const char *cf_StartThreads(cmd_parms *cmd, void *dummy,
2333 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2334 + if (err != NULL) return err;
2336 + threads_to_start = atoi(arg);
2337 + if (threads_to_start > thread_limit) {
2338 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2339 + "WARNING: StartThreads of %d exceeds ThreadLimit value"
2340 + " of %d threads,", threads_to_start,
2342 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2343 + " lowering StartThreads to %d. To increase, please"
2344 + " see the", thread_limit);
2345 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2346 + " ThreadLimit directive.");
2348 + else if (threads_to_start < 1) {
2349 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2350 + "WARNING: Require StartThreads > 0, setting to 1");
2351 + threads_to_start = 1;
2356 +static const char *cf_MinSpareThreads(cmd_parms *cmd, void *dummy,
2359 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2360 + if (err != NULL) return err;
2362 + min_spare_threads = atoi(arg);
2363 + if (min_spare_threads <= 0)
2365 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2366 + "WARNING: detected MinSpareThreads set to non-positive.");
2367 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2368 + "Resetting to 1 to avoid almost certain Apache failure.");
2369 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2370 + "Please read the documentation.");
2371 + min_spare_threads = 1;
2377 +static const char *cf_MaxSpareThreads(cmd_parms *cmd, void *dummy,
2380 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2381 + if (err != NULL) return err;
2383 + max_spare_threads = atoi(arg);
2384 + if (max_spare_threads >= thread_limit)
2386 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2387 + "WARNING: detected MinSpareThreads set higher than");
2388 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2389 + "ThreadLimit. Resetting to %d", thread_limit);
2390 + max_spare_threads = thread_limit;
2395 +static const char *cf_MaxThreadsPerChild(cmd_parms *cmd, void *dummy, const char *arg)
2397 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2398 + if (err != NULL) return err;
2400 + max_threads = atoi(arg);
2401 + if (max_threads > thread_limit)
2403 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2404 + "WARNING: detected MaxThreadsPerChild set higher than");
2405 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2406 + "ThreadLimit. Resetting to %d", thread_limit);
2407 + max_threads = thread_limit;
2412 +static const char* child_add ( int type, const char* user_name, const char* group_name ,const char* chroot_dir )
2414 + _DBG("%d: %s.%s %s", num_childs, user_name, group_name, chroot_dir);
2415 + if (num_childs<server_limit)
2420 + child_info_table[num_childs].uid = ap_uname2id(user_name);
2421 + child_info_table[num_childs].gid = ap_gname2id(group_name);
2422 + child_info_table[num_childs].type = type;
2423 + socketpair(PF_UNIX, SOCK_STREAM, 0, socks);
2424 + child_info_table[num_childs].input = socks[0];
2425 + child_info_table[num_childs].output = socks[1];
2426 + child_info_table[num_childs].chroot_dir = 0;
2428 + l = strlen(chroot_dir);
2430 + child_info_table[num_childs].chroot_dir = chroot_dir;
2431 + /* should copy the contents */
2432 + /* do we need to check its existence? */
2436 + _DBG("[%d] uid=%d gid=%d type=%d fd_in=%d fd_out=%d,chroot_dir=%s",
2438 + child_info_table[num_childs].uid,
2439 + child_info_table[num_childs].gid,
2440 + child_info_table[num_childs].type,
2441 + child_info_table[num_childs].input,
2442 + child_info_table[num_childs].output,
2443 + child_info_table[num_childs].chroot_dir
2446 + if (child_info_table[num_childs].uid == 0 ||
2447 + child_info_table[num_childs].gid == 0)
2449 + _DBG("Assigning root user/group to a child.",0);
2455 + return "Trying to use more child ID's than NumServers. "
2456 + "Increase NumServers in your config file.";
2459 +/* we define an Processor w/ specific uid/gid */
2460 +static const char *cf_Processor(
2461 + cmd_parms *cmd, void *dummy, const char *user_name, const char *group_name, const char *chroot_dir)
2463 + _DBG("%d: %s.%s %s", num_childs, user_name, group_name, chroot_dir);
2464 + return child_add ( CHILD_TYPE_PROCESSOR, user_name, group_name, chroot_dir );
2467 +/* we define an Multiplexer child w/ specific uid/gid */
2468 +static const char *cf_Multiplexer(
2469 + cmd_parms *cmd, void *dummy, const char *user_name, const char *group_name, const char *chroot_dir)
2471 + _DBG("%d: %s.%s %s", num_childs, user_name, group_name, chroot_dir);
2472 + return child_add ( CHILD_TYPE_MULTIPLEXER, user_name, group_name, chroot_dir );
2475 +/* process the config file option AssignUserId */
2476 +/* -- FIXME: perhaps we could add childs from here automatically -- */
2477 +static const char * cf_AssignUserId
2481 + const char *user_name,
2482 + const char *group_name
2487 + int uid = ap_uname2id(user_name);
2488 + int gid = ap_gname2id(group_name);
2489 + const char *errstr;
2491 + metuxmpm_server_conf *sconf
2492 + = metuxmpm_SERVER_CONF(cmd->server->module_config);
2494 + sconf->fullsockname =
2495 + apr_pstrcat(cmd->pool, sconf->sockname, ".", user_name,":", group_name, NULL);
2497 + _DBG("user=\"%s\" (%d) group=\"%s\" (%d) numchilds=%d", user_name, uid, group_name, gid, num_childs );
2499 + for (i = 0; i < num_childs; i++)
2501 + _DBG("trying %d: %d.%d / %d", i,
2502 + child_info_table[i].uid, child_info_table[i].gid, child_info_table[i].type );
2504 + if ((uid == child_info_table[i].uid) &&
2505 + (gid == child_info_table[i].gid) &&
2506 + (child_info_table[i].type == CHILD_TYPE_PROCESSOR))
2508 + /* create an socket for this child, if it has no one */
2509 + /* FIXME: we should do it anywhere else, for _all_ childs */
2510 + sconf->child = &child_info_table[i];
2511 + _DBG("assigning server to child %d; "
2512 + "UID: %d, GID: %d, input=%d, output=%d",
2513 + i, uid, gid, sconf->child->input, sconf->child->output);
2518 + _DBG("assigning server to child FAILED %d; UID: %d, GID: %d ", i, uid, gid);
2519 + return "Unable to find process with matching uid/gid.";
2522 +static const char *cf_ServerLimit (cmd_parms *cmd, void *dummy, const char *arg)
2524 + int tmp_server_limit;
2526 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2527 + if (err != NULL) return err;
2529 + tmp_server_limit = atoi(arg);
2530 + /* you cannot change ServerLimit across a restart; ignore
2531 + * any such attempts
2533 + if (first_server_limit && tmp_server_limit != server_limit)
2535 + /* how do we log a message? the error log is a bit bucket at this
2536 + * point; we'll just have to set a flag so that ap_mpm_run()
2537 + * logs a warning later
2539 + changed_limit_at_restart = 1;
2542 + server_limit = tmp_server_limit;
2544 + if (server_limit > MAX_SERVER_LIMIT)
2546 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2547 + "WARNING: ServerLimit of %d exceeds compile time limit "
2548 + "of %d servers,", server_limit, MAX_SERVER_LIMIT);
2549 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2550 + " lowering ServerLimit to %d.", MAX_SERVER_LIMIT);
2551 + server_limit = MAX_SERVER_LIMIT;
2553 + else if (server_limit < 1)
2555 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2556 + "WARNING: Require ServerLimit > 0, setting to 1");
2562 +static const char *cf_ThreadLimit (cmd_parms *cmd, void *dummy, const char *arg)
2564 + int tmp_thread_limit;
2566 + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2567 + if (err != NULL) return err;
2569 + tmp_thread_limit = atoi(arg);
2570 + /* you cannot change ThreadLimit across a restart; ignore
2571 + * any such attempts
2573 + if (first_thread_limit && tmp_thread_limit != thread_limit)
2575 + /* how do we log a message? the error log is a bit bucket at this
2576 + * point; we'll just have to set a flag so that ap_mpm_run()
2577 + * logs a warning later
2579 + changed_limit_at_restart = 1;
2582 + thread_limit = tmp_thread_limit;
2584 + if (thread_limit > MAX_THREAD_LIMIT)
2586 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2587 + "WARNING: ThreadLimit of %d exceeds compile time limit "
2588 + "of %d servers,", thread_limit, MAX_THREAD_LIMIT);
2589 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2590 + " lowering ThreadLimit to %d.", MAX_THREAD_LIMIT);
2591 + thread_limit = MAX_THREAD_LIMIT;
2593 + else if (thread_limit < 1)
2595 + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
2596 + "WARNING: Require ThreadLimit > 0, setting to 1");
2602 +static const command_rec metuxmpm_cmds[] = {
2603 +UNIX_DAEMON_COMMANDS,
2605 +AP_INIT_TAKE1("StartThreads", cf_StartThreads, NULL, RSRC_CONF,
2606 + "Number of threads each child creates"),
2607 +AP_INIT_TAKE1("MinSpareThreads", cf_MinSpareThreads, NULL, RSRC_CONF,
2608 + "Minimum number of idle threads per child, to handle "
2609 + "request spikes"),
2610 +AP_INIT_TAKE1("MaxSpareThreads", cf_MaxSpareThreads, NULL, RSRC_CONF,
2611 + "Maximum number of idle threads per child"),
2612 +AP_INIT_TAKE1("MaxThreadsPerChild", cf_MaxThreadsPerChild, NULL, RSRC_CONF,
2613 + "Maximum number of threads per child"),
2614 +AP_INIT_TAKE23("Multiplexer", cf_Multiplexer, NULL, RSRC_CONF,
2615 + "Specify an Multiplexer Child configuration."),
2616 +AP_INIT_TAKE23("Processor", cf_Processor, NULL, RSRC_CONF,
2617 + "Specify a User and Group for a specific child process."),
2618 +AP_INIT_TAKE2("AssignUserID", cf_AssignUserId, NULL, RSRC_CONF,
2619 + "Tie a virtual host to a specific child process."),
2620 +AP_INIT_TAKE1("ServerLimit", cf_ServerLimit, NULL, RSRC_CONF,
2621 + "Maximum value of NumServers for this run of Apache"),
2622 +AP_INIT_TAKE1("ThreadLimit", cf_ThreadLimit, NULL, RSRC_CONF,
2623 + "Maximum worker threads in a server for this run of Apache"),
2627 +/* == allocate an private server config structure == */
2628 +static void *metuxmpm_create_config(apr_pool_t *p, server_rec *s)
2630 + metuxmpm_server_conf *c = (metuxmpm_server_conf *)
2631 + apr_pcalloc(p, sizeof(metuxmpm_server_conf));
2636 +module AP_MODULE_DECLARE_DATA mpm_metuxmpm_module =
2638 + MPM20_MODULE_STUFF,
2639 + ap_mpm_rewrite_args, /* hook to run before apache parses args */
2640 + NULL, /* create per-directory config structure */
2641 + NULL, /* merge per-directory config structures */
2642 + metuxmpm_create_config, /* create per-server config structure */
2643 + NULL, /* merge per-server config structures */
2644 + metuxmpm_cmds, /* command apr_table_t */
2645 + metuxmpm_hooks /* register_hooks */
2648 diff -Nur httpd-2.0.48/server/mpm/experimental/metuxmpm/mpm.h httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/mpm.h
2649 --- httpd-2.0.48/server/mpm/experimental/metuxmpm/mpm.h 1969-12-31 17:00:00.000000000 -0700
2650 +++ httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/mpm.h 2004-03-19 10:03:32.137459576 -0700
2652 +/* ====================================================================
2653 + * The Apache Software License, Version 1.1
2655 + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
2658 + * Redistribution and use in source and binary forms, with or without
2659 + * modification, are permitted provided that the following conditions
2662 + * 1. Redistributions of source code must retain the above copyright
2663 + * notice, this list of conditions and the following disclaimer.
2665 + * 2. Redistributions in binary form must reproduce the above copyright
2666 + * notice, this list of conditions and the following disclaimer in
2667 + * the documentation and/or other materials provided with the
2670 + * 3. The end-user documentation included with the redistribution,
2671 + * if any, must include the following acknowledgment:
2672 + * "This product includes software developed by the
2673 + * Apache Software Foundation (http://www.apache.org/)."
2674 + * Alternately, this acknowledgment may appear in the software itself,
2675 + * if and wherever such third-party acknowledgments normally appear.
2677 + * 4. The names "Apache" and "Apache Software Foundation" must
2678 + * not be used to endorse or promote products derived from this
2679 + * software without prior written permission. For written
2680 + * permission, please contact apache@apache.org.
2682 + * 5. Products derived from this software may not be called "Apache",
2683 + * nor may "Apache" appear in their name, without prior written
2684 + * permission of the Apache Software Foundation.
2686 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
2687 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2688 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2689 + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
2690 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2691 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2692 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2693 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2694 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2695 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2696 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2698 + * ====================================================================
2700 + * This software consists of voluntary contributions made by many
2701 + * individuals on behalf of the Apache Software Foundation. For more
2702 + * information on the Apache Software Foundation, please see
2703 + * <http://www.apache.org/>.
2705 + * Portions of this software are based upon public domain software
2706 + * originally written at the National Center for Supercomputing Applications,
2707 + * University of Illinois, Urbana-Champaign.
2711 +#include "mpm_default.h"
2714 +#ifndef APACHE_MPM_METUXMPM_H
2715 +#define APACHE_MPM_METUXMPM_H
2717 +#define METUXMPM_MPM
2719 +#define MPM_NAME "metuxmpm"
2721 +#define AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
2722 +#define AP_MPM_WANT_WAIT_OR_TIMEOUT
2723 +#define AP_MPM_WANT_PROCESS_CHILD_STATUS
2724 +#define AP_MPM_WANT_SET_PIDFILE
2725 +#define AP_MPM_WANT_SET_SCOREBOARD
2726 +#define AP_MPM_WANT_SET_LOCKFILE
2727 +#define AP_MPM_WANT_SET_MAX_REQUESTS
2728 +#define AP_MPM_WANT_SET_COREDUMPDIR
2729 +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
2730 +#define AP_MPM_WANT_SIGNAL_SERVER
2731 +#define AP_MPM_USES_POD
2733 +#define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
2734 +#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
2735 +#define MPM_ACCEPT_FUNC unixd_accept
2737 +/* Table of child status */
2738 +#define SERVER_DEAD 0
2739 +#define SERVER_DYING 1
2740 +#define SERVER_ALIVE 2
2742 +typedef struct ap_ctable{
2744 + unsigned char status;
2747 +extern int ap_threads_per_child;
2748 +extern int ap_max_daemons_limit;
2749 +extern server_rec *ap_server_conf;
2751 +#endif /* APACHE_MPM_METUXMPM_H */
2752 diff -Nur httpd-2.0.48/server/mpm/experimental/metuxmpm/mpm_default.h httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/mpm_default.h
2753 --- httpd-2.0.48/server/mpm/experimental/metuxmpm/mpm_default.h 1969-12-31 17:00:00.000000000 -0700
2754 +++ httpd-2.0.48-metuxmpm-r8/server/mpm/experimental/metuxmpm/mpm_default.h 2004-03-19 10:03:32.138459433 -0700
2756 +/* ====================================================================
2757 + * The Apache Software License, Version 1.1
2759 + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
2762 + * Redistribution and use in source and binary forms, with or without
2763 + * modification, are permitted provided that the following conditions
2766 + * 1. Redistributions of source code must retain the above copyright
2767 + * notice, this list of conditions and the following disclaimer.
2769 + * 2. Redistributions in binary form must reproduce the above copyright
2770 + * notice, this list of conditions and the following disclaimer in
2771 + * the documentation and/or other materials provided with the
2774 + * 3. The end-user documentation included with the redistribution,
2775 + * if any, must include the following acknowledgment:
2776 + * "This product includes software developed by the
2777 + * Apache Software Foundation (http://www.apache.org/)."
2778 + * Alternately, this acknowledgment may appear in the software itself,
2779 + * if and wherever such third-party acknowledgments normally appear.
2781 + * 4. The names "Apache" and "Apache Software Foundation" must
2782 + * not be used to endorse or promote products derived from this
2783 + * software without prior written permission. For written
2784 + * permission, please contact apache@apache.org.
2786 + * 5. Products derived from this software may not be called "Apache",
2787 + * nor may "Apache" appear in their name, without prior written
2788 + * permission of the Apache Software Foundation.
2790 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
2791 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2792 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2793 + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
2794 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2795 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2796 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2797 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2798 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2799 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2800 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2802 + * ====================================================================
2804 + * This software consists of voluntary contributions made by many
2805 + * individuals on behalf of the Apache Software Foundation. For more
2806 + * information on the Apache Software Foundation, please see
2807 + * <http://www.apache.org/>.
2809 + * Portions of this software are based upon public domain software
2810 + * originally written at the National Center for Supercomputing Applications,
2811 + * University of Illinois, Urbana-Champaign.
2814 +#ifndef APACHE_MPM_DEFAULT_H
2815 +#define APACHE_MPM_DEFAULT_H
2817 +#define NO_SERIALIZED_ACCEPT
2819 +/* Number of threads to spawn off by default --- also, if fewer than
2820 + * this free when the caretaker checks, it will spawn more.
2822 +#ifndef DEFAULT_START_THREAD
2823 +#define DEFAULT_START_THREAD 5
2826 +/* Maximum number of *free* server threads --- more than this, and
2827 + * they will die off.
2830 +#ifndef DEFAULT_MAX_SPARE_THREAD
2831 +#define DEFAULT_MAX_SPARE_THREAD 10
2834 +/* Minimum --- fewer than this, and more will be created */
2836 +#ifndef DEFAULT_MIN_SPARE_THREAD
2837 +#define DEFAULT_MIN_SPARE_THREAD 5
2840 +/* Number of servers to spawn off by default
2842 +#ifndef DEFAULT_NUM_DAEMON
2843 +#define DEFAULT_NUM_DAEMON 2
2846 +/* File used for accept locking, when we use a file */
2847 +#ifndef DEFAULT_LOCKFILE
2848 +#define DEFAULT_LOCKFILE DEFAULT_REL_RUNTIMEDIR "/accept.lock"
2851 +/* Where the main/parent process's pid is logged */
2852 +#ifndef DEFAULT_PIDLOG
2853 +#define DEFAULT_PIDLOG DEFAULT_REL_RUNTIMEDIR "/httpd.pid"
2857 + * Interval, in microseconds, between scoreboard maintenance.
2859 +#ifndef SCOREBOARD_MAINTENANCE_INTERVAL
2860 +#define SCOREBOARD_MAINTENANCE_INTERVAL 1000000
2863 +/* Number of requests to try to handle in a single process. If <= 0,
2864 + * the children don't die off.
2866 +#ifndef DEFAULT_MAX_REQUESTS_PER_CHILD
2867 +#define DEFAULT_MAX_REQUESTS_PER_CHILD 10000
2870 +#endif /* AP_MPM_DEFAULT_H */
2871 diff -Nur httpd-2.0.48/srclib/apr/network_io/unix/sockets.c httpd-2.0.48-metuxmpm-r8/srclib/apr/network_io/unix/sockets.c
2872 --- httpd-2.0.48/srclib/apr/network_io/unix/sockets.c 2003-07-08 06:53:11.000000000 -0600
2873 +++ httpd-2.0.48-metuxmpm-r8/srclib/apr/network_io/unix/sockets.c 2004-03-19 10:03:32.138459433 -0700
2874 @@ -411,7 +411,36 @@
2875 set_socket_vars(*sock, APR_INET, SOCK_STREAM, 0);
2876 (*sock)->timeout = -1;
2878 - (*sock)->local_port_unknown = (*sock)->local_interface_unknown = 1;
2879 +// (*sock)->local_port_unknown = (*sock)->local_interface_unknown = 1;
2882 + /* fixup socket's peer information.
2883 + we need it for the muxmpm. enrico weigelt, metux ITS
2884 + <weigelt@metux.de>
2886 + /* XXX next line looks bogus w.r.t. AF_INET6 support */
2888 + /* adjust remote address */
2889 + (*sock)->remote_addr->salen = sizeof((*sock)->remote_addr->sa);
2892 + (struct sockaddr*)&((*sock)->remote_addr->sa),
2893 + &((*sock)->remote_addr->salen)
2895 + (*sock)->remote_addr->port = ntohs((*sock)->remote_addr->sa.sin.sin_port);
2897 + /* XXX assumes sin_port and sin6_port at same offset */
2899 + /* adjust local address */
2902 + (struct sockaddr*)&((*sock)->local_addr->sa),
2903 + &((*sock)->local_addr->salen)
2905 + (*sock)->local_addr->port = ntohs((*sock)->local_addr->sa.sin.sin_port);
2906 + (*sock)->local_port_unknown = (*sock)->local_interface_unknown = 0;
2909 (*sock)->remote_addr_unknown = 1;
2910 (*sock)->socketdes = *thesock;