mpm_unix.c revision 2eb5346b17b3b69767cfe87d0f632efd6d15500d
3802a3d3d7af51ddff31943d5514382f01265770Lennart Poettering/* Licensed to the Apache Software Foundation (ASF) under one or more
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * contributor license agreements. See the NOTICE file distributed with
681eb9cf2b831293a4f3d4c48a748d2e4a25d69eFilipe Brandenburger * this work for additional information regarding copyright ownership.
681eb9cf2b831293a4f3d4c48a748d2e4a25d69eFilipe Brandenburger * The ASF licenses this file to You under the Apache License, Version 2.0
681eb9cf2b831293a4f3d4c48a748d2e4a25d69eFilipe Brandenburger * (the "License"); you may not use this file except in compliance with
681eb9cf2b831293a4f3d4c48a748d2e4a25d69eFilipe Brandenburger * the License. You may obtain a copy of the License at
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * http://www.apache.org/licenses/LICENSE-2.0
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * Unless required by applicable law or agreed to in writing, software
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * distributed under the License is distributed on an "AS IS" BASIS,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * See the License for the specific language governing permissions and
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * limitations under the License.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* The purpose of this file is to store the code that MOST mpm's will need
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * this does not mean a function only goes into this file if every MPM needs
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * it. It means that if a function is needed by more than one MPM, and
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * future maintenance would be served by making the code common, then the
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * function belongs here.
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * This is going in src/main because it is not platform specific, it is
b975b0d514321f169b3c4599a8ea92e13741b4e4Zbigniew Jędrzejewski-Szmek * specific to multi-process servers, but NOT to Unix. Which is why it
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * does not belong in src/os/unix
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringtypedef enum {DO_NOTHING, SEND_SIGTERM, SEND_SIGKILL, GIVEUP} action_t;
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringvoid ap_register_extra_mpm_process(pid_t pid)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering extra_process_t *p = (extra_process_t *)malloc(sizeof(extra_process_t));
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringint ap_unregister_extra_mpm_process(pid_t pid)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering /* we don't know about any such process */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringstatic int reclaim_one_pid(pid_t pid, action_t action)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering /* Ensure pid sanity. */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering waitret = apr_proc_wait(&proc, &status, &why, APR_NOWAIT);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering ap_process_child_status(&proc, why, status);
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering /* ok, now it's being annoying */
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek ap_log_error(APLOG_MARK, APLOG_WARNING,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering " still did not exit, "
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering "sending a SIGTERM",
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek ap_log_error(APLOG_MARK, APLOG_ERR,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering " still did not exit, "
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering "sending a SIGKILL",
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek /* gave it our best shot, but alas... If this really
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * is a child we are trying to kill and it really hasn't
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * exited, we will likely fail to bind to the port
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * after the restart.
0, ap_server_conf,
pid);
int not_dead_yet;
int max_daemons;
} action_table[] = {
++next_action;
not_dead_yet = 0;
for (i = 0; i < max_daemons; ++i) {
if (pid == 0) {
++not_dead_yet;
while (cur_extra) {
++not_dead_yet;
} while (not_dead_yet > 0 &&
void ap_relieve_child_processes(void)
int max_daemons;
for (i = 0; i < max_daemons; ++i) {
if (pid == 0) {
while (cur_extra) {
#ifndef HAVE_GETPGID
int status;
return APR_EINVAL;
return APR_EINVAL;
return APR_EINVAL;
return APR_EINVAL;
return errno;
return APR_EINVAL;
const char *sigdesc;
return status;
0, ap_server_conf,
return APEXIT_CHILDFATAL;
switch (signum) {
case SIGTERM:
case SIGHUP:
case AP_SIG_GRACEFUL:
case SIGKILL:
0, ap_server_conf,
0, ap_server_conf,
APR_WRITE_BLOCK, p);
return rv;
(*pod)->p = p;
return APR_SUCCESS;
return APR_SUCCESS;
return rv;
return AP_NORESTART;
return rv;
return rv;
return APR_SUCCESS;
return rv;
char *srequest;
apr_pool_t *p;
return rv;
if (!lp) {
apr_pool_destroy(p);
return rv;
apr_pool_destroy(p);
return rv;
apr_pool_destroy(p);
return rv;
return rv;
int running = 0;
int have_pid_file = 0;
const char *status;
*exit_status = 0;
otherpid);
if (running) {
if (!running) {
if (!running) {
if (!running) {
if (!running) {
const char *optarg;
int fixed_args;
if (!dash_k_arg) {
if (optarg) {
if (dash_k_arg) {
static int exception_hook_enabled;
const char *arg)
return err;
return NULL;
if (exception_hook_enabled &&
geteuid() != 0 &&
0, ap_server_conf,
return APR_SUCCESS;
#ifndef NO_USE_SIGACTION
#if defined(SA_ONESHOT)
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGFPE
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGFPE
return APR_SUCCESS;