Apache HTTPD
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
51extern "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
89typedef 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)
106AP_DECLARE(void) ap_reclaim_child_processes(int terminate,
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
210AP_DECLARE(uid_t) ap_uname2id(const char *name);
211#endif
212
213#ifdef HAVE_GETGRNAM
220AP_DECLARE(gid_t) ap_gname2id(const char *name);
221#endif
222
223#ifndef HAVE_INITGROUPS
233int initgroups(const char *name, gid_t basegid);
234#endif
235
236#if (!defined(WIN32) && !defined(NETWARE)) || defined(DOXYGEN)
237
238typedef struct ap_pod_t ap_pod_t;
239
245
253
258
265
272
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
330AP_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
344const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
345 const char *arg);
346
350AP_DECLARE_DATA extern const char *ap_pid_fname;
351const 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 */
360const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
361 const char *arg);
362
368 const char *arg);
369#define AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND \
370AP_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
375int ap_signal_server(int *, apr_pool_t *);
377
378AP_DECLARE_DATA extern apr_uint32_t ap_max_mem_free;
379extern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
380 const char *arg);
381
382AP_DECLARE_DATA extern apr_size_t ap_thread_stacksize;
383extern 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 */
387extern 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
391extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
392 const char *arg);
393#endif
394
396
397/* register modules that undertake to manage system security */
399AP_DECLARE_HOOK(int, drop_privileges, (apr_pool_t * pchild, server_rec * s))
400
401/* implement the ap_mpm_query() function
402 * The MPM should return OK+APR_ENOTIMPL for any unimplemented query codes;
403 * modules which intercede for specific query codes should DECLINE for others.
404 */
405AP_DECLARE_HOOK(int, mpm_query, (int query_code, int *result, apr_status_t *rv))
406
407/* register the specified callback */
408AP_DECLARE_HOOK(apr_status_t, mpm_register_timed_callback,
410
411/* get MPM name (e.g., "prefork" or "event") */
412AP_DECLARE_HOOK(const char *,mpm_get_name,(void))
413
432AP_DECLARE_HOOK(void, suspend_connection,
434
452AP_DECLARE_HOOK(void, resume_connection,
454
461AP_DECLARE_HOOK(void, child_stopping,
462 (apr_pool_t *pchild, int graceful))
463
464/* mutex type string for accept mutex, if any; MPMs should use the
465 * same mutex type for ease of configuration
466 */
467#define AP_ACCEPT_MUTEX_TYPE "mpm-accept"
468
469/* internal pre-config logic for MPM-related settings, callable only from
470 * core's pre-config hook
471 */
473
474#ifdef __cplusplus
475}
476#endif
477
478#endif /* !APACHE_MPM_COMMON_H */
Symbol export macros and hook functions.
#define AP_DECLARE_DATA
Definition ap_config.h:89
#define AP_DECLARE(type)
Definition ap_config.h:67
#define AP_DECLARE_HOOK(ret, name, args)
Definition ap_hooks.h:74
Apache Multi-Processing Module library.
APR Process Locking Routines.
static apr_pool_t * pconf
Definition event.c:441
request_rec * r
#define MAX_STRING_LEN
Definition httpd.h:300
mpm_child_status
Definition ap_mpm.h:205
void() ap_mpm_callback_fn_t(void *baton)
Definition ap_mpm.h:198
ap_vhost_iterate_conn_cb void * baton
Definition http_vhost.h:87
void * dummy
Definition http_vhost.h:62
void const char * arg
Definition http_vhost.h:63
void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, apr_pool_t *p, server_rec *s)
Definition mpm_common.c:181
const char * ap_pid_fname
Definition mpm_common.c:150
char ap_coredump_dir[8192]
Definition mpm_common.c:152
void mpm_common_pre_config(apr_pool_t *pconf)
Definition mpm_common.c:164
void ap_mpm_rewrite_args(process_rec *)
Definition mpm_unix.c:872
apr_status_t ap_mpm_safe_kill(pid_t pid, int sig)
Definition mpm_unix.c:331
int ap_sys_privileges_handlers(int inc)
Definition core.c:5062
const char * ap_check_mpm(void)
Definition mpm_common.c:559
apr_status_t ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod)
Definition mpm_unix.c:447
int ap_max_requests_per_child
Definition mpm_common.c:151
apr_status_t ap_mpm_pod_close(ap_pod_t *pod)
Definition mpm_unix.c:487
apr_status_t ap_mpm_pod_signal(ap_pod_t *pod)
Definition mpm_unix.c:731
int ap_unregister_extra_mpm_process(pid_t pid, ap_generation_t *old_gen)
Definition mpm_unix.c:92
const char * ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:300
const char * ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:369
int ap_coredumpdir_configured
Definition mpm_common.c:153
const char * ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:341
int ap_signal_server(int *, apr_pool_t *)
Definition mpm_unix.c:784
void ap_relieve_child_processes(ap_reclaim_callback_fn_t *mpm_callback)
Definition mpm_unix.c:286
int ap_graceful_shutdown_timeout
Definition mpm_common.c:154
int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status)
Definition mpm_unix.c:386
void ap_reclaim_child_processes(int terminate, ap_reclaim_callback_fn_t *mpm_callback)
Definition mpm_unix.c:184
#define ap_sock_disable_nagle(s)
Definition mpm_common.h:200
apr_status_t ap_fatal_signal_child_setup(server_rec *s)
Definition mpm_unix.c:1011
void ap_mpm_pod_killpg(ap_pod_t *pod, int num)
Definition mpm_unix.c:743
void ap_reclaim_callback_fn_t(int childnum, pid_t pid, ap_generation_t gen)
Definition mpm_common.h:89
int initgroups(const char *name, gid_t basegid)
Definition mpm_common.c:267
void ap_mpm_podx_killpg(ap_pod_t *pod, int num, ap_podx_restart_t graceful)
Definition mpm_unix.c:609
apr_size_t ap_thread_stacksize
Definition mpm_common.c:156
void ap_mpm_dump_pidfile(apr_pool_t *p, apr_file_t *out)
Definition mpm_common.c:316
void ap_register_extra_mpm_process(pid_t pid, ap_generation_t gen)
Definition mpm_unix.c:82
void ap_core_child_status(server_rec *s, pid_t pid, ap_generation_t gen, int slot, mpm_child_status status)
Definition mpm_common.c:477
apr_uint32_t ap_max_mem_free
Definition mpm_common.c:155
apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *in_pconf)
Definition mpm_unix.c:1044
int ap_mpm_podx_check(ap_pod_t *pod)
Definition mpm_unix.c:540
apr_status_t ap_mpm_podx_signal(ap_pod_t *pod, ap_podx_restart_t graceful)
Definition mpm_unix.c:603
apr_status_t ap_mpm_podx_close(ap_pod_t *pod)
Definition mpm_unix.c:562
const char * ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:322
apr_status_t ap_mpm_end_gen_helper(void *unused)
Definition mpm_common.c:441
ap_podx_restart_t
Definition mpm_common.h:284
const char * ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:401
apr_status_t ap_mpm_pod_check(ap_pod_t *pod)
Definition mpm_unix.c:468
apr_status_t ap_mpm_podx_open(apr_pool_t *p, ap_pod_t **pod)
Definition mpm_unix.c:519
const char * ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy, const char *arg)
Definition mpm_common.c:381
@ 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
const char apr_int32_t inc
Definition apr_redis.h:337
int apr_status_t
Definition apr_errno.h:44
apr_array_header_t ** result
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_interval_time_t t
apr_interval_time_t apr_int32_t * num
Definition apr_poll.h:273
const char * s
Definition apr_strings.h:95
int sig
apr_cmdtype_e cmd
apr_exit_why_e
int * exitcode
int int status
apr_int64_t apr_time_t
Definition apr_time.h:45
static apr_pool_t * pchild
Definition h2_mplx.c:74
apr_pool_t * p
Definition md_event.c:32
static apr_file_t * out
Definition mod_info.c:85
Apache scoreboard library.
int ap_generation_t
Definition scoreboard.h:78
char * name
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
Structure to store things which are per connection.
Definition httpd.h:1152
A structure that represents one process.
Definition httpd.h:829
A structure that represents the current request.
Definition httpd.h:845
A structure to store information for each virtual server.
Definition httpd.h:1322