mpm_common.h revision b5435778a96719686b741361cd52af2f3ed3f8e8
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * applicable.
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * Licensed under the Apache License, Version 2.0 (the "License");
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * you may not use this file except in compliance with the License.
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * You may obtain a copy of the License at
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * Unless required by applicable law or agreed to in writing, software
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * distributed under the License is distributed on an "AS IS" BASIS,
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * See the License for the specific language governing permissions and
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * limitations under the License.
b26e4ced91d0ac0eabdce1c505228ccafc65a23fDavid Herrmann/* The purpose of this file is to store the code that MOST mpm's will need
b26e4ced91d0ac0eabdce1c505228ccafc65a23fDavid Herrmann * this does not mean a function only goes into this file if every MPM needs
b26e4ced91d0ac0eabdce1c505228ccafc65a23fDavid Herrmann * it. It means that if a function is needed by more than one MPM, and
b26e4ced91d0ac0eabdce1c505228ccafc65a23fDavid Herrmann * future maintenance would be served by making the code common, then the
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * function belongs here.
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * This is going in src/main because it is not platform specific, it is
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * specific to multi-process servers, but NOT to Unix. Which is why it
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * does not belong in src/os/unix
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @brief Multi-Processing Modules functions
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * @defgroup APACHE_MPM Multi-Processing Modules
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek * @ingroup APACHE
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek/* The maximum length of the queue of pending connections, as defined
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek * by listen(2). Under some systems, it should be increased if you
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek * are experiencing a heavy TCP SYN flood attack.
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek * It defaults to 511 instead of 512 because some systems store it
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is
fa9d4be3f1f4a792b2f3624c2a08fe9cc6ce6e54Zbigniew Jędrzejewski-Szmek * 255 when truncated.
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers/* Signal used to gracefully restart */
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann/* Signal used to gracefully restart (without SIG prefix) */
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers/* Signal used to gracefully restart (as a quoted string) */
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt/* Signal used to gracefully stop */
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers/* Signal used to gracefully stop (without SIG prefix) */
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers/* Signal used to gracefully stop (as a quoted string) */
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Make sure all child processes that have been spawned by the parent process
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * have died. This includes process registered as "other_children".
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @warning This is only defined if the MPM defines
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param terminate Either 1 or 0. If 1, send the child processes SIGTERM
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * each time through the loop. If 0, give the process time to die
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * on its own before signalling it.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @tip This function requires that some macros are defined by the MPM: <pre>
42a9de1c2513aa348df369080cdd941ef4ab00abMartin Pitt * MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * @tip The MPM child processes which are reclaimed are those listed
90e633a7901060063e62bf53948c4c239a9f55d1Jason St. John * in the scoreboard as well as those currently registered via
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * ap_register_extra_mpm_process().
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * Catch any child processes that have been spawned by the parent process
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * which have exited. This includes processes registered as "other_children".
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * @warning This is only defined if the MPM defines
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @tip This function requires that some macros are defined by the MPM: <pre>
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @tip The MPM child processes which are relieved are those listed
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * in the scoreboard as well as those currently registered via
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * ap_register_extra_mpm_process().
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * Tell ap_reclaim_child_processes() and ap_relieve_child_processes() about
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * an MPM child process which has no entry in the scoreboard.
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * @warning This is only defined if the MPM defines
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * @param pid The process id of an MPM child process which should be
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * reclaimed when ap_reclaim_child_processes() is called.
c5b7838ddeae1fcd5c613ea15f04918b945823e5Martin Pitt * @tip If an extra MPM child process terminates prior to calling
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * ap_reclaim_child_processes(), remove it from the list of such processes
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * by calling ap_unregister_extra_mpm_process().
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmannvoid ap_register_extra_mpm_process(pid_t pid);
2dd30e7da94b32df03451df8cf602e9454a376cbKay Sievers * Unregister an MPM child process which was previously registered by a
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * call to ap_register_extra_mpm_process().
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @warning This is only defined if the MPM defines
1e091c1285b59d0fbab58e6e5113ad111bc08794Martin Pitt * AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
1e091c1285b59d0fbab58e6e5113ad111bc08794Martin Pitt * @param pid The process id of an MPM child process which no longer needs to
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * be reclaimed.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @return 1 if the process was found and removed, 0 otherwise
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmannint ap_unregister_extra_mpm_process(pid_t pid);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Determine if any child process has died. If no child process died, then
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * this process sleeps for the amount of time specified by the MPM defined
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * macro SCOREBOARD_MAINTENANCE_INTERVAL.
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @param status The return code if a process has died
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param ret The process id of the process that died
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param p The pool to allocate out of
33e74db2667103e33f7e47277378612dcdbdfaa5Martin Pittvoid ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Log why a child died to the error log, if the child died without the
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * parent signalling it.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param pid The child that has died
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param status The status returned from ap_wait_or_timeout
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @return 0 on success, APEXIT_CHILDFATAL if MPM should terminate
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sieversint ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status);
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers#if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Turn off the nagle algorithm for the specified socket. The nagle algorithm
0c959b39175b126fdb70ae00de37ca6d9c8ca3a1Kay Sievers * says that we should delay sending partial packets in the hopes of getting
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * more data. There are bad interactions between persistent connections and
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Nagle's algorithm that have severe performance penalties.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param s The socket to disable nagle for.
b26e4ced91d0ac0eabdce1c505228ccafc65a23fDavid Herrmann * Convert a username to a numeric ID
fc1ae82cae69d8dbbd9e7a31938810a486fac782Hans de Goede * @param name The name to convert
fc1ae82cae69d8dbbd9e7a31938810a486fac782Hans de Goede * @return The user id corresponding to a name
fc1ae82cae69d8dbbd9e7a31938810a486fac782Hans de Goede * @deffunc uid_t ap_uname2id(const char *name)
fc1ae82cae69d8dbbd9e7a31938810a486fac782Hans de GoedeAP_DECLARE(uid_t) ap_uname2id(const char *name);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Convert a group name to a numeric ID
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @param name The name to convert
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @return The group id corresponding to a name
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @deffunc gid_t ap_gname2id(const char *name)
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers#define AP_MPM_HARD_LIMITS_FILE APACHE_MPM_DIR "/mpm_default.h"
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Open the pipe-of-death. The pipe of death is used to tell all child
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * processes that it is time to die gracefully.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param p The pool to use for allocating the pipe
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay SieversAP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Check the pipe to determine if the process has been signalled to die.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay SieversAP_DECLARE(apr_status_t) ap_mpm_pod_check(ap_pod_t *pod);
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * Close the pipe-of-death
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid HerrmannAP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Write data to the pipe-of-death, signalling that one child process
aba248ee6b1eb10baf3d89eca2ad7569459af6abHans de Goede * should die.
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * @param p The pool to use when allocating any required structures.
aba248ee6b1eb10baf3d89eca2ad7569459af6abHans de GoedeAP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod);
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * Write data to the pipe-of-death, signalling that all child process
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * should die.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param p The pool to use when allocating any required structures.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * @param num The number of child processes to kill
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay SieversAP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * These data members are common to all mpms. Each new mpm
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * should either use the appropriate ap_mpm_set_* function
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * in their command table or create their own for custom or
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * OS specific needs. These should work for most.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * The maximum number of requests each child thread or
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * process handles before dying off
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmannconst char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
24119cf10c7ed58a8fc0851745149dcc6dd5757fStefan Brüns const char *arg);
1f6d36f267186c0e3184bab4c7eca48481c6faabHui Wang * The filename used to store the process id.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversextern const char *ap_pid_fname;
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversconst char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * The name of lockfile used when Apache needs to lock the accept() call.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversextern const char *ap_lock_fname;
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversconst char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * The system mutex implementation to use for the accept mutex.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversextern const char ap_valid_accept_mutex_string[];
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversconst char *ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy,
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann const char *arg);
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann * Set the scorboard file.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversconst char *ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * The directory that the server changes directory to dump core.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversconst char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers * Set the timeout period for a graceful shutdown.
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversconst char *ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
b17de8449c3ce26031d5bb7dec1086b56e51ac9bDavid Herrmann#define AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND \
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay SieversAP_INIT_TAKE1("GracefulShutdownTimeout", ap_mpm_set_graceful_shutdown, NULL, \
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers RSRC_CONF, "Maximum time in seconds to wait for child " \
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers "processes to complete transactions during shutdown")
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversextern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
0787758d26337ec897d9553fe962678fbf0a0962Zbigniew Jędrzejewski-Szmekextern const char *ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy,
0787758d26337ec897d9553fe962678fbf0a0962Zbigniew Jędrzejewski-Szmekextern apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *pconf);
0787758d26337ec897d9553fe962678fbf0a0962Zbigniew Jędrzejewski-Szmekextern apr_status_t ap_fatal_signal_child_setup(server_rec *s);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sieversextern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers const char *arg);
aedc2eddd16e48d468e6ad0aea2caf00c7d37365Kay Sievers#endif /* !APACHE_MPM_COMMON_H */