]> granicus.if.org Git - apache/blob - include/mpm_common.h
add "-l" option to indicate interval is based on localtime not gmt
[apache] / include / mpm_common.h
1 /* Copyright 2000-2004 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 /* The purpose of this file is to store the code that MOST mpm's will need
17  * this does not mean a function only goes into this file if every MPM needs
18  * it.  It means that if a function is needed by more than one MPM, and
19  * future maintenance would be served by making the code common, then the
20  * function belongs here.
21  *
22  * This is going in src/main because it is not platform specific, it is
23  * specific to multi-process servers, but NOT to Unix.  Which is why it
24  * does not belong in src/os/unix
25  */
26
27 #ifndef APACHE_MPM_COMMON_H
28 #define APACHE_MPM_COMMON_H
29
30 #include "ap_config.h"
31
32 #if APR_HAVE_NETINET_TCP_H
33 #include <netinet/tcp.h>    /* for TCP_NODELAY */
34 #endif
35
36 #include "mpm.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /**
43  * @package Multi-Processing Modules functions
44  */
45
46 /* The maximum length of the queue of pending connections, as defined
47  * by listen(2).  Under some systems, it should be increased if you
48  * are experiencing a heavy TCP SYN flood attack.
49  *
50  * It defaults to 511 instead of 512 because some systems store it 
51  * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is 
52  * 255 when truncated.
53  */
54 #ifndef DEFAULT_LISTENBACKLOG
55 #define DEFAULT_LISTENBACKLOG 511
56 #endif
57         
58 /**
59  * Make sure all child processes that have been spawned by the parent process
60  * have died.  This includes process registered as "other_children".
61  * @warning This is only defined if the MPM defines 
62  *          MPM_NEEDS_RECLAIM_CHILD_PROCESS
63  * @param terminate Either 1 or 0.  If 1, send the child processes SIGTERM
64  *        each time through the loop.  If 0, give the process time to die
65  *        on its own before signalling it.
66  * @tip This function requires that some macros are defined by the MPM: <pre>
67  *  MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
68  *  MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
69  * </pre>
70  */
71 #ifdef AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
72 void ap_reclaim_child_processes(int terminate);
73 #endif
74
75 /**
76  * Determine if any child process has died.  If no child process died, then
77  * this process sleeps for the amount of time specified by the MPM defined
78  * macro SCOREBOARD_MAINTENANCE_INTERVAL.
79  * @param status The return code if a process has died
80  * @param ret The process id of the process that died
81  * @param p The pool to allocate out of
82  */
83 #ifdef AP_MPM_WANT_WAIT_OR_TIMEOUT
84 void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, 
85                         apr_pool_t *p);
86 #endif
87
88 /**
89  * Log why a child died to the error log, if the child died without the
90  * parent signalling it.
91  * @param pid The child that has died
92  * @param status The status returned from ap_wait_or_timeout
93  * @return 0 on success, APEXIT_CHILDFATAL if MPM should terminate
94  */
95 #ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS
96 int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status);
97 #endif
98
99 #if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
100 /**
101  * Turn off the nagle algorithm for the specified socket.  The nagle algorithm
102  * says that we should delay sending partial packets in the hopes of getting
103  * more data.  There are bad interactions between persistent connections and
104  * Nagle's algorithm that have severe performance penalties.
105  * @param s The socket to disable nagle for.
106  */
107 void ap_sock_disable_nagle(apr_socket_t *s);
108 #else
109 #define ap_sock_disable_nagle(s)        /* NOOP */
110 #endif
111
112 #ifdef HAVE_GETPWNAM
113 /**
114  * Convert a username to a numeric ID
115  * @param name The name to convert
116  * @return The user id corresponding to a name
117  * @deffunc uid_t ap_uname2id(const char *name)
118  */
119 AP_DECLARE(uid_t) ap_uname2id(const char *name);
120 #endif
121
122 #ifdef HAVE_GETGRNAM
123 /**
124  * Convert a group name to a numeric ID
125  * @param name The name to convert
126  * @return The group id corresponding to a name
127  * @deffunc gid_t ap_gname2id(const char *name)
128  */
129 AP_DECLARE(gid_t) ap_gname2id(const char *name);
130 #endif
131
132 #define AP_MPM_HARD_LIMITS_FILE APACHE_MPM_DIR "/mpm_default.h"
133
134 #ifdef AP_MPM_USES_POD
135
136 typedef struct ap_pod_t ap_pod_t;
137
138 struct ap_pod_t {
139     apr_file_t *pod_in;
140     apr_file_t *pod_out;
141     apr_pool_t *p;
142 };
143
144 /**
145  * Open the pipe-of-death.  The pipe of death is used to tell all child
146  * processes that it is time to die gracefully.
147  * @param p The pool to use for allocating the pipe
148  */
149 AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod);
150
151 /**
152  * Check the pipe to determine if the process has been signalled to die.
153  */
154 AP_DECLARE(apr_status_t) ap_mpm_pod_check(ap_pod_t *pod);
155
156 /**
157  * Close the pipe-of-death
158  */
159 AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod);
160
161 /**
162  * Write data to the pipe-of-death, signalling that one child process
163  * should die.
164  * @param p The pool to use when allocating any required structures.
165  */
166 AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod);
167
168 /**
169  * Write data to the pipe-of-death, signalling that all child process
170  * should die.
171  * @param p The pool to use when allocating any required structures.
172  * @param num The number of child processes to kill
173  */
174 AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num);
175 #endif
176
177 /*
178  * These data members are common to all mpms. Each new mpm
179  * should either use the appropriate ap_mpm_set_* function
180  * in their command table or create their own for custom or
181  * OS specific needs. These should work for most.
182  */
183
184 /**
185  * The maximum number of requests each child thread or
186  * process handles before dying off
187  */
188 #ifdef AP_MPM_WANT_SET_MAX_REQUESTS
189 extern int ap_max_requests_per_child;
190 const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
191                                     const char *arg);
192 #endif
193
194 /**
195  * The filename used to store the process id.
196  */
197 #ifdef AP_MPM_WANT_SET_PIDFILE
198 extern const char *ap_pid_fname;
199 const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
200                                const char *arg);
201 #endif
202
203 /**
204  * The name of lockfile used when Apache needs to lock the accept() call.
205  */
206 #ifdef AP_MPM_WANT_SET_LOCKFILE
207 extern const char *ap_lock_fname;
208 const char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
209                                 const char *arg);
210 #endif
211
212 /**
213  * The system mutex implementation to use for the accept mutex.
214  */
215 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
216 extern apr_lockmech_e ap_accept_lock_mech;
217 extern const char ap_valid_accept_mutex_string[];
218 const char *ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy,
219                                         const char *arg);
220 #endif
221
222 /*
223  * Set the scorboard file.
224  */
225 #ifdef AP_MPM_WANT_SET_SCOREBOARD
226 const char *ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy,
227                                   const char *arg);
228 #endif
229
230 /*
231  * The directory that the server changes directory to dump core.
232  */
233 #ifdef AP_MPM_WANT_SET_COREDUMPDIR
234 extern char ap_coredump_dir[MAX_STRING_LEN];
235 extern int ap_coredumpdir_configured;
236 const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
237                                    const char *arg);
238 #endif
239
240 #ifdef AP_MPM_WANT_SIGNAL_SERVER
241 int ap_signal_server(int *, apr_pool_t *);
242 void ap_mpm_rewrite_args(process_rec *);
243 #endif
244
245 #ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
246 extern apr_uint32_t ap_max_mem_free;
247 extern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
248                                            const char *arg);
249 #endif
250
251 #ifdef AP_MPM_WANT_SET_STACKSIZE
252 extern apr_size_t ap_thread_stacksize;
253 extern const char *ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy,
254                                                const char *arg);
255 #endif
256
257 #ifdef AP_MPM_WANT_FATAL_SIGNAL_HANDLER
258 extern apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *pconf);
259 extern apr_status_t ap_fatal_signal_child_setup(server_rec *s);
260 #endif
261
262 #if AP_ENABLE_EXCEPTION_HOOK
263 extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
264                                              const char *arg);
265 #endif
266
267 #ifdef __cplusplus
268 }
269 #endif
270
271 #endif /* !APACHE_MPM_COMMON_H */