1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @brief Apache Multi-Processing Module library
21 * @defgroup APACHE_CORE_MPM Multi-Processing Module library
22 * @ingroup APACHE_CORE
29 #include "apr_thread_proc.h"
36 The MPM, "multi-processing model" provides an abstraction of the
37 interface with the OS for distributing incoming connections to
38 threads/process for processing. http_main invokes the MPM, and
39 the MPM runs until a shutdown/restart has been indicated.
40 The MPM calls out to the apache core via the ap_process_connection
41 function when a connection arrives.
43 The MPM may or may not be multithreaded. In the event that it is
44 multithreaded, at any instant it guarantees a 1:1 mapping of threads
45 ap_process_connection invocations.
47 Note: In the future it will be possible for ap_process_connection
48 to return to the MPM prior to finishing the entire connection; and
49 the MPM will proceed with asynchronous handling for the connection;
50 in the future the MPM may call ap_process_connection again -- but
51 does not guarantee it will occur on the same thread as the first call.
53 The MPM further guarantees that no asynchronous behaviour such as
54 longjmps and signals will interfere with the user code that is
55 invoked through ap_process_connection. The MPM may reserve some
56 signals for its use (i.e. SIGUSR1), but guarantees that these signals
57 are ignored when executing outside the MPM code itself. (This
58 allows broken user code that does not handle EINTR to function
61 The suggested server restart and stop behaviour will be "graceful".
62 However the MPM may choose to terminate processes when the user
63 requests a non-graceful restart/stop. When this occurs, the MPM kills
64 all threads with extreme prejudice, and destroys the pchild pool.
65 User cleanups registered in the pchild apr_pool_t will be invoked at
66 this point. (This can pose some complications, the user cleanups
67 are asynchronous behaviour not unlike longjmp/signal... but if the
68 admin is asking for a non-graceful shutdown, how much effort should
69 we put into doing it in a nice way?)
72 - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
73 But the preferred method of handling timeouts is to use the
74 timeouts provided by the BUFF abstraction.
75 - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
76 for any of their own processing, it must be restored to SIG_IGN
77 prior to executing or returning to any apache code.
78 TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
82 * This is the function that MPMs must create. This function is responsible
83 * for controlling the parent and child processes. It will run until a
84 * restart/shutdown is indicated.
85 * @param pconf the configuration pool, reset before the config file is read
86 * @param plog the log pool, reset after the config file is read
87 * @param server_conf the global server config.
88 * @return 1 for shutdown 0 otherwise.
89 * @fn int ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf)
91 AP_DECLARE(int) ap_mpm_run(apr_pool_t
*pconf
, apr_pool_t
*plog
, server_rec
*server_conf
);
94 * Spawn a process with privileges that another module has requested
95 * @param r The request_rec of the current request
96 * @param newproc The resulting process handle.
97 * @param progname The program to run
98 * @param const_args the arguments to pass to the new program. The first
99 * one should be the program name.
100 * @param env The new environment apr_table_t for the new process. This
101 * should be a list of NULL-terminated strings.
102 * @param attr the procattr we should use to determine how to create the new
104 * @param p The pool to use.
106 AP_DECLARE(apr_status_t
) ap_os_create_privileged_process(
107 const request_rec
*r
,
109 const char *progname
,
110 const char * const *args
,
111 const char * const *env
,
112 apr_procattr_t
*attr
,
115 /* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED */
116 #define AP_MPMQ_NOT_SUPPORTED 0 /* This value specifies whether */
117 /* an MPM is capable of */
118 /* threading or forking. */
119 #define AP_MPMQ_STATIC 1 /* This value specifies whether */
120 /* an MPM is using a static # */
121 /* threads or daemons. */
122 #define AP_MPMQ_DYNAMIC 2 /* This value specifies whether */
123 /* an MPM is using a dynamic # */
124 /* threads or daemons. */
126 /* Values returned for AP_MPMQ_MPM_STATE */
127 #define AP_MPMQ_STARTING 0
128 #define AP_MPMQ_RUNNING 1
129 #define AP_MPMQ_STOPPING 2
131 #define AP_MPMQ_MAX_DAEMON_USED 1 /* Max # of daemons used so far */
132 #define AP_MPMQ_IS_THREADED 2 /* MPM can do threading */
133 #define AP_MPMQ_IS_FORKED 3 /* MPM can do forking */
134 #define AP_MPMQ_HARD_LIMIT_DAEMONS 4 /* The compiled max # daemons */
135 #define AP_MPMQ_HARD_LIMIT_THREADS 5 /* The compiled max # threads */
136 #define AP_MPMQ_MAX_THREADS 6 /* # of threads/child by config */
137 #define AP_MPMQ_MIN_SPARE_DAEMONS 7 /* Min # of spare daemons */
138 #define AP_MPMQ_MIN_SPARE_THREADS 8 /* Min # of spare threads */
139 #define AP_MPMQ_MAX_SPARE_DAEMONS 9 /* Max # of spare daemons */
140 #define AP_MPMQ_MAX_SPARE_THREADS 10 /* Max # of spare threads */
141 #define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */
142 #define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */
143 #define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */
144 #define AP_MPMQ_IS_ASYNC 14 /* MPM can process async connections */
147 * Query a property of the current MPM.
148 * @param query_code One of APM_MPMQ_*
149 * @param result A location to place the result of the query
150 * @return APR_SUCCESS or APR_ENOTIMPL
151 * @fn int ap_mpm_query(int query_code, int *result)
153 AP_DECLARE(apr_status_t
) ap_mpm_query(int query_code
, int *result
);
156 typedef void (ap_mpm_callback_fn_t
)(void *baton
);
158 /* XXXXXXX: only added support in the Event MPM.... */
159 AP_DECLARE(void) ap_mpm_register_timed_callback(apr_time_t t
,
160 ap_mpm_callback_fn_t
*cbfn
,
163 /* Defining GPROF when compiling uses the moncontrol() function to
164 * disable gprof profiling in the parent, and enable it only for
165 * request processing in children (or in one_process mode). It's
166 * absolutely required to get useful gprof results under linux
167 * because the profile itimers and such are disabled across a
168 * fork(). It's probably useful elsewhere as well.
171 extern void moncontrol(int);
172 #define AP_MONCONTROL(x) moncontrol(x)
174 #define AP_MONCONTROL(x)
177 #if AP_ENABLE_EXCEPTION_HOOK
178 typedef struct ap_exception_info_t
{
181 } ap_exception_info_t
;
183 AP_DECLARE_HOOK(int,fatal_exception
,(ap_exception_info_t
*ei
))
184 #endif /*AP_ENABLE_EXCEPTION_HOOK*/