mpm_common.h revision fda1a61aacb6950953b7393b845b0639d8e87359
b66914021bd429f41311d2909a7e9289866da7fdnd/* Licensed to the Apache Software Foundation (ASF) under one or more
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * contributor license agreements. See the NOTICE file distributed with
9963f91528694fb21e93da8584c31f226c6de97akess * this work for additional information regarding copyright ownership.
b66914021bd429f41311d2909a7e9289866da7fdnd * The ASF licenses this file to You under the Apache License, Version 2.0
b66914021bd429f41311d2909a7e9289866da7fdnd * (the "License"); you may not use this file except in compliance with
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz * the License. You may obtain a copy of the License at
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz *
b66914021bd429f41311d2909a7e9289866da7fdnd * http://www.apache.org/licenses/LICENSE-2.0
b66914021bd429f41311d2909a7e9289866da7fdnd *
b66914021bd429f41311d2909a7e9289866da7fdnd * Unless required by applicable law or agreed to in writing, software
b66914021bd429f41311d2909a7e9289866da7fdnd * distributed under the License is distributed on an "AS IS" BASIS,
b66914021bd429f41311d2909a7e9289866da7fdnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b66914021bd429f41311d2909a7e9289866da7fdnd * See the License for the specific language governing permissions and
b66914021bd429f41311d2909a7e9289866da7fdnd * limitations under the License.
b66914021bd429f41311d2909a7e9289866da7fdnd */
b66914021bd429f41311d2909a7e9289866da7fdnd
b66914021bd429f41311d2909a7e9289866da7fdnd/* The purpose of this file is to store the code that MOST mpm's will need
b66914021bd429f41311d2909a7e9289866da7fdnd * this does not mean a function only goes into this file if every MPM needs
b66914021bd429f41311d2909a7e9289866da7fdnd * it. It means that if a function is needed by more than one MPM, and
b66914021bd429f41311d2909a7e9289866da7fdnd * future maintenance would be served by making the code common, then the
b66914021bd429f41311d2909a7e9289866da7fdnd * function belongs here.
eed2a23d9b5986937f1e2b1c120be97744508a72nd *
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This is going in src/main because it is not platform specific, it is
eed2a23d9b5986937f1e2b1c120be97744508a72nd * specific to multi-process servers, but NOT to Unix. Which is why it
eed2a23d9b5986937f1e2b1c120be97744508a72nd * does not belong in src/os/unix
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/**
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @file mpm_common.h
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @brief Multi-Processing Modules functions
eed2a23d9b5986937f1e2b1c120be97744508a72nd *
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @defgroup APACHE_MPM Multi-Processing Modules
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @ingroup APACHE
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @{
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd#ifndef APACHE_MPM_COMMON_H
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define APACHE_MPM_COMMON_H
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd#include "ap_config.h"
eed2a23d9b5986937f1e2b1c120be97744508a72nd#include "ap_mpm.h"
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd#if APR_HAVE_NETINET_TCP_H
eed2a23d9b5986937f1e2b1c120be97744508a72nd#include <netinet/tcp.h> /* for TCP_NODELAY */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#endif
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd#include "apr_proc_mutex.h"
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd#ifdef __cplusplus
eed2a23d9b5986937f1e2b1c120be97744508a72ndextern "C" {
eed2a23d9b5986937f1e2b1c120be97744508a72nd#endif
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* The maximum length of the queue of pending connections, as defined
eed2a23d9b5986937f1e2b1c120be97744508a72nd * by listen(2). Under some systems, it should be increased if you
eed2a23d9b5986937f1e2b1c120be97744508a72nd * are experiencing a heavy TCP SYN flood attack.
eed2a23d9b5986937f1e2b1c120be97744508a72nd *
eed2a23d9b5986937f1e2b1c120be97744508a72nd * It defaults to 511 instead of 512 because some systems store it
eed2a23d9b5986937f1e2b1c120be97744508a72nd * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is
eed2a23d9b5986937f1e2b1c120be97744508a72nd * 255 when truncated.
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#ifndef DEFAULT_LISTENBACKLOG
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define DEFAULT_LISTENBACKLOG 511
eed2a23d9b5986937f1e2b1c120be97744508a72nd#endif
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Signal used to gracefully restart */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define AP_SIG_GRACEFUL SIGUSR1
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Signal used to gracefully restart (without SIG prefix) */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define AP_SIG_GRACEFUL_SHORT USR1
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Signal used to gracefully restart (as a quoted string) */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define AP_SIG_GRACEFUL_STRING "SIGUSR1"
bcf004854091600aa279525d6772e1827114d39dnd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Signal used to gracefully stop */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define AP_SIG_GRACEFUL_STOP SIGWINCH
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Signal used to gracefully stop (without SIG prefix) */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define AP_SIG_GRACEFUL_STOP_SHORT WINCH
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Signal used to gracefully stop (as a quoted string) */
eed2a23d9b5986937f1e2b1c120be97744508a72nd#define AP_SIG_GRACEFUL_STOP_STRING "SIGWINCH"
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/**
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Make sure all child processes that have been spawned by the parent process
eed2a23d9b5986937f1e2b1c120be97744508a72nd * have died. This includes process registered as "other_children".
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @param terminate Either 1 or 0. If 1, send the child processes SIGTERM
eed2a23d9b5986937f1e2b1c120be97744508a72nd * each time through the loop. If 0, give the process time to die
eed2a23d9b5986937f1e2b1c120be97744508a72nd * on its own before signalling it.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @tip This function requires that some macros are defined by the MPM: <pre>
eed2a23d9b5986937f1e2b1c120be97744508a72nd * MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
eed2a23d9b5986937f1e2b1c120be97744508a72nd * MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
eed2a23d9b5986937f1e2b1c120be97744508a72nd * </pre>
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @tip The MPM child processes which are reclaimed are those listed
eed2a23d9b5986937f1e2b1c120be97744508a72nd * in the scoreboard as well as those currently registered via
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ap_register_extra_mpm_process().
9963f91528694fb21e93da8584c31f226c6de97akess */
bcf004854091600aa279525d6772e1827114d39dndvoid ap_reclaim_child_processes(int terminate);
9963f91528694fb21e93da8584c31f226c6de97akess
eed2a23d9b5986937f1e2b1c120be97744508a72nd/**
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Catch any child processes that have been spawned by the parent process
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * which have exited. This includes processes registered as "other_children".
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * @tip This function requires that some macros are defined by the MPM: <pre>
eed2a23d9b5986937f1e2b1c120be97744508a72nd * MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
eed2a23d9b5986937f1e2b1c120be97744508a72nd * MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
eed2a23d9b5986937f1e2b1c120be97744508a72nd * </pre>
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @tip The MPM child processes which are relieved are those listed
eed2a23d9b5986937f1e2b1c120be97744508a72nd * in the scoreboard as well as those currently registered via
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ap_register_extra_mpm_process().
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
eed2a23d9b5986937f1e2b1c120be97744508a72ndvoid ap_relieve_child_processes(void);
eed2a23d9b5986937f1e2b1c120be97744508a72nd
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd/**
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Tell ap_reclaim_child_processes() and ap_relieve_child_processes() about
eed2a23d9b5986937f1e2b1c120be97744508a72nd * an MPM child process which has no entry in the scoreboard.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @param pid The process id of an MPM child process which should be
eed2a23d9b5986937f1e2b1c120be97744508a72nd * reclaimed when ap_reclaim_child_processes() is called.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @tip If an extra MPM child process terminates prior to calling
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ap_reclaim_child_processes(), remove it from the list of such processes
eed2a23d9b5986937f1e2b1c120be97744508a72nd * by calling ap_unregister_extra_mpm_process().
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
eed2a23d9b5986937f1e2b1c120be97744508a72ndvoid ap_register_extra_mpm_process(pid_t pid);
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/**
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Unregister an MPM child process which was previously registered by a
eed2a23d9b5986937f1e2b1c120be97744508a72nd * call to ap_register_extra_mpm_process().
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @param pid The process id of an MPM child process which no longer needs to
eed2a23d9b5986937f1e2b1c120be97744508a72nd * be reclaimed.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * @return 1 if the process was found and removed, 0 otherwise
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
eed2a23d9b5986937f1e2b1c120be97744508a72ndint ap_unregister_extra_mpm_process(pid_t pid);
/**
* Safely signal an MPM child process, if the process is in the
* current process group. Otherwise fail.
* @param pid the process id of a child process to signal
* @param sig the signal number to send
* @return APR_SUCCESS if signal is sent, otherwise an error as per kill(3);
* APR_EINVAL is returned if passed either an invalid (< 1) pid, or if
* the pid is not in the current process group
*/
apr_status_t ap_mpm_safe_kill(pid_t pid, int sig);
/**
* Determine if any child process has died. If no child process died, then
* this process sleeps for the amount of time specified by the MPM defined
* macro SCOREBOARD_MAINTENANCE_INTERVAL.
* @param status The return code if a process has died
* @param ret The process id of the process that died
* @param p The pool to allocate out of
*/
void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret,
apr_pool_t *p);
/**
* Log why a child died to the error log, if the child died without the
* parent signalling it.
* @param pid The child that has died
* @param status The status returned from ap_wait_or_timeout
* @return 0 on success, APEXIT_CHILDFATAL if MPM should terminate
*/
int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status);
#if defined(TCP_NODELAY)
/**
* Turn off the nagle algorithm for the specified socket. The nagle algorithm
* says that we should delay sending partial packets in the hopes of getting
* more data. There are bad interactions between persistent connections and
* Nagle's algorithm that have severe performance penalties.
* @param s The socket to disable nagle for.
*/
void ap_sock_disable_nagle(apr_socket_t *s);
#else
#define ap_sock_disable_nagle(s) /* NOOP */
#endif
#ifdef HAVE_GETPWNAM
/**
* Convert a username to a numeric ID
* @param name The name to convert
* @return The user id corresponding to a name
* @fn uid_t ap_uname2id(const char *name)
*/
AP_DECLARE(uid_t) ap_uname2id(const char *name);
#endif
#ifdef HAVE_GETGRNAM
/**
* Convert a group name to a numeric ID
* @param name The name to convert
* @return The group id corresponding to a name
* @fn gid_t ap_gname2id(const char *name)
*/
AP_DECLARE(gid_t) ap_gname2id(const char *name);
#endif
typedef struct ap_pod_t ap_pod_t;
struct ap_pod_t {
apr_file_t *pod_in;
apr_file_t *pod_out;
apr_pool_t *p;
};
/**
* Open the pipe-of-death. The pipe of death is used to tell all child
* processes that it is time to die gracefully.
* @param p The pool to use for allocating the pipe
*/
AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod);
/**
* Check the pipe to determine if the process has been signalled to die.
*/
AP_DECLARE(apr_status_t) ap_mpm_pod_check(ap_pod_t *pod);
/**
* Close the pipe-of-death
*/
AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod);
/**
* Write data to the pipe-of-death, signalling that one child process
* should die.
* @param p The pool to use when allocating any required structures.
*/
AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod);
/**
* Write data to the pipe-of-death, signalling that all child process
* should die.
* @param p The pool to use when allocating any required structures.
* @param num The number of child processes to kill
*/
AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num);
/*
* These data members are common to all mpms. Each new mpm
* should either use the appropriate ap_mpm_set_* function
* in their command table or create their own for custom or
* OS specific needs. These should work for most.
*/
/**
* The maximum number of requests each child thread or
* process handles before dying off
*/
extern int ap_max_requests_per_child;
const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
const char *arg);
/**
* The filename used to store the process id.
*/
extern const char *ap_pid_fname;
const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
const char *arg);
/**
* The name of lockfile used when Apache needs to lock the accept() call.
*/
extern const char *ap_lock_fname;
const char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
const char *arg);
/**
* The system mutex implementation to use for the accept mutex.
*/
extern apr_lockmech_e ap_accept_lock_mech;
const char *ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy,
const char *arg);
/*
* Set the scorboard file.
*/
const char *ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy,
const char *arg);
/*
* The directory that the server changes directory to dump core.
*/
extern char ap_coredump_dir[MAX_STRING_LEN];
extern int ap_coredumpdir_configured;
const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
const char *arg);
/**
* Set the timeout period for a graceful shutdown.
*/
extern int ap_graceful_shutdown_timeout;
const char *ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy,
const char *arg);
#define AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND \
AP_INIT_TAKE1("GracefulShutdownTimeout", ap_mpm_set_graceful_shutdown, NULL, \
RSRC_CONF, "Maximum time in seconds to wait for child " \
"processes to complete transactions during shutdown")
int ap_signal_server(int *, apr_pool_t *);
void ap_mpm_rewrite_args(process_rec *);
extern apr_uint32_t ap_max_mem_free;
extern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
const char *arg);
extern apr_size_t ap_thread_stacksize;
extern const char *ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy,
const char *arg);
extern apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *pconf);
extern apr_status_t ap_fatal_signal_child_setup(server_rec *s);
#if AP_ENABLE_EXCEPTION_HOOK
extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
const char *arg);
#endif
AP_DECLARE(pid_t) ap_mpm_get_child_pid(int childnum);
AP_DECLARE(apr_status_t) ap_mpm_note_child_killed(int childnum);
AP_DECLARE_HOOK(int,monitor,(apr_pool_t *p))
/* register modules that undertake to manage system security */
AP_DECLARE(int) ap_sys_privileges_handlers(int inc);
AP_DECLARE_HOOK(int, drop_privileges, (apr_pool_t * pchild, server_rec * s))
/* pass control to the MPM */
AP_DECLARE_HOOK(int, mpm, (apr_pool_t *pconf, apr_pool_t *plog, server_rec *s))
/* implement the mpm query function */
AP_DECLARE_HOOK(apr_status_t, mpm_query, (int query_code, int *result))
/* get pid of child by index */
AP_DECLARE_HOOK(pid_t, mpm_get_child_pid, (int childnum))
/* child specified by index has been killed */
AP_DECLARE_HOOK(apr_status_t, mpm_note_child_killed, (int childnum))
/* register the specified callback */
AP_DECLARE_HOOK(apr_status_t, mpm_register_timed_callback,
(apr_time_t t, ap_mpm_callback_fn_t *cbfn, void *baton))
/* get MPM name */
AP_DECLARE_HOOK(const char *,mpm_get_name,(void))
#ifdef __cplusplus
}
#endif
#endif /* !APACHE_MPM_COMMON_H */
/** @} */