Apache2
mpm_common.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 
17 /* The purpose of this file is to store the code that MOST mpm's will need
18  * this does not mean a function only goes into this file if every MPM needs
19  * it. It means that if a function is needed by more than one MPM, and
20  * future maintenance would be served by making the code common, then the
21  * function belongs here.
22  *
23  * This is going in src/main because it is not platform specific, it is
24  * specific to multi-process servers, but NOT to Unix. Which is why it
25  * does not belong in src/os/unix
26  */
27 
37 #ifndef APACHE_MPM_COMMON_H
38 #define APACHE_MPM_COMMON_H
39 
40 #include "ap_config.h"
41 #include "ap_mpm.h"
42 #include "scoreboard.h"
43 
44 #if APR_HAVE_NETINET_TCP_H
45 #include <netinet/tcp.h> /* for TCP_NODELAY */
46 #endif
47 
48 #include "apr_proc_mutex.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /* The maximum length of the queue of pending connections, as defined
55  * by listen(2). Under some systems, it should be increased if you
56  * are experiencing a heavy TCP SYN flood attack.
57  *
58  * It defaults to 511 instead of 512 because some systems store it
59  * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is
60  * 255 when truncated.
61  */
62 #ifndef DEFAULT_LISTENBACKLOG
63 #define DEFAULT_LISTENBACKLOG 511
64 #endif
65 
66 /* Signal used to gracefully restart */
67 #define AP_SIG_GRACEFUL SIGUSR1
68 
69 /* Signal used to gracefully restart (without SIG prefix) */
70 #define AP_SIG_GRACEFUL_SHORT USR1
71 
72 /* Signal used to gracefully restart (as a quoted string) */
73 #define AP_SIG_GRACEFUL_STRING "SIGUSR1"
74 
75 /* Signal used to gracefully stop */
76 #define AP_SIG_GRACEFUL_STOP SIGWINCH
77 
78 /* Signal used to gracefully stop (without SIG prefix) */
79 #define AP_SIG_GRACEFUL_STOP_SHORT WINCH
80 
81 /* Signal used to gracefully stop (as a quoted string) */
82 #define AP_SIG_GRACEFUL_STOP_STRING "SIGWINCH"
83 
89 typedef void ap_reclaim_callback_fn_t(int childnum, pid_t pid,
90  ap_generation_t gen);
91 
92 #if (!defined(WIN32) && !defined(NETWARE)) || defined(DOXYGEN)
107  ap_reclaim_callback_fn_t *mpm_callback);
108 
120 
133 
143 
154 
164 
167 
168 #endif /* (!WIN32 && !NETWARE) || DOXYGEN */
169 
175 
187  apr_proc_t *ret, apr_pool_t *p,
188  server_rec *s);
189 
190 #if defined(TCP_NODELAY)
199 #else
200 #define ap_sock_disable_nagle(s) /* NOOP */
201 #endif
202 
203 #ifdef HAVE_GETPWNAM
210 AP_DECLARE(uid_t) ap_uname2id(const char *name);
211 #endif
212 
213 #ifdef HAVE_GETGRNAM
220 AP_DECLARE(gid_t) ap_gname2id(const char *name);
221 #endif
222 
223 #ifndef HAVE_INITGROUPS
233 int initgroups(const char *name, gid_t basegid);
234 #endif
235 
236 #if (!defined(WIN32) && !defined(NETWARE)) || defined(DOXYGEN)
237 
238 typedef struct ap_pod_t ap_pod_t;
239 
240 struct ap_pod_t {
244 };
245 
253 
258 
265 
272 
279 AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num);
280 
281 #define AP_MPM_PODX_RESTART_CHAR '$'
282 #define AP_MPM_PODX_GRACEFUL_CHAR '!'
283 
285 
292 
297 
304 
312  ap_podx_restart_t graceful);
313 
322  ap_podx_restart_t graceful);
323 
324 #endif /* (!WIN32 && !NETWARE) || DOXYGEN */
325 
330 AP_DECLARE(const char *) ap_check_mpm(void);
331 
332 /*
333  * These data members are common to all mpms. Each new mpm
334  * should either use the appropriate ap_mpm_set_* function
335  * in their command table or create their own for custom or
336  * OS specific needs. These should work for most.
337  */
338 
344 const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
345  const char *arg);
346 
350 AP_DECLARE_DATA extern const char *ap_pid_fname;
351 const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
352  const char *arg);
354 
355 /*
356  * The directory that the server changes directory to dump core.
357  */
360 const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
361  const char *arg);
362 
367 AP_DECLARE(const char *)ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy,
368  const char *arg);
369 #define AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND \
370 AP_INIT_TAKE1("GracefulShutdownTimeout", ap_mpm_set_graceful_shutdown, NULL, \
371  RSRC_CONF, "Maximum time in seconds to wait for child " \
372  "processes to complete transactions during shutdown")
373 
374 
377 
379 extern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
380  const char *arg);
381 
383 extern const char *ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy,
384  const char *arg);
385 
386 /* core's implementation of child_status hook */
387 extern void ap_core_child_status(server_rec *s, pid_t pid, ap_generation_t gen,
388  int slot, mpm_child_status status);
389 
390 #if defined(AP_ENABLE_EXCEPTION_HOOK) && AP_ENABLE_EXCEPTION_HOOK
391 extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
392  const char *arg);
393 #endif
394 
405 
406 /* register modules that undertake to manage system security */
409 
416 AP_DECLARE_HOOK(int, mpm_query, (int query_code, int *result, apr_status_t *rv))
417 
423  (apr_time_t t, ap_mpm_callback_fn_t *cbfn, void *baton))
424 
430  (apr_pool_t *p, const apr_array_header_t *pds,
431  ap_mpm_callback_fn_t *cbfn, void *baton))
432 
433 /* register the specified callback, with timeout
434  * @ingroup hooks
435  *
436  */
438  (apr_pool_t *p, const apr_array_header_t *pds,
440  void *baton, apr_time_t timeout))
441 
446 
451 AP_DECLARE_HOOK(const char *,mpm_get_name,(void))
452 
462 
470 
492 
513 
523  (apr_pool_t *pchild, int graceful))
524 
537  (apr_pool_t *pchild, int graceful))
538 
539 /* mutex type string for accept mutex, if any; MPMs should use the
540  * same mutex type for ease of configuration
541  */
542 #define AP_ACCEPT_MUTEX_TYPE "mpm-accept"
543 
544 /* internal pre-config logic for MPM-related settings, callable only from
545  * core's pre-config hook
546  */
548 
549 #ifdef __cplusplus
550 }
551 #endif
552 
553 #endif /* !APACHE_MPM_COMMON_H */
Symbol export macros and hook functions.
#define AP_DECLARE_HOOK(ret, name, args)
Definition: ap_hooks.h:74
Apache Multi-Processing Module library.
APR Process Locking Routines.
#define MAX_STRING_LEN
Definition: httpd.h:305
mpm_child_status
Definition: ap_mpm.h:255
void() ap_mpm_callback_fn_t(void *baton)
Definition: ap_mpm.h:202
gid_t ap_gname2id(const char *name)
void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, apr_pool_t *p, server_rec *s)
const char * ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, const char *arg)
void mpm_common_pre_config(apr_pool_t *pconf)
apr_status_t mpm_register_poll_callback_timeout(apr_pool_t *p, const apr_array_header_t *pds, ap_mpm_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn, void *baton, apr_time_t timeout)
void child_stopped(apr_pool_t *pchild, int graceful)
void ap_mpm_rewrite_args(process_rec *)
apr_status_t ap_mpm_safe_kill(pid_t pid, int sig)
AP_DECLARE_DATA char ap_coredump_dir[MAX_STRING_LEN]
int ap_sys_privileges_handlers(int inc)
apr_status_t ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod)
apr_status_t ap_mpm_pod_close(ap_pod_t *pod)
apr_status_t ap_mpm_pod_signal(ap_pod_t *pod)
int ap_unregister_extra_mpm_process(pid_t pid, ap_generation_t *old_gen)
AP_DECLARE_DATA const char * ap_pid_fname
AP_DECLARE_DATA apr_size_t ap_thread_stacksize
const char * ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, const char *arg)
const char * ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, const char *arg)
int ap_signal_server(int *, apr_pool_t *)
const char * ap_check_mpm(void)
void ap_relieve_child_processes(ap_reclaim_callback_fn_t *mpm_callback)
int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status)
void ap_reclaim_child_processes(int terminate, ap_reclaim_callback_fn_t *mpm_callback)
#define ap_sock_disable_nagle(s)
Definition: mpm_common.h:200
apr_status_t ap_fatal_signal_child_setup(server_rec *s)
void ap_mpm_pod_killpg(ap_pod_t *pod, int num)
void ap_reclaim_callback_fn_t(int childnum, pid_t pid, ap_generation_t gen)
Definition: mpm_common.h:89
void ap_mpm_podx_killpg(ap_pod_t *pod, int num, ap_podx_restart_t graceful)
const char * ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy, const char *arg)
void child_stopping(apr_pool_t *pchild, int graceful)
AP_DECLARE_DATA apr_uint32_t ap_max_mem_free
void ap_mpm_dump_pidfile(apr_pool_t *p, apr_file_t *out)
void ap_register_extra_mpm_process(pid_t pid, ap_generation_t gen)
void ap_core_child_status(server_rec *s, pid_t pid, ap_generation_t gen, int slot, mpm_child_status status)
apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *in_pconf)
int ap_mpm_podx_check(ap_pod_t *pod)
apr_status_t ap_mpm_podx_signal(ap_pod_t *pod, ap_podx_restart_t graceful)
apr_status_t ap_mpm_podx_close(ap_pod_t *pod)
apr_status_t ap_mpm_end_gen_helper(void *unused)
ap_podx_restart_t
Definition: mpm_common.h:284
apr_status_t ap_mpm_pod_check(ap_pod_t *pod)
const char * ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy, const char *arg)
AP_DECLARE_DATA int ap_coredumpdir_configured
const char * ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, const char *arg)
apr_status_t ap_mpm_podx_open(apr_pool_t *p, ap_pod_t **pod)
AP_DECLARE_DATA int ap_graceful_shutdown_timeout
AP_DECLARE_DATA int ap_max_requests_per_child
uid_t ap_uname2id(const char *name)
int drop_privileges(apr_pool_t *pchild, server_rec *s)
@ AP_MPM_PODX_NORESTART
Definition: mpm_common.h:284
@ AP_MPM_PODX_RESTART
Definition: mpm_common.h:284
@ AP_MPM_PODX_GRACEFUL
Definition: mpm_common.h:284
request_rec * r
Definition: mod_dav.h:518
int status
Definition: mod_dav.h:141
const char * s
Definition: mod_dav.h:1327
const char * name
Definition: mod_dav.h:805
int apr_status_t
Definition: apr_errno.h:44
unsigned int apr_uint32_t
Definition: apr.h:348
size_t apr_size_t
Definition: apr.h:394
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_exit_why_e
Definition: apr_thread_proc.h:66
apr_int64_t apr_time_t
Definition: apr_time.h:45
apr_status_t mpm_resume_suspended(conn_rec *)
int input_pending(conn_rec *c)
void resume_connection(conn_rec *c, request_rec *r)
int monitor(apr_pool_t *p, server_rec *s)
apr_status_t mpm_register_timed_callback(apr_time_t t, ap_mpm_callback_fn_t *cbfn, void *baton)
const char * mpm_get_name(void)
int output_pending(conn_rec *c)
int mpm_query(int query_code, int *result, apr_status_t *rv)
void suspend_connection(conn_rec *c, request_rec *r)
apr_status_t mpm_register_poll_callback(apr_pool_t *p, const apr_array_header_t *pds, ap_mpm_callback_fn_t *cbfn, void *baton)
#define AP_DECLARE_DATA
Definition: macros.h:15
#define AP_DECLARE(x)
Definition: macros.h:1
Apache scoreboard library.
int ap_generation_t
Definition: scoreboard.h:78
Definition: mpm_common.h:240
apr_file_t * pod_in
Definition: mpm_common.h:241
apr_pool_t * p
Definition: mpm_common.h:243
apr_file_t * pod_out
Definition: mpm_common.h:242
Definition: apr_tables.h:62
Definition: apr_arch_file_io.h:107
Definition: apr_thread_proc.h:134
Definition: apr_arch_networkio.h:37
Definition: http_config.h:288
Structure to store things which are per connection.
Definition: httpd.h:1193
A structure that represents one process.
Definition: httpd.h:840
A structure that represents the current request.
Definition: httpd.h:856
A structure to store information for each virtual server.
Definition: httpd.h:1382
apr_pool_t * p