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
* @deffunc 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
* predicate indicating if a graceful stop has been requested ...
95
* used by the connection loop
96
* @return 1 if a graceful stop has been requested, 0 otherwise
97
* @deffunc int ap_graceful_stop_signalled(*void)
99
AP_DECLARE(int) ap_graceful_stop_signalled(void);
102
* Spawn a process with privileges that another module has requested
103
* @param r The request_rec of the current request
104
* @param newproc The resulting process handle.
105
* @param progname The program to run
106
* @param const_args the arguments to pass to the new program. The first
107
* one should be the program name.
108
* @param env The new environment apr_table_t for the new process. This
109
* should be a list of NULL-terminated strings.
110
* @param attr the procattr we should use to determine how to create the new
112
* @param p The pool to use.
114
AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
115
const request_rec *r,
117
const char *progname,
118
const char * const *args,
119
const char * const *env,
120
apr_procattr_t *attr,
123
/* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED */
124
#define AP_MPMQ_NOT_SUPPORTED 0 /* This value specifies whether */
125
/* an MPM is capable of */
126
/* threading or forking. */
127
#define AP_MPMQ_STATIC 1 /* This value specifies whether */
128
/* an MPM is using a static # */
129
/* threads or daemons. */
130
#define AP_MPMQ_DYNAMIC 2 /* This value specifies whether */
131
/* an MPM is using a dynamic # */
132
/* threads or daemons. */
134
/* Values returned for AP_MPMQ_MPM_STATE */
135
#define AP_MPMQ_STARTING 0
136
#define AP_MPMQ_RUNNING 1
137
#define AP_MPMQ_STOPPING 2
139
#define AP_MPMQ_MAX_DAEMON_USED 1 /* Max # of daemons used so far */
140
#define AP_MPMQ_IS_THREADED 2 /* MPM can do threading */
141
#define AP_MPMQ_IS_FORKED 3 /* MPM can do forking */
142
#define AP_MPMQ_HARD_LIMIT_DAEMONS 4 /* The compiled max # daemons */
143
#define AP_MPMQ_HARD_LIMIT_THREADS 5 /* The compiled max # threads */
144
#define AP_MPMQ_MAX_THREADS 6 /* # of threads/child by config */
145
#define AP_MPMQ_MIN_SPARE_DAEMONS 7 /* Min # of spare daemons */
146
#define AP_MPMQ_MIN_SPARE_THREADS 8 /* Min # of spare threads */
147
#define AP_MPMQ_MAX_SPARE_DAEMONS 9 /* Max # of spare daemons */
148
#define AP_MPMQ_MAX_SPARE_THREADS 10 /* Max # of spare threads */
149
#define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */
150
#define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */
151
#define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */
152
#define AP_MPMQ_IS_ASYNC 14 /* MPM can process async connections */
155
* Query a property of the current MPM.
156
* @param query_code One of APM_MPMQ_*
157
* @param result A location to place the result of the query
158
* @return APR_SUCCESS or APR_ENOTIMPL
159
* @deffunc int ap_mpm_query(int query_code, int *result)
161
AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
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*/