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"
32
The MPM, "multi-processing model" provides an abstraction of the
33
interface with the OS for distributing incoming connections to
34
threads/process for processing. http_main invokes the MPM, and
35
the MPM runs until a shutdown/restart has been indicated.
36
The MPM calls out to the apache core via the ap_process_connection
37
function when a connection arrives.
39
The MPM may or may not be multithreaded. In the event that it is
40
multithreaded, at any instant it guarantees a 1:1 mapping of threads
41
ap_process_connection invocations.
43
Note: In the future it will be possible for ap_process_connection
44
to return to the MPM prior to finishing the entire connection; and
45
the MPM will proceed with asynchronous handling for the connection;
46
in the future the MPM may call ap_process_connection again -- but
47
does not guarantee it will occur on the same thread as the first call.
49
The MPM further guarantees that no asynchronous behaviour such as
50
longjmps and signals will interfere with the user code that is
51
invoked through ap_process_connection. The MPM may reserve some
52
signals for its use (i.e. SIGUSR1), but guarantees that these signals
53
are ignored when executing outside the MPM code itself. (This
54
allows broken user code that does not handle EINTR to function
57
The suggested server restart and stop behaviour will be "graceful".
58
However the MPM may choose to terminate processes when the user
59
requests a non-graceful restart/stop. When this occurs, the MPM kills
60
all threads with extreme prejudice, and destroys the pchild pool.
61
User cleanups registered in the pchild apr_pool_t will be invoked at
62
this point. (This can pose some complications, the user cleanups
63
are asynchronous behaviour not unlike longjmp/signal... but if the
64
admin is asking for a non-graceful shutdown, how much effort should
65
we put into doing it in a nice way?)
68
- The MPM does not set a SIGALRM handler, user code may use SIGALRM.
69
But the preferred method of handling timeouts is to use the
70
timeouts provided by the BUFF abstraction.
71
- The proper setting for SIGPIPE is SIG_IGN, if user code changes it
72
for any of their own processing, it must be restored to SIG_IGN
73
prior to executing or returning to any apache code.
74
TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
78
* This is the function that MPMs must create. This function is responsible
79
* for controlling the parent and child processes. It will run until a
80
* restart/shutdown is indicated.
81
* @param pconf the configuration pool, reset before the config file is read
82
* @param plog the log pool, reset after the config file is read
83
* @param server_conf the global server config.
84
* @return 1 for shutdown 0 otherwise.
85
* @deffunc int ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf)
87
AP_DECLARE(int) ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf);
90
* predicate indicating if a graceful stop has been requested ...
91
* used by the connection loop
92
* @return 1 if a graceful stop has been requested, 0 otherwise
93
* @deffunc int ap_graceful_stop_signalled(*void)
95
AP_DECLARE(int) ap_graceful_stop_signalled(void);
98
* Spawn a process with privileges that another module has requested
99
* @param r The request_rec of the current request
100
* @param newproc The resulting process handle.
101
* @param progname The program to run
102
* @param const_args the arguments to pass to the new program. The first
103
* one should be the program name.
104
* @param env The new environment apr_table_t for the new process. This
105
* should be a list of NULL-terminated strings.
106
* @param attr the procattr we should use to determine how to create the new
108
* @param p The pool to use.
110
AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
111
const request_rec *r,
113
const char *progname,
114
const char * const *args,
115
const char * const *env,
116
apr_procattr_t *attr,
119
/* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED */
120
#define AP_MPMQ_NOT_SUPPORTED 0 /* This value specifies whether */
121
/* an MPM is capable of */
122
/* threading or forking. */
123
#define AP_MPMQ_STATIC 1 /* This value specifies whether */
124
/* an MPM is using a static # */
125
/* threads or daemons. */
126
#define AP_MPMQ_DYNAMIC 2 /* This value specifies whether */
127
/* an MPM is using a dynamic # */
128
/* threads or daemons. */
130
/* Values returned for AP_MPMQ_MPM_STATE */
131
#define AP_MPMQ_STARTING 0
132
#define AP_MPMQ_RUNNING 1
133
#define AP_MPMQ_STOPPING 2
135
#define AP_MPMQ_MAX_DAEMON_USED 1 /* Max # of daemons used so far */
136
#define AP_MPMQ_IS_THREADED 2 /* MPM can do threading */
137
#define AP_MPMQ_IS_FORKED 3 /* MPM can do forking */
138
#define AP_MPMQ_HARD_LIMIT_DAEMONS 4 /* The compiled max # daemons */
139
#define AP_MPMQ_HARD_LIMIT_THREADS 5 /* The compiled max # threads */
140
#define AP_MPMQ_MAX_THREADS 6 /* # of threads/child by config */
141
#define AP_MPMQ_MIN_SPARE_DAEMONS 7 /* Min # of spare daemons */
142
#define AP_MPMQ_MIN_SPARE_THREADS 8 /* Min # of spare threads */
143
#define AP_MPMQ_MAX_SPARE_DAEMONS 9 /* Max # of spare daemons */
144
#define AP_MPMQ_MAX_SPARE_THREADS 10 /* Max # of spare threads */
145
#define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */
146
#define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */
147
#define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */
148
#define AP_MPMQ_IS_ASYNC 14 /* MPM can process async connections */
151
* Query a property of the current MPM.
152
* @param query_code One of APM_MPMQ_*
153
* @param result A location to place the result of the query
154
* @return APR_SUCCESS or APR_ENOTIMPL
155
* @deffunc int ap_mpm_query(int query_code, int *result)
157
AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
159
/* Defining GPROF when compiling uses the moncontrol() function to
160
* disable gprof profiling in the parent, and enable it only for
161
* request processing in children (or in one_process mode). It's
162
* absolutely required to get useful gprof results under linux
163
* because the profile itimers and such are disabled across a
164
* fork(). It's probably useful elsewhere as well.
167
extern void moncontrol(int);
168
#define AP_MONCONTROL(x) moncontrol(x)
170
#define AP_MONCONTROL(x)
173
#if AP_ENABLE_EXCEPTION_HOOK
174
typedef struct ap_exception_info_t {
177
} ap_exception_info_t;
179
AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei))
180
#endif /*AP_ENABLE_EXCEPTION_HOOK*/