Apache HTTPD
ap_mpm.h
Go to the documentation of this file.
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
26#ifndef AP_MPM_H
27#define AP_MPM_H
28
29#include "apr_thread_proc.h"
30#include "httpd.h"
31#include "scoreboard.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/*
38 The MPM, "multi-processing model" provides an abstraction of the
39 interface with the OS for distributing incoming connections to
40 threads/process for processing. http_main invokes the MPM, and
41 the MPM runs until a shutdown/restart has been indicated.
42 The MPM calls out to the apache core via the ap_process_connection
43 function when a connection arrives.
44
45 The MPM may or may not be multithreaded. In the event that it is
46 multithreaded, at any instant it guarantees a 1:1 mapping of threads
47 ap_process_connection invocations.
48
49 Note: In the future it will be possible for ap_process_connection
50 to return to the MPM prior to finishing the entire connection; and
51 the MPM will proceed with asynchronous handling for the connection;
52 in the future the MPM may call ap_process_connection again -- but
53 does not guarantee it will occur on the same thread as the first call.
54
55 The MPM further guarantees that no asynchronous behaviour such as
56 longjmps and signals will interfere with the user code that is
57 invoked through ap_process_connection. The MPM may reserve some
58 signals for its use (i.e. SIGUSR1), but guarantees that these signals
59 are ignored when executing outside the MPM code itself. (This
60 allows broken user code that does not handle EINTR to function
61 properly.)
62
63 The suggested server restart and stop behaviour will be "graceful".
64 However the MPM may choose to terminate processes when the user
65 requests a non-graceful restart/stop. When this occurs, the MPM kills
66 all threads with extreme prejudice, and destroys the pchild pool.
67 User cleanups registered in the pchild apr_pool_t will be invoked at
68 this point. (This can pose some complications, the user cleanups
69 are asynchronous behaviour not unlike longjmp/signal... but if the
70 admin is asking for a non-graceful shutdown, how much effort should
71 we put into doing it in a nice way?)
72
73 unix/posix notes:
74 - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
75 But the preferred method of handling timeouts is to use the
76 timeouts provided by the BUFF abstraction.
77 - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
78 for any of their own processing, it must be restored to SIG_IGN
79 prior to executing or returning to any apache code.
80 TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
81*/
82
93AP_DECLARE_HOOK(int, mpm, (apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf))
94
95
109 const request_rec *r,
111 const char *progname,
112 const char * const *args,
113 const char * const *env,
115 apr_pool_t *p);
116
125#define AP_MPMQ_NOT_SUPPORTED 0
128#define AP_MPMQ_STATIC 1
131#define AP_MPMQ_DYNAMIC 2
140#define AP_MPMQ_STARTING 0
141#define AP_MPMQ_RUNNING 1
142#define AP_MPMQ_STOPPING 2
150#define AP_MPMQ_MAX_DAEMON_USED 1
152#define AP_MPMQ_IS_THREADED 2
154#define AP_MPMQ_IS_FORKED 3
156#define AP_MPMQ_HARD_LIMIT_DAEMONS 4
158#define AP_MPMQ_HARD_LIMIT_THREADS 5
160#define AP_MPMQ_MAX_THREADS 6
162#define AP_MPMQ_MIN_SPARE_DAEMONS 7
164#define AP_MPMQ_MIN_SPARE_THREADS 8
166#define AP_MPMQ_MAX_SPARE_DAEMONS 9
168#define AP_MPMQ_MAX_SPARE_THREADS 10
170#define AP_MPMQ_MAX_REQUESTS_DAEMON 11
172#define AP_MPMQ_MAX_DAEMONS 12
174#define AP_MPMQ_MPM_STATE 13
176#define AP_MPMQ_IS_ASYNC 14
178#define AP_MPMQ_GENERATION 15
180#define AP_MPMQ_HAS_SERF 16
194AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
195
198typedef void (ap_mpm_callback_fn_t)(void *baton);
199
200/* only added support in the Event MPM.... check for APR_ENOTIMPL */
203 void *baton);
204
210
231AP_DECLARE_HOOK(void,child_status,(server_rec *s, pid_t pid, ap_generation_t gen,
232 int slot, mpm_child_status state))
233
234
242AP_DECLARE_HOOK(void,end_generation,(server_rec *s, ap_generation_t gen))
243
244/* Defining GPROF when compiling uses the moncontrol() function to
245 * disable gprof profiling in the parent, and enable it only for
246 * request processing in children (or in one_process mode). It's
247 * absolutely required to get useful gprof results under linux
248 * because the profile itimers and such are disabled across a
249 * fork(). It's probably useful elsewhere as well.
250 */
251#ifdef GPROF
252extern void moncontrol(int);
253#define AP_MONCONTROL(x) moncontrol(x)
254#else
255#define AP_MONCONTROL(x)
256#endif
257
258#ifdef AP_ENABLE_EXCEPTION_HOOK
259typedef struct ap_exception_info_t {
260 int sig;
261 pid_t pid;
262} ap_exception_info_t;
263
272AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei))
273#endif /*AP_ENABLE_EXCEPTION_HOOK*/
274
275#ifdef __cplusplus
276}
277#endif
278
279#endif
#define AP_DECLARE(type)
Definition ap_config.h:67
#define AP_DECLARE_HOOK(ret, name, args)
Definition ap_hooks.h:74
APR Thread and Process Library.
static apr_pool_t * pconf
Definition event.c:441
request_rec * r
mpm_child_status
Definition ap_mpm.h:205
apr_status_t ap_os_create_privileged_process(const request_rec *r, apr_proc_t *newproc, const char *progname, const char *const *args, const char *const *env, apr_procattr_t *attr, apr_pool_t *p)
apr_status_t ap_mpm_register_timed_callback(apr_time_t t, ap_mpm_callback_fn_t *cbfn, void *baton)
Definition mpm_common.c:543
void() ap_mpm_callback_fn_t(void *baton)
Definition ap_mpm.h:198
@ MPM_CHILD_EXITED
Definition ap_mpm.h:207
@ MPM_CHILD_STARTED
Definition ap_mpm.h:206
@ MPM_CHILD_LOST_SLOT
Definition ap_mpm.h:208
ap_vhost_iterate_conn_cb void * baton
Definition http_vhost.h:87
int apr_status_t
Definition apr_errno.h:44
apr_array_header_t ** result
char const *const char const *const ** env
apr_interval_time_t t
const char * s
Definition apr_strings.h:95
const char const char *const const char *const apr_procattr_t * attr
int sig
const char const char *const * args
const char * progname
apr_int64_t apr_time_t
Definition apr_time.h:45
apr_status_t ap_mpm_query(int query_code, int *result)
Definition mpm_common.c:421
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
Apache scoreboard library.
int ap_generation_t
Definition scoreboard.h:78
A structure that represents the current request.
Definition httpd.h:845
A structure to store information for each virtual server.
Definition httpd.h:1322
static apr_proc_t newproc
Definition testproc.c:30