mpm_common.c revision 9b07fdbae72923016406bb66e2875e3324722a6f
3802a3d3d7af51ddff31943d5514382f01265770Lennart Poettering/* ====================================================================
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * The Apache Software License, Version 1.1
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * Copyright (c) 2000 The Apache Software Foundation. All rights
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * Redistribution and use in source and binary forms, with or without
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * modification, are permitted provided that the following conditions
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * 1. Redistributions of source code must retain the above copyright
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * notice, this list of conditions and the following disclaimer.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * 2. Redistributions in binary form must reproduce the above copyright
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * notice, this list of conditions and the following disclaimer in
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * the documentation and/or other materials provided with the
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * 3. The end-user documentation included with the redistribution,
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * if any, must include the following acknowledgment:
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * "This product includes software developed by the
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * Apache Software Foundation (http://www.apache.org/)."
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * Alternately, this acknowledgment may appear in the software itself,
301af7e4853ad0281402f8d86f5a77c6cb7ce9f4Josh Triplett * if and wherever such third-party acknowledgments normally appear.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * 4. The names "Apache" and "Apache Software Foundation" must
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * not be used to endorse or promote products derived from this
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * software without prior written permission. For written
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * permission, please contact apache@apache.org.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * 5. Products derived from this software may not be called "Apache",
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * nor may "Apache" appear in their name, without prior written
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * permission of the Apache Software Foundation.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301af7e4853ad0281402f8d86f5a77c6cb7ce9f4Josh Triplett * ====================================================================
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * This software consists of voluntary contributions made by many
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * individuals on behalf of the Apache Software Foundation. For more
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * information on the Apache Software Foundation, please see
301af7e4853ad0281402f8d86f5a77c6cb7ce9f4Josh Triplett * Portions of this software are based upon public domain software
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen * originally written at the National Center for Supercomputing Applications,
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * University of Illinois, Urbana-Champaign.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek/* The purpose of this file is to store the code that MOST mpm's will need
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * this does not mean a function only goes into this file if every MPM needs
dd2b607b7d1ce355e93f9f71cd256ec20b8ae9c4Thomas Hindoe Paaboel Andersen * it. It means that if a function is needed by more than one MPM, and
18ead1b00dff180a97507d014325cb46198e6657Chris Mayo * future maintenance would be served by making the code common, then the
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * function belongs here.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * This is going in src/main because it is not platform specific, it is
e93549ef29c4123d9ee45acb5815048390201e49Zbigniew Jędrzejewski-Szmek * specific to multi-process servers, but NOT to Unix. Which is why it
301af7e4853ad0281402f8d86f5a77c6cb7ce9f4Josh Triplett * does not belong in src/os/unix
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek#include <sys/time.h> /* for timeval definitions */
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek#if defined(DEXTER) || defined(MPMT_BEOS_MPM) || defined(BEOS_MPM)
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek#define CHILD_INFO_TABLE ap_child_table
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek#elif defined(MPMT_PTHREAD) || defined (NO_THREADS) || defined(PREFORK_MPM)
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek#define CHILD_INFO_TABLE ap_scoreboard_image->parent
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmekvoid ap_reclaim_child_processes(int terminate)
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek long int waittime = 1024 * 16; /* in usecs */
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek for (tries = terminate ? 4 : 1; tries <= 9; ++tries) {
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek /* don't want to hold up progress any more than
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * necessary, but we need to allow children a few moments to exit.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek * Set delay with an exponential backoff.
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek /* now see who is done */
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek for (i = 0; i < max_daemons; ++i) {
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek pid_t pid = CHILD_INFO_TABLE[i].pid;
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek if (ap_child_table[i].status == SERVER_DEAD)
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek if (pid == ap_my_pid || pid == 0)
0dc5d23c85db85f96b141d4d32deee8018e56a6aLennart Poettering waitret = ap_wait_proc(&proc, APR_NOWAIT);
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek /* ok, now it's being annoying */
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING,
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek "child process %ld still did not exit, sending a SIGTERM",
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek /* die child scum */
3cc765d2718ac9b4ff978044ceabf5ad59d73edfZbigniew Jędrzejewski-Szmek ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR,
0, ap_server_conf,
(long)pid);
#ifndef BEOS
0, ap_server_conf,
if (!not_dead_yet) {
#ifndef INTERVAL_OF_WRITABLE_PROBES
static int wait_or_timeout_counter;
#ifdef APR_HAS_OTHER_CHILD
#ifdef NEED_WAITPID
case SIGTERM:
case SIGHUP:
case SIGUSR1:
case SIGKILL:
#ifdef SYS_SIGLIST
#ifdef WCOREDUMP
0, ap_server_conf,
0, ap_server_conf,
#ifdef WCOREDUMP
0, ap_server_conf,