Blame include/ap_mpm.h

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * @file  ap_mpm.h
Packit 90a5c9
 * @brief Apache Multi-Processing Module library
Packit 90a5c9
 *
Packit 90a5c9
 * @defgroup APACHE_CORE_MPM Multi-Processing Module library
Packit 90a5c9
 * @ingroup  APACHE_CORE
Packit 90a5c9
 * @{
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#ifndef AP_MPM_H
Packit 90a5c9
#define AP_MPM_H
Packit 90a5c9
Packit 90a5c9
#include "apr_thread_proc.h"
Packit 90a5c9
#include "httpd.h"
Packit 90a5c9
#include "scoreboard.h"
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
extern "C" {
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/*
Packit 90a5c9
    The MPM, "multi-processing model" provides an abstraction of the
Packit 90a5c9
    interface with the OS for distributing incoming connections to
Packit 90a5c9
    threads/process for processing.  http_main invokes the MPM, and
Packit 90a5c9
    the MPM runs until a shutdown/restart has been indicated.
Packit 90a5c9
    The MPM calls out to the apache core via the ap_process_connection
Packit 90a5c9
    function when a connection arrives.
Packit 90a5c9
Packit 90a5c9
    The MPM may or may not be multithreaded.  In the event that it is
Packit 90a5c9
    multithreaded, at any instant it guarantees a 1:1 mapping of threads
Packit 90a5c9
    ap_process_connection invocations.
Packit 90a5c9
Packit 90a5c9
    Note: In the future it will be possible for ap_process_connection
Packit 90a5c9
    to return to the MPM prior to finishing the entire connection; and
Packit 90a5c9
    the MPM will proceed with asynchronous handling for the connection;
Packit 90a5c9
    in the future the MPM may call ap_process_connection again -- but
Packit 90a5c9
    does not guarantee it will occur on the same thread as the first call.
Packit 90a5c9
Packit 90a5c9
    The MPM further guarantees that no asynchronous behaviour such as
Packit 90a5c9
    longjmps and signals will interfere with the user code that is
Packit 90a5c9
    invoked through ap_process_connection.  The MPM may reserve some
Packit 90a5c9
    signals for its use (i.e. SIGUSR1), but guarantees that these signals
Packit 90a5c9
    are ignored when executing outside the MPM code itself.  (This
Packit 90a5c9
    allows broken user code that does not handle EINTR to function
Packit 90a5c9
    properly.)
Packit 90a5c9
Packit 90a5c9
    The suggested server restart and stop behaviour will be "graceful".
Packit 90a5c9
    However the MPM may choose to terminate processes when the user
Packit 90a5c9
    requests a non-graceful restart/stop.  When this occurs, the MPM kills
Packit 90a5c9
    all threads with extreme prejudice, and destroys the pchild pool.
Packit 90a5c9
    User cleanups registered in the pchild apr_pool_t will be invoked at
Packit 90a5c9
    this point.  (This can pose some complications, the user cleanups
Packit 90a5c9
    are asynchronous behaviour not unlike longjmp/signal... but if the
Packit 90a5c9
    admin is asking for a non-graceful shutdown, how much effort should
Packit 90a5c9
    we put into doing it in a nice way?)
Packit 90a5c9
Packit 90a5c9
    unix/posix notes:
Packit 90a5c9
    - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
Packit 90a5c9
        But the preferred method of handling timeouts is to use the
Packit 90a5c9
        timeouts provided by the BUFF abstraction.
Packit 90a5c9
    - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
Packit 90a5c9
        for any of their own processing, it must be restored to SIG_IGN
Packit 90a5c9
        prior to executing or returning to any apache code.
Packit 90a5c9
    TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
Packit 90a5c9
*/
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Pass control to the MPM for steady-state processing.  It is responsible
Packit 90a5c9
 * for controlling the parent and child processes.  It will run until a
Packit 90a5c9
 * restart/shutdown is indicated.
Packit 90a5c9
 * @param pconf the configuration pool, reset before the config file is read
Packit 90a5c9
 * @param plog the log pool, reset after the config file is read
Packit 90a5c9
 * @param server_conf the global server config.
Packit 90a5c9
 * @return DONE for shutdown OK otherwise.
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE_HOOK(int, mpm, (apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf))
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Spawn a process with privileges that another module has requested
Packit 90a5c9
 * @param r The request_rec of the current request
Packit 90a5c9
 * @param newproc The resulting process handle.
Packit 90a5c9
 * @param progname The program to run
Packit 90a5c9
 * @param args the arguments to pass to the new program.  The first
Packit 90a5c9
 *                   one should be the program name.
Packit 90a5c9
 * @param env The new environment apr_table_t for the new process.  This
Packit 90a5c9
 *            should be a list of NULL-terminated strings.
Packit 90a5c9
 * @param attr the procattr we should use to determine how to create the new
Packit 90a5c9
 *         process
Packit 90a5c9
 * @param p The pool to use.
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
Packit 90a5c9
    const request_rec *r,
Packit 90a5c9
    apr_proc_t *newproc,
Packit 90a5c9
    const char *progname,
Packit 90a5c9
    const char * const *args,
Packit 90a5c9
    const char * const *env,
Packit 90a5c9
    apr_procattr_t *attr,
Packit 90a5c9
    apr_pool_t *p);
Packit 90a5c9
Packit 90a5c9
/* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED        */
Packit 90a5c9
#define AP_MPMQ_NOT_SUPPORTED      0  /* This value specifies that an */
Packit 90a5c9
                                      /* MPM is not capable of        */
Packit 90a5c9
                                      /* threading or forking.        */
Packit 90a5c9
#define AP_MPMQ_STATIC             1  /* This value specifies that    */
Packit 90a5c9
                                      /* an MPM is using a static     */
Packit 90a5c9
                                      /* number of threads or daemons */
Packit 90a5c9
#define AP_MPMQ_DYNAMIC            2  /* This value specifies that    */
Packit 90a5c9
                                      /* an MPM is using a dynamic    */
Packit 90a5c9
                                      /* number of threads or daemons */
Packit 90a5c9
Packit 90a5c9
/* Values returned for AP_MPMQ_MPM_STATE */
Packit 90a5c9
#define AP_MPMQ_STARTING              0
Packit 90a5c9
#define AP_MPMQ_RUNNING               1
Packit 90a5c9
#define AP_MPMQ_STOPPING              2
Packit 90a5c9
Packit 90a5c9
#define AP_MPMQ_MAX_DAEMON_USED       1  /* Max # of daemons used so far */
Packit 90a5c9
#define AP_MPMQ_IS_THREADED           2  /* MPM can do threading         */
Packit 90a5c9
#define AP_MPMQ_IS_FORKED             3  /* MPM can do forking           */
Packit 90a5c9
#define AP_MPMQ_HARD_LIMIT_DAEMONS    4  /* The compiled max # daemons   */
Packit 90a5c9
#define AP_MPMQ_HARD_LIMIT_THREADS    5  /* The compiled max # threads   */
Packit 90a5c9
#define AP_MPMQ_MAX_THREADS           6  /* # of threads/child by config */
Packit 90a5c9
#define AP_MPMQ_MIN_SPARE_DAEMONS     7  /* Min # of spare daemons       */
Packit 90a5c9
#define AP_MPMQ_MIN_SPARE_THREADS     8  /* Min # of spare threads       */
Packit 90a5c9
#define AP_MPMQ_MAX_SPARE_DAEMONS     9  /* Max # of spare daemons       */
Packit 90a5c9
#define AP_MPMQ_MAX_SPARE_THREADS    10  /* Max # of spare threads       */
Packit 90a5c9
#define AP_MPMQ_MAX_REQUESTS_DAEMON  11  /* Max # of requests per daemon */
Packit 90a5c9
#define AP_MPMQ_MAX_DAEMONS          12  /* Max # of daemons by config   */
Packit 90a5c9
#define AP_MPMQ_MPM_STATE            13  /* starting, running, stopping  */
Packit 90a5c9
#define AP_MPMQ_IS_ASYNC             14  /* MPM can process async connections  */
Packit 90a5c9
#define AP_MPMQ_GENERATION           15  /* MPM generation */
Packit 90a5c9
#define AP_MPMQ_HAS_SERF             16  /* MPM can drive serf internally  */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Query a property of the current MPM.
Packit 90a5c9
 * @param query_code One of APM_MPMQ_*
Packit 90a5c9
 * @param result A location to place the result of the query
Packit 90a5c9
 * @return APR_EGENERAL if an mpm-query hook has not been registered;
Packit 90a5c9
 * APR_SUCCESS or APR_ENOTIMPL otherwise
Packit 90a5c9
 * @remark The MPM doesn't register the implementing hook until the
Packit 90a5c9
 * register_hooks hook is called, so modules cannot use ap_mpm_query()
Packit 90a5c9
 * until after that point.
Packit 90a5c9
 * @fn int ap_mpm_query(int query_code, int *result)
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
typedef void (ap_mpm_callback_fn_t)(void *baton);
Packit 90a5c9
Packit 90a5c9
/* only added support in the Event MPM....  check for APR_ENOTIMPL */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_mpm_register_timed_callback(apr_time_t t,
Packit 90a5c9
                                                       ap_mpm_callback_fn_t *cbfn,
Packit 90a5c9
                                                       void *baton);
Packit 90a5c9
Packit 90a5c9
typedef enum mpm_child_status {
Packit 90a5c9
    MPM_CHILD_STARTED,
Packit 90a5c9
    MPM_CHILD_EXITED,
Packit 90a5c9
    MPM_CHILD_LOST_SLOT
Packit 90a5c9
} mpm_child_status;
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Allow a module to remain aware of MPM child process state changes,
Packit 90a5c9
 * along with the generation and scoreboard slot of the process changing
Packit 90a5c9
 * state.
Packit 90a5c9
 *
Packit 90a5c9
 * With some MPMs (event and worker), an active MPM child process may lose
Packit 90a5c9
 * its scoreboard slot if the child process is exiting and the scoreboard
Packit 90a5c9
 * slot is needed by other processes.  When this occurs, the hook will be
Packit 90a5c9
 * called with the MPM_CHILD_LOST_SLOT state.
Packit 90a5c9
 *
Packit 90a5c9
 * @param s The main server_rec.
Packit 90a5c9
 * @param pid The id of the MPM child process.
Packit 90a5c9
 * @param gen The server generation of that child process.
Packit 90a5c9
 * @param slot The scoreboard slot number, or -1.  It will be -1 when an
Packit 90a5c9
 * MPM child process exits, and that child had previously lost its
Packit 90a5c9
 * scoreboard slot.
Packit 90a5c9
 * @param state One of the mpm_child_status values.  Modules should ignore
Packit 90a5c9
 * unrecognized values.
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE_HOOK(void,child_status,(server_rec *s, pid_t pid, ap_generation_t gen,
Packit 90a5c9
                                   int slot, mpm_child_status state))
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Allow a module to be notified when the last child process of a generation
Packit 90a5c9
 * exits.
Packit 90a5c9
 *
Packit 90a5c9
 * @param s The main server_rec.
Packit 90a5c9
 * @param gen The server generation which is now completely finished.
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE_HOOK(void,end_generation,(server_rec *s, ap_generation_t gen))
Packit 90a5c9
Packit 90a5c9
/* Defining GPROF when compiling uses the moncontrol() function to
Packit 90a5c9
 * disable gprof profiling in the parent, and enable it only for
Packit 90a5c9
 * request processing in children (or in one_process mode).  It's
Packit 90a5c9
 * absolutely required to get useful gprof results under linux
Packit 90a5c9
 * because the profile itimers and such are disabled across a
Packit 90a5c9
 * fork().  It's probably useful elsewhere as well.
Packit 90a5c9
 */
Packit 90a5c9
#ifdef GPROF
Packit 90a5c9
extern void moncontrol(int);
Packit 90a5c9
#define AP_MONCONTROL(x) moncontrol(x)
Packit 90a5c9
#else
Packit 90a5c9
#define AP_MONCONTROL(x)
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#ifdef AP_ENABLE_EXCEPTION_HOOK
Packit 90a5c9
typedef struct ap_exception_info_t {
Packit 90a5c9
    int sig;
Packit 90a5c9
    pid_t pid;
Packit 90a5c9
} ap_exception_info_t;
Packit 90a5c9
Packit 90a5c9
AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei))
Packit 90a5c9
#endif /*AP_ENABLE_EXCEPTION_HOOK*/
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
}
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#endif
Packit 90a5c9
/** @} */