mpm_common.c revision 2d399cd7535887fceaa9f8f116eb98ce68ddd602
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl/* ====================================================================
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner * The Apache Software License, Version 1.1
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl *
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * reserved.
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl *
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * Redistribution and use in source and binary forms, with or without
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * modification, are permitted provided that the following conditions
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * are met:
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl *
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * 1. Redistributions of source code must retain the above copyright
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * notice, this list of conditions and the following disclaimer.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco *
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * 2. Redistributions in binary form must reproduce the above copyright
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * notice, this list of conditions and the following disclaimer in
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the documentation and/or other materials provided with the
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * distribution.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco *
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * 3. The end-user documentation included with the redistribution,
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * if any, must include the following acknowledgment:
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * "This product includes software developed by the
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * Apache Software Foundation (http://www.apache.org/)."
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * Alternately, this acknowledgment may appear in the software itself,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * if and wherever such third-party acknowledgments normally appear.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * 4. The names "Apache" and "Apache Software Foundation" must
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * not be used to endorse or promote products derived from this
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * software without prior written permission. For written
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * permission, please contact apache@apache.org.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * 5. Products derived from this software may not be called "Apache",
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * nor may "Apache" appear in their name, without prior written
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * permission of the Apache Software Foundation.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco *
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
8ecdb62fa2cef068eb4dbce59f3219a8e3adc0baChristian Maeder * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * SUCH DAMAGE.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * ====================================================================
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco * This software consists of voluntary contributions made by many
6e121321775373fe11161d23c541437456df19b4Adrián Riesco * individuals on behalf of the Apache Software Foundation. For more
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * information on the Apache Software Foundation, please see
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * <http://www.apache.org/>.
6e121321775373fe11161d23c541437456df19b4Adrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * Portions of this software are based upon public domain software
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * originally written at the National Center for Supercomputing Applications,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * University of Illinois, Urbana-Champaign.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco/* The purpose of this file is to store the code that MOST mpm's will need
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * this does not mean a function only goes into this file if every MPM needs
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * it. It means that if a function is needed by more than one MPM, and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * future maintenance would be served by making the code common, then the
a74f814d3b445eadad6f68737a98a7a303698affChristian Maeder * function belongs here.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * This is going in src/main because it is not platform specific, it is
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * specific to multi-process servers, but NOT to Unix. Which is why it
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * does not belong in src/os/unix
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#include "apr.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "apr_thread_proc.h"
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#include "apr_signal.h"
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#include "apr_strings.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#define APR_WANT_STRFUNC
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "apr_want.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "httpd.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "http_config.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "http_log.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "http_main.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "mpm.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "mpm_common.h"
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#include "ap_mpm.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "ap_listen.h"
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco#include "mpm_default.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_SET_SCOREBOARD
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "scoreboard.h"
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef HAVE_PWD_H
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <pwd.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef HAVE_GRP_H
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <grp.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maedervoid ap_reclaim_child_processes(int terminate)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int i;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder long int waittime = 1024 * 16; /* in usecs */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder apr_status_t waitret;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int tries;
a74f814d3b445eadad6f68737a98a7a303698affChristian Maeder int not_dead_yet;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int max_daemons;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder for (tries = terminate ? 4 : 1; tries <= 9; ++tries) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* don't want to hold up progress any more than
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * necessary, but we need to allow children a few moments to exit.
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * Set delay with an exponential backoff.
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_sleep(waittime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco waittime = waittime * 4;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder /* now see who is done */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder not_dead_yet = 0;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder for (i = 0; i < max_daemons; ++i) {
6e121321775373fe11161d23c541437456df19b4Adrián Riesco pid_t pid = MPM_CHILD_PID(i);
6e121321775373fe11161d23c541437456df19b4Adrián Riesco apr_proc_t proc;
6e121321775373fe11161d23c541437456df19b4Adrián Riesco
6e121321775373fe11161d23c541437456df19b4Adrián Riesco if (pid == 0)
6e121321775373fe11161d23c541437456df19b4Adrián Riesco continue;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder proc.pid = pid;
6e121321775373fe11161d23c541437456df19b4Adrián Riesco waitret = apr_proc_wait(&proc, NULL, NULL, APR_NOWAIT);
6e121321775373fe11161d23c541437456df19b4Adrián Riesco if (waitret != APR_CHILD_NOTDONE) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder MPM_NOTE_CHILD_KILLED(i);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder continue;
6e121321775373fe11161d23c541437456df19b4Adrián Riesco }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ++not_dead_yet;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco switch (tries) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 1: /* 16ms */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 2: /* 82ms */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 3: /* 344ms */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 4: /* 16ms */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco break;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 5: /* 82ms */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 6: /* 344ms */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco case 7: /* 1.4sec */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* ok, now it's being annoying */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_log_error(APLOG_MARK, APLOG_WARNING,
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder 0, ap_server_conf,
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder "child process %ld still did not exit, "
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder "sending a SIGTERM",
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder (long)pid);
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder kill(pid, SIGTERM);
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder break;
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder case 8: /* 6 sec */
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder /* die child scum */
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder ap_log_error(APLOG_MARK, APLOG_ERR,
9e0e436980397412aa6c10b9aebde527ca2474bfChristian Maeder 0, ap_server_conf,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder "child process %ld still did not exit, "
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder "sending a SIGKILL",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (long)pid);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#ifndef BEOS
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder kill(pid, SIGKILL);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco#else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* sending a SIGKILL kills the entire team on BeOS, and as
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco * httpd thread is part of that team it removes any chance
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * of ever doing a restart. To counter this I'm changing to
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * use a kinder, gentler way of killing a specific thread
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * that is just as effective.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco kill_thread(pid);
dece9056c18ada64bcc8f2fba285270374139ee8Christian Maeder#endif
dece9056c18ada64bcc8f2fba285270374139ee8Christian Maeder break;
e0f1794e365dd347e97b37d7d22b2fce27296fa1Christian Maeder
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco case 9: /* 14 sec */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* gave it our best shot, but alas... If this really
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * is a child we are trying to kill and it really hasn't
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * exited, we will likely fail to bind to the port
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * after the restart.
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco ap_log_error(APLOG_MARK, APLOG_ERR,
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco 0, ap_server_conf,
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "could not make child process %ld exit, "
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "attempting to continue anyway",
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco (long)pid);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco break;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
ab9c6be005cb2af851307b7968c2baa16a76d6b1Adrián Riesco#if APR_HAS_OTHER_CHILD
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_proc_other_child_check();
5eb747ed1f9cb3d902d4277badfc2a42f9f98b0cAdrián Riesco#endif
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco if (!not_dead_yet) {
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco /* nothing left to wait for */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco break;
3f8cdebaede9921402318d525b57a9af8f9279d3Adrián Riesco }
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco }
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco}
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#endif /* AP_MPM_WANT_RECLAIM_CHILD_PROCESSES */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_WAIT_OR_TIMEOUT
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco/* number of calls to wait_or_timeout between writable probes */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#ifndef INTERVAL_OF_WRITABLE_PROBES
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#define INTERVAL_OF_WRITABLE_PROBES 10
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#endif
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riescostatic int wait_or_timeout_counter;
e0f1794e365dd347e97b37d7d22b2fce27296fa1Christian Maeder
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riescovoid ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret,
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco apr_pool_t *p)
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco{
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco apr_status_t rv;
0f593bb6e3f0bc82abf3d6d3c76ef222a43d0476Adrián Riesco
0f593bb6e3f0bc82abf3d6d3c76ef222a43d0476Adrián Riesco ++wait_or_timeout_counter;
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) {
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco wait_or_timeout_counter = 0;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco }
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco rv = apr_proc_wait_all_procs(ret, exitcode, status, APR_NOWAIT, p);
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco if (APR_STATUS_IS_EINTR(rv)) {
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco ret->pid = -1;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco return;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco }
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco if (APR_STATUS_IS_CHILD_DONE(rv)) {
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco return;
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco }
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#ifdef NEED_WAITPID
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco if ((ret = reap_children(exitcode, status)) > 0) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco }
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#endif
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder apr_sleep(SCOREBOARD_MAINTENANCE_INTERVAL);
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco ret->pid = -1;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder}
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder#endif /* AP_MPM_WANT_WAIT_OR_TIMEOUT */
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status)
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco{
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco int signum = status;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco const char *sigdesc = apr_signal_get_description(signum);
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco /* Child died... if it died due to a fatal error,
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * we should simply bail out. The caller needs to
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * check for bad rc from us and exit, running any
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * appropriate cleanups.
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco *
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * If the child died due to a resource shortage,
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * the parent should limit the rate of forking
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco if (APR_PROC_CHECK_EXIT(why)) {
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco if (status == APEXIT_CHILDSICK) {
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco return status;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco }
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco if (status == APEXIT_CHILDFATAL) {
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco ap_log_error(APLOG_MARK, APLOG_ALERT,
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco 0, ap_server_conf,
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco "Child %" APR_PID_T_FMT
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco " returned a Fatal error..." APR_EOL_STR
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco "Apache is exiting!",
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder pid->pid);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return APEXIT_CHILDFATAL;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco }
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco return 0;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco }
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco if (APR_PROC_CHECK_SIGNALED(why)) {
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco switch (signum) {
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco case SIGTERM:
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco case SIGHUP:
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder case AP_SIG_GRACEFUL:
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco case SIGKILL:
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco break;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
cffa214f1ca524a65075ab26339df7040fe36032Christian Maeder default:
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco if (APR_PROC_CHECK_CORE_DUMP(why)) {
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco ap_log_error(APLOG_MARK, APLOG_NOTICE,
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco 0, ap_server_conf,
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco "child pid %ld exit signal %s (%d), "
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco "possible coredump in %s",
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco (long)pid->pid, sigdesc, signum,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco ap_coredump_dir);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco }
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco else {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco ap_log_error(APLOG_MARK, APLOG_NOTICE,
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco 0, ap_server_conf,
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco "child pid %ld exit signal %s (%d)",
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco (long)pid->pid, sigdesc, signum);
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco }
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco }
0be63c5d4b5e66cc600a0003081ae2bf85be9615Adrián Riesco }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder return 0;
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco}
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco#endif /* AP_MPM_WANT_PROCESS_CHILD_STATUS */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco#if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF) && !defined(WIN32)
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescovoid ap_sock_disable_nagle(apr_socket_t *s)
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco{
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco /* The Nagle algorithm says that we should delay sending partial
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco * packets in hopes of getting more data. We don't want to do
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco * this; we are not telnet. There are bad interactions between
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco * persistent connections and Nagle's algorithm that have very severe
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * performance penalties. (Failing to disable Nagle is not much of a
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco * problem with simple HTTP.)
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco *
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * In spite of these problems, failure here is not a shooting offense.
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder */
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco apr_status_t status = apr_setsocketopt(s, APR_TCP_NODELAY, 1);
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco if (status != APR_SUCCESS) {
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco ap_log_error(APLOG_MARK, APLOG_WARNING, status, ap_server_conf,
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco "setsockopt: (TCP_NODELAY)");
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco }
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco}
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco#endif
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco#ifdef HAVE_GETPWNAM
223be434693e8c97e2522ac19155a284b3536035Adrián RiescoAP_DECLARE(uid_t) ap_uname2id(const char *name)
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco struct passwd *ent;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco if (name[0] == '#')
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder return (atoi(&name[1]));
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco if (!(ent = getpwnam(name))) {
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "%s: bad user name %s", ap_server_argv0, name);
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco exit(1);
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder }
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return (ent->pw_uid);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco}
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco#endif
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#ifdef HAVE_GETGRNAM
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián RiescoAP_DECLARE(gid_t) ap_gname2id(const char *name)
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco{
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco struct group *ent;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (name[0] == '#')
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return (atoi(&name[1]));
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco if (!(ent = getgrnam(name))) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "%s: bad group name %s", ap_server_argv0, name);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco exit(1);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco return (ent->gr_gid);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco}
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco#endif
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco#ifndef HAVE_INITGROUPS
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riescoint initgroups(const char *name, gid_t basegid)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM) || defined(OS2) || defined(WIN32) || defined(NETWARE)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder/* QNX, MPE and BeOS do not appear to support supplementary groups. */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return 0;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#else /* ndef QNX */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco gid_t groups[NGROUPS_MAX];
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco struct group *g;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder int index = 0;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco setgrent();
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco groups[index++] = basegid;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco while (index < NGROUPS_MAX && ((g = getgrent()) != NULL)) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (g->gr_gid != basegid) {
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco char **names;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco for (names = g->gr_mem; *names != NULL; ++names) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (!strcmp(*names, name))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco groups[index++] = g->gr_gid;
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco }
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco }
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco endgrent();
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return setgroups(index, groups);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#endif /* def QNX */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder}
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco#endif /* def NEED_INITGROUPS */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#ifdef AP_MPM_USES_POD
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian MaederAP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_status_t rv;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder *pod = apr_palloc(p, sizeof(**pod));
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco rv = apr_file_pipe_create(&((*pod)->pod_in), &((*pod)->pod_out), p);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (rv != APR_SUCCESS) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return rv;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_file_pipe_timeout_set((*pod)->pod_in, 0);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco (*pod)->p = p;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_sockaddr_info_get(&(*pod)->sa, ap_listeners->bind_addr->hostname,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco APR_UNSPEC, ap_listeners->bind_addr->port, 0, p);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco return APR_SUCCESS;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco}
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián RiescoAP_DECLARE(apr_status_t) ap_mpm_pod_check(ap_pod_t *pod)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco char c;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder apr_size_t len = 1;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder apr_status_t rv;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco rv = apr_file_read(pod->pod_in, &c, &len);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv == APR_SUCCESS) && (len == 1)) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return APR_SUCCESS;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (rv != APR_SUCCESS) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return rv;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return AP_NORESTART;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco}
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián RiescoAP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_status_t rv;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder rv = apr_file_close(pod->pod_out);
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco if (rv != APR_SUCCESS) {
8ecdb62fa2cef068eb4dbce59f3219a8e3adc0baChristian Maeder return rv;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco }
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco rv = apr_file_close(pod->pod_in);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (rv != APR_SUCCESS) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return rv;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco }
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco return APR_SUCCESS;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder}
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
357381f0a999099cd2d4c268006df56b47847d68Adrián Riescostatic apr_status_t pod_signal_internal(ap_pod_t *pod)
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco{
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_status_t rv;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco char char_of_death = '!';
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_size_t one = 1;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder rv = apr_file_write(pod->pod_out, &char_of_death, &one);
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco if (rv != APR_SUCCESS) {
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder "write pipe_of_death");
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco }
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco return rv;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco}
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco/* This function connects to the server, then immediately closes the connection.
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco * This permits the MPM to skip the poll when there is only one listening
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco * socket, because it provides a alternate way to unblock an accept() when
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * the pod is used.
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder */
357381f0a999099cd2d4c268006df56b47847d68Adrián Riescostatic apr_status_t dummy_connection(ap_pod_t *pod)
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco{
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_status_t rv;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_socket_t *sock;
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco apr_pool_t *p;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
357381f0a999099cd2d4c268006df56b47847d68Adrián Riesco /* create a temporary pool for the socket. pconf stays around too long */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder rv = apr_pool_create(&p, pod->p);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (rv != APR_SUCCESS) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return rv;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder rv = apr_socket_create(&sock, pod->sa->family, SOCK_STREAM, p);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (rv != APR_SUCCESS) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco "get socket to connect to listener");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return rv;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder /* on some platforms (e.g., FreeBSD), the kernel won't accept many
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * queued connections before it starts blocking local connects...
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * we need to keep from blocking too long and instead return an error,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * because the MPM won't want to hold up a graceful restart for a
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco * long time
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder rv = apr_setsocketopt(sock, APR_SO_TIMEOUT, 3 * APR_USEC_PER_SEC);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (rv != APR_SUCCESS) {
d021fa76efedeeb63529a82dd1cfd81911f4d03eChristian Maeder ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco "set timeout on socket to connect to listener");
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco apr_socket_close(sock);
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder return rv;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco rv = apr_connect(sock, pod->sa);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco if (rv != APR_SUCCESS) {
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco int log_level = APLOG_WARNING;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (APR_STATUS_IS_TIMEUP(rv)) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder /* probably some server processes bailed out already and there
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * is nobody around to call accept and clear out the kernel
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * connection queue; usually this is not worth logging
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco log_level = APLOG_DEBUG;
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_log_error(APLOG_MARK, log_level, rv, ap_server_conf,
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "connect to listener");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco apr_socket_close(sock);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_pool_destroy(p);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return rv;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco}
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian MaederAP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder{
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco apr_status_t rv;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder rv = pod_signal_internal(pod);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (rv != APR_SUCCESS) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return rv;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return dummy_connection(pod);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder}
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riescovoid ap_mpm_pod_killpg(ap_pod_t *pod, int num)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int i;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_status_t rv = APR_SUCCESS;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* we don't write anything to the pod here... we assume
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * that the would-be reader of the pod has another way to
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * see that it is time to die once we wake it up
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * writing lots of things to the pod at once is very
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * problematic... we can fill the kernel pipe buffer and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * be blocked until somebody consumes some bytes or
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * we hit a timeout... if we hit a timeout we can't just
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * keep trying because maybe we'll never successfully
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * write again... but then maybe we'll leave would-be
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * readers stranded (a number of them could be tied up for
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder * a while serving time-consuming requests)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < num && rv == APR_SUCCESS; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco rv = dummy_connection(pod);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif /* #ifdef AP_MPM_USES_POD */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder/* standard mpm configuration handling */
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#ifdef AP_MPM_WANT_SET_PIDFILE
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maederconst char *ap_pid_fname = NULL;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescoconst char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder const char *arg)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder{
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (err != NULL) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return err;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (cmd->server->is_virtual) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return "PidFile directive not allowed in <VirtualHost>";
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder ap_pid_fname = arg;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return NULL;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_SET_SCOREBOARD
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescoconst char * ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *arg)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco if (err != NULL) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return err;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_scoreboard_fname = arg;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return NULL;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_SET_LOCKFILE
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescoconst char *ap_lock_fname = NULL;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maederconst char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *arg)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (err != NULL) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return err;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_lock_fname = arg;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return NULL;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco}
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#endif
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_SET_MAX_REQUESTS
6f6549c13f912de12345850e4eb248ec358c1b43Adrián Riescoint ap_max_requests_per_child = 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescoconst char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder const char *arg)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (err != NULL) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return err;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco ap_max_requests_per_child = atoi(arg);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return NULL;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef AP_MPM_WANT_SET_COREDUMPDIR
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riescochar ap_coredump_dir[MAX_STRING_LEN];
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riescoconst char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder const char *arg)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_status_t rv;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_finfo_t finfo;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *fname;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
d021fa76efedeeb63529a82dd1cfd81911f4d03eChristian Maeder if (err != NULL) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return err;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder fname = ap_server_root_relative(cmd->pool, arg);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (!fname) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return apr_pstrcat(cmd->pool, "Invalid CoreDumpDirectory path ",
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder arg, NULL);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if ((rv = apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool)) != APR_SUCCESS) {
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco " does not exist", NULL);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (finfo.filetype != APR_DIR) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder " is not a directory", NULL);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return NULL;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riescoapr_lockmech_e ap_accept_lock_mech = APR_LOCK_DEFAULT;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riescoconst char ap_valid_accept_mutex_string[] =
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco "Valid accept mutexes for this platform and MPM are: default"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#if APR_HAS_FLOCK_SERIALIZE
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder ", flock"
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#endif
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#if APR_HAS_FCNTL_SERIALIZE
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco ", fcntl"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#endif
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder ", sysvsem"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#endif
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#if APR_HAS_POSIXSEM_SERIALIZE
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder ", posixsem"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#endif
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#if APR_HAS_PROC_PTHREAD_SERIALIZE
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco ", pthread"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#endif
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco ".";
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian MaederAP_DECLARE(const char *) ap_mpm_set_accept_lock_mech(cmd_parms *cmd,
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder void *dummy,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *arg)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (err != NULL) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder return err;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder if (!strcasecmp(arg, "default")) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_accept_lock_mech = APR_LOCK_DEFAULT;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#if APR_HAS_FLOCK_SERIALIZE
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder else if (!strcasecmp(arg, "flock")) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_accept_lock_mech = APR_LOCK_FLOCK;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAS_FCNTL_SERIALIZE
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (!strcasecmp(arg, "fcntl")) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_accept_lock_mech = APR_LOCK_FCNTL;
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* perchild can't use SysV sems because the permissions on the accept
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * mutex can't be set to allow all processes to use the mutex and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * at the same time keep all users from being able to dink with the
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * mutex
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder else if (!strcasecmp(arg, "sysvsem")) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder ap_accept_lock_mech = APR_LOCK_SYSVSEM;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAS_POSIXSEM_SERIALIZE
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder else if (!strcasecmp(arg, "posixsem")) {
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder ap_accept_lock_mech = APR_LOCK_POSIXSEM;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAS_PROC_PTHREAD_SERIALIZE
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (!strcasecmp(arg, "pthread")) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_accept_lock_mech = APR_LOCK_PROC_PTHREAD;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; ",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ap_valid_accept_mutex_string, NULL);
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return NULL;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder#endif
94e112d16f89130a688db8b03ad3224903f5e97eChristian Maeder