/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file ap_mpm.h
* @brief Apache Multi-Processing Module library
*
* @defgroup APACHE_CORE_MPM Multi-Processing Module library
* @ingroup APACHE_CORE
* @{
*/
#ifndef AP_MPM_H
#define AP_MPM_H
#include "apr_thread_proc.h"
#include "httpd.h"
#include "scoreboard.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
The MPM, "multi-processing model" provides an abstraction of the
interface with the OS for distributing incoming connections to
The MPM calls out to the apache core via the ap_process_connection
function when a connection arrives.
The MPM may or may not be multithreaded. In the event that it is
multithreaded, at any instant it guarantees a 1:1 mapping of threads
ap_process_connection invocations.
Note: In the future it will be possible for ap_process_connection
to return to the MPM prior to finishing the entire connection; and
the MPM will proceed with asynchronous handling for the connection;
in the future the MPM may call ap_process_connection again -- but
does not guarantee it will occur on the same thread as the first call.
The MPM further guarantees that no asynchronous behaviour such as
longjmps and signals will interfere with the user code that is
invoked through ap_process_connection. The MPM may reserve some
signals for its use (i.e. SIGUSR1), but guarantees that these signals
are ignored when executing outside the MPM code itself. (This
allows broken user code that does not handle EINTR to function
properly.)
The suggested server restart and stop behaviour will be "graceful".
However the MPM may choose to terminate processes when the user
all threads with extreme prejudice, and destroys the pchild pool.
User cleanups registered in the pchild apr_pool_t will be invoked at
this point. (This can pose some complications, the user cleanups
admin is asking for a non-graceful shutdown, how much effort should
we put into doing it in a nice way?)
- The MPM does not set a SIGALRM handler, user code may use SIGALRM.
But the preferred method of handling timeouts is to use the
timeouts provided by the BUFF abstraction.
- The proper setting for SIGPIPE is SIG_IGN, if user code changes it
for any of their own processing, it must be restored to SIG_IGN
prior to executing or returning to any apache code.
TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
*/
/**
* Pass control to the MPM for steady-state processing. It is responsible
* for controlling the parent and child processes. It will run until a
* @param pconf the configuration pool, reset before the config file is read
* @param plog the log pool, reset after the config file is read
* @param server_conf the global server config.
* @return DONE for shutdown OK otherwise.
* @ingroup hooks
*/
/**
* Spawn a process with privileges that another module has requested
* @param r The request_rec of the current request
* @param newproc The resulting process handle.
* @param progname The program to run
* @param args the arguments to pass to the new program. The first
* one should be the program name.
* @param env The new environment apr_table_t for the new process. This
* should be a list of NULL-terminated strings.
* @param attr the procattr we should use to determine how to create the new
* process
* @param p The pool to use.
*/
const request_rec *r,
const char *progname,
const char * const *args,
const char * const *env,
apr_pool_t *p);
/** @defgroup mpmq MPM query
* @{
*/
* @ingroup mpmq
* @{
*/
* MPM is not capable of
* threading or forking. */
* an MPM is using a static
* number of threads or daemons */
* an MPM is using a dynamic
* number of threads or daemons */
/** @} */
/** @defgroup qstate Values returned for AP_MPMQ_MPM_STATE
* @ingroup mpmq
* @{
*/
#define AP_MPMQ_STARTING 0
/** @} */
/** @defgroup qcodes Query codes for ap_mpm_query()
* @ingroup mpmq
* @{
*/
/** Max # of daemons used so far */
/** MPM can do threading */
/** MPM can do forking */
/** The compiled max # daemons */
/** The compiled max # threads */
/** Min # of spare daemons */
/** Min # of spare threads */
/** Max # of spare daemons */
/** Max # of spare threads */
/** Max # of requests per daemon */
/** Max # of daemons by config */
/** starting, running, stopping */
/** MPM can process async connections */
/** MPM generation */
/** MPM can drive serf internally */
/** MPM supports suspending/resuming connections */
/** @} */
/**
* Query a property of the current MPM.
* @param query_code One of AP_MPMQ_*
* @param result A location to place the result of the query
* @return APR_EGENERAL if an mpm-query hook has not been registered;
* APR_SUCCESS or APR_ENOTIMPL otherwise
* @remark The MPM doesn't register the implementing hook until the
* register_hooks hook is called, so modules cannot use ap_mpm_query()
* until after that point.
* @fn int ap_mpm_query(int query_code, int *result)
*/
/** @} */
/* only added support in the Event MPM.... check for APR_ENOTIMPL */
/* only added support in the Event MPM.... check for APR_ENOTIMPL */
void *baton);
/**
* Register a callback on the readability or writability on a group of sockets
* @param s Null-terminated list of sockets
* @param p pool for use between registration and callback
* @param for_read Whether the sockets are monitored for read or writability
* @param cbfn The callback function
* @param baton userdata for the callback function
* @return APR_SUCCESS if all sockets could be added to a pollset,
* APR_ENOTIMPL if no asynch support, or an apr_pollset_add error.
* @remark When activity is found on any 1 socket in the list, all are removed
* from the pollset and only 1 callback is issued.
*/
apr_pool_t *p,
int for_read,
void *baton);
/**
* Register a callback on the readability or writability on a group of sockets, with a timeout
* @param s Null-terminated list of sockets
* @param p pool for use between registration and callback
* @param for_read Whether the sockets are monitored for read or writability
* @param cbfn The callback function
* @param tofn The callback function if the timeout expires
* @param baton userdata for the callback function
* @param timeout timeout for I/O in microseconds, unlimited if <= 0
* @return APR_SUCCESS if all sockets could be added to a pollset,
* APR_ENOTIMPL if no asynch support, or an apr_pollset_add error.
* @remark When activity is found on any 1 socket in the list, all are removed
* from the pollset and only 1 callback is issued.
* @remark For each call, only one of tofn or cbfn will be called, never both.
*/
apr_pool_t *p,
int for_read,
void *baton,
apr_pool_t *p);
typedef enum mpm_child_status {
/**
* Allow a module to remain aware of MPM child process state changes,
* along with the generation and scoreboard slot of the process changing
* state.
*
* With some MPMs (event and worker), an active MPM child process may lose
* its scoreboard slot if the child process is exiting and the scoreboard
* slot is needed by other processes. When this occurs, the hook will be
* called with the MPM_CHILD_LOST_SLOT state.
*
* @param s The main server_rec.
* @param pid The id of the MPM child process.
* @param gen The server generation of that child process.
* @param slot The scoreboard slot number, or -1. It will be -1 when an
* MPM child process exits, and that child had previously lost its
* scoreboard slot.
* @param state One of the mpm_child_status values. Modules should ignore
* unrecognized values.
* @ingroup hooks
*/
/**
* Allow a module to be notified when the last child process of a generation
* exits.
*
* @param s The main server_rec.
* @param gen The server generation which is now completely finished.
* @ingroup hooks
*/
/* Defining GPROF when compiling uses the moncontrol() function to
* disable gprof profiling in the parent, and enable it only for
* request processing in children (or in one_process mode). It's
* absolutely required to get useful gprof results under linux
* because the profile itimers and such are disabled across a
* fork(). It's probably useful elsewhere as well.
*/
#ifdef GPROF
extern void moncontrol(int);
#else
#define AP_MONCONTROL(x)
#endif
#ifdef AP_ENABLE_EXCEPTION_HOOK
typedef struct ap_exception_info_t {
int sig;
/**
* Run the fatal_exception hook for each module; this hook is run
* from some MPMs in the event of a child process crash, if the
* server was built with --enable-exception-hook and the
* EnableExceptionHook directive is On.
* @param ei information about the exception
* @ingroup hooks
*/
#endif /*AP_ENABLE_EXCEPTION_HOOK*/
#ifdef __cplusplus
}
#endif
#endif
/** @} */