Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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)
93 
106 AP_DECLARE(void) ap_reclaim_child_processes(int terminate,
107  ap_reclaim_callback_fn_t *mpm_callback);
108 
120 
133 
143 
153 AP_DECLARE(apr_status_t) ap_mpm_safe_kill(pid_t pid, int sig);
154 
164 
167 
168 #endif /* (!WIN32 && !NETWARE) || DOXYGEN */
169 
174 apr_status_t ap_mpm_end_gen_helper(void *unused);
175 
186 AP_DECLARE(void) ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode,
187  apr_proc_t *ret, apr_pool_t *p,
188  server_rec *s);
189 
190 #if defined(TCP_NODELAY)
191 
199 #else
200 #define ap_sock_disable_nagle(s) /* NOOP */
201 #endif
202 
203 #ifdef HAVE_GETPWNAM
204 
210 AP_DECLARE(uid_t) ap_uname2id(const char *name);
211 #endif
212 
213 #ifdef HAVE_GETGRNAM
214 
220 AP_DECLARE(gid_t) ap_gname2id(const char *name);
221 #endif
222 
223 #ifndef HAVE_INITGROUPS
224 
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 
321 AP_DECLARE(void) ap_mpm_podx_killpg(ap_pod_t *pod, int num,
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 
375 int ap_signal_server(int *, apr_pool_t *);
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_array_header_t *pds, ap_mpm_callback_fn_t *cbfn, void *baton))
431 
432 /* register the specified callback, with timeout
433  * @ingroup hooks
434  *
435  */
437  (apr_array_header_t *pds,
438  ap_mpm_callback_fn_t *cbfn,
439  ap_mpm_callback_fn_t *tofn,
440  void *baton,
441  apr_time_t timeout))
442 
448  (apr_array_header_t *pds))
449 
454 
459 AP_DECLARE_HOOK(const char *,mpm_get_name,(void))
460 
470 
478 
499  (conn_rec *c, request_rec *r))
500 
520  (conn_rec *c, request_rec *r))
521 
522 /* mutex type string for accept mutex, if any; MPMs should use the
523  * same mutex type for ease of configuration
524  */
525 #define AP_ACCEPT_MUTEX_TYPE "mpm-accept"
526 
527 /* internal pre-config logic for MPM-related settings, callable only from
528  * core's pre-config hook
529  */
530 void mpm_common_pre_config(apr_pool_t *pconf);
531 
532 #ifdef __cplusplus
533 }
534 #endif
535 
536 #endif /* !APACHE_MPM_COMMON_H */
537 
const char * ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, const char *arg)
void ap_mpm_pod_killpg(ap_pod_t *pod, int num)
void resume_connection(conn_rec *c, request_rec *r)
size_t apr_size_t
Definition: apr.h:375
apr_status_t mpm_resume_suspended(conn_rec *)
int ap_generation_t
Definition: scoreboard.h:78
AP_DECLARE_DATA int ap_max_requests_per_child
apr_status_t ap_mpm_pod_close(ap_pod_t *pod)
void( ap_mpm_callback_fn_t)(void *baton)
Definition: ap_mpm.h:208
apr_status_t ap_mpm_safe_kill(pid_t pid, int sig)
#define ap_sock_disable_nagle(s)
Definition: mpm_common.h:200
void ap_mpm_podx_killpg(ap_pod_t *pod, int num, ap_podx_restart_t graceful)
Definition: apr_arch_file_io.h:107
Definition: apr_tables.h:62
void ap_core_child_status(server_rec *s, pid_t pid, ap_generation_t gen, int slot, mpm_child_status status)
AP_DECLARE_DATA apr_size_t ap_thread_stacksize
#define AP_DECLARE(x)
Definition: macros.h:1
int ap_unregister_extra_mpm_process(pid_t pid, ap_generation_t *old_gen)
apr_status_t mpm_register_poll_callback(apr_array_header_t *pds, ap_mpm_callback_fn_t *cbfn, void *baton)
apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *in_pconf)
void mpm_common_pre_config(apr_pool_t *pconf)
Definition: mpm_common.h:284
int input_pending(conn_rec *c)
apr_status_t mpm_unregister_poll_callback(apr_array_header_t *pds)
Definition: apr_thread_proc.h:144
AP_DECLARE_DATA const char * ap_pid_fname
apr_file_t * pod_in
Definition: mpm_common.h:241
A structure that represents one process.
Definition: httpd.h:790
gid_t ap_gname2id(const char *name)
const char * ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy, const char *arg)
Structure to store things which are per connection.
Definition: httpd.h:1116
apr_status_t mpm_register_poll_callback_timeout(apr_array_header_t *pds, ap_mpm_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn, void *baton, apr_time_t timeout)
uid_t ap_uname2id(const char *name)
void ap_mpm_rewrite_args(process_rec *)
Symbol export macros and hook functions.
#define AP_DECLARE_HOOK(ret, name, args)
Definition: ap_hooks.h:74
ap_podx_restart_t
Definition: mpm_common.h:284
void ap_reclaim_callback_fn_t(int childnum, pid_t pid, ap_generation_t gen)
Definition: mpm_common.h:89
Definition: http_config.h:295
apr_int64_t apr_time_t
Definition: apr_time.h:45
apr_status_t ap_fatal_signal_child_setup(server_rec *s)
Definition: mpm_common.h:284
void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, apr_pool_t *p, server_rec *s)
#define MAX_STRING_LEN
Definition: httpd.h:300
Definition: mpm_common.h:284
A structure to store information for each virtual server.
Definition: httpd.h:1310
Definition: apr_arch_networkio.h:37
void ap_mpm_dump_pidfile(apr_pool_t *p, apr_file_t *out)
int mpm_query(int query_code, int *result, apr_status_t *rv)
int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status)
apr_status_t ap_mpm_podx_signal(ap_pod_t *pod, ap_podx_restart_t graceful)
int ap_mpm_podx_check(ap_pod_t *pod)
apr_status_t ap_mpm_pod_signal(ap_pod_t *pod)
void ap_relieve_child_processes(ap_reclaim_callback_fn_t *mpm_callback)
unsigned int apr_uint32_t
Definition: apr.h:334
const char * ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, const char *arg)
void ap_register_extra_mpm_process(pid_t pid, ap_generation_t gen)
const char * ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, const char *arg)
int drop_privileges(apr_pool_t *pchild, server_rec *s)
apr_pool_t * p
APR Process Locking Routines.
apr_file_t * pod_out
Definition: mpm_common.h:242
AP_DECLARE_DATA int ap_graceful_shutdown_timeout
apr_pool_t * p
Definition: mpm_common.h:243
AP_DECLARE_DATA apr_uint32_t ap_max_mem_free
apr_exit_why_e
Definition: apr_thread_proc.h:66
AP_DECLARE_DATA char ap_coredump_dir[MAX_STRING_LEN]
A structure that represents the current request.
Definition: httpd.h:806
void ap_reclaim_child_processes(int terminate, ap_reclaim_callback_fn_t *mpm_callback)
Apache scoreboard library.
#define AP_DECLARE_DATA
Definition: macros.h:15
int status
Definition: mod_dav.h:141
apr_status_t ap_mpm_podx_close(ap_pod_t *pod)
Definition: mpm_common.h:240
int monitor(apr_pool_t *p, server_rec *s)
const char * mpm_get_name(void)
Apache Multi-Processing Module library.
const char * name
Definition: mod_dav.h:726
const char * ap_check_mpm(void)
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44
request_rec * r
Definition: mod_dav.h:515
mpm_child_status
Definition: ap_mpm.h:261
AP_DECLARE_DATA int ap_coredumpdir_configured
apr_status_t ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod)
const char * ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy, const char *arg)
int output_pending(conn_rec *c)
apr_status_t ap_mpm_pod_check(ap_pod_t *pod)
void suspend_connection(conn_rec *c, request_rec *r)
apr_status_t ap_mpm_end_gen_helper(void *unused)
apr_status_t mpm_register_timed_callback(apr_time_t t, ap_mpm_callback_fn_t *cbfn, void *baton)
const char * ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, const char *arg)
apr_status_t ap_mpm_podx_open(apr_pool_t *p, ap_pod_t **pod)
int ap_sys_privileges_handlers(int inc)
int ap_signal_server(int *, apr_pool_t *)