bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / include / mpm_common.h
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
28 #ifndef APACHE_MPM_COMMON_H
29 #define APACHE_MPM_COMMON_H
30
31 #include "ap_config.h"
32
33 #if APR_HAVE_NETINET_TCP_H
34 #include <netinet/tcp.h>    /* for TCP_NODELAY */
35 #endif
36
37 #include "mpm.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44  * @package Multi-Processing Modules functions
45  */
46
47 /* The maximum length of the queue of pending connections, as defined
48  * by listen(2).  Under some systems, it should be increased if you
49  * are experiencing a heavy TCP SYN flood attack.
50  *
51  * It defaults to 511 instead of 512 because some systems store it 
52  * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is 
53  * 255 when truncated.
54  */
55 #ifndef DEFAULT_LISTENBACKLOG
56 #define DEFAULT_LISTENBACKLOG 511
57 #endif
58         
59 /**
60  * Make sure all child processes that have been spawned by the parent process
61  * have died.  This includes process registered as "other_children".
62  * @warning This is only defined if the MPM defines 
63  *          AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
64  * @param terminate Either 1 or 0.  If 1, send the child processes SIGTERM
65  *        each time through the loop.  If 0, give the process time to die
66  *        on its own before signalling it.
67  * @tip This function requires that some macros are defined by the MPM: <pre>
68  *  MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
69  *  MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
70  * </pre>
71  * @tip The MPM child processes which are reclaimed are those listed
72  * in the scoreboard as well as those currently registered via
73  * ap_register_extra_mpm_process().
74  */
75 #ifdef AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
76 void ap_reclaim_child_processes(int terminate);
77 #endif
78
79 /**
80  * Tell ap_reclaim_child_processes() about an MPM child process which has no
81  * entry in the scoreboard.
82  * @warning This is only defined if the MPM defines
83  *          AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
84  * @param pid The process id of an MPM child process which should be
85  * reclaimed when ap_reclaim_child_processes() is called.
86  * @tip If an extra MPM child process terminates prior to calling
87  * ap_reclaim_child_processes(), remove it from the list of such processes
88  * by calling ap_unregister_extra_mpm_process().
89  */
90 #ifdef AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
91 void ap_register_extra_mpm_process(pid_t pid);
92 #endif
93
94 /**
95  * Unregister an MPM child process which was previously registered by a
96  * call to ap_register_extra_mpm_process().
97  * @warning This is only defined if the MPM defines
98  *          AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
99  * @param pid The process id of an MPM child process which no longer needs to
100  * be reclaimed.
101  * @return 1 if the process was found and removed, 0 otherwise
102  */
103 #ifdef AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
104 int ap_unregister_extra_mpm_process(pid_t pid);
105 #endif
106
107 /**
108  * Determine if any child process has died.  If no child process died, then
109  * this process sleeps for the amount of time specified by the MPM defined
110  * macro SCOREBOARD_MAINTENANCE_INTERVAL.
111  * @param status The return code if a process has died
112  * @param ret The process id of the process that died
113  * @param p The pool to allocate out of
114  */
115 #ifdef AP_MPM_WANT_WAIT_OR_TIMEOUT
116 void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, 
117                         apr_pool_t *p);
118 #endif
119
120 /**
121  * Log why a child died to the error log, if the child died without the
122  * parent signalling it.
123  * @param pid The child that has died
124  * @param status The status returned from ap_wait_or_timeout
125  * @return 0 on success, APEXIT_CHILDFATAL if MPM should terminate
126  */
127 #ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS
128 int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status);
129 #endif
130
131 #if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
132 /**
133  * Turn off the nagle algorithm for the specified socket.  The nagle algorithm
134  * says that we should delay sending partial packets in the hopes of getting
135  * more data.  There are bad interactions between persistent connections and
136  * Nagle's algorithm that have severe performance penalties.
137  * @param s The socket to disable nagle for.
138  */
139 void ap_sock_disable_nagle(apr_socket_t *s);
140 #else
141 #define ap_sock_disable_nagle(s)        /* NOOP */
142 #endif
143
144 #ifdef HAVE_GETPWNAM
145 /**
146  * Convert a username to a numeric ID
147  * @param name The name to convert
148  * @return The user id corresponding to a name
149  * @deffunc uid_t ap_uname2id(const char *name)
150  */
151 AP_DECLARE(uid_t) ap_uname2id(const char *name);
152 #endif
153
154 #ifdef HAVE_GETGRNAM
155 /**
156  * Convert a group name to a numeric ID
157  * @param name The name to convert
158  * @return The group id corresponding to a name
159  * @deffunc gid_t ap_gname2id(const char *name)
160  */
161 AP_DECLARE(gid_t) ap_gname2id(const char *name);
162 #endif
163
164 #define AP_MPM_HARD_LIMITS_FILE APACHE_MPM_DIR "/mpm_default.h"
165
166 #ifdef AP_MPM_USES_POD
167
168 typedef struct ap_pod_t ap_pod_t;
169
170 struct ap_pod_t {
171     apr_file_t *pod_in;
172     apr_file_t *pod_out;
173     apr_pool_t *p;
174     apr_sockaddr_t *sa;
175 };
176
177 /**
178  * Open the pipe-of-death.  The pipe of death is used to tell all child
179  * processes that it is time to die gracefully.
180  * @param p The pool to use for allocating the pipe
181  */
182 AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod);
183
184 /**
185  * Check the pipe to determine if the process has been signalled to die.
186  */
187 AP_DECLARE(apr_status_t) ap_mpm_pod_check(ap_pod_t *pod);
188
189 /**
190  * Close the pipe-of-death
191  */
192 AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod);
193
194 /**
195  * Write data to the pipe-of-death, signalling that one child process
196  * should die.
197  * @param p The pool to use when allocating any required structures.
198  */
199 AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod);
200
201 /**
202  * Write data to the pipe-of-death, signalling that all child process
203  * should die.
204  * @param p The pool to use when allocating any required structures.
205  * @param num The number of child processes to kill
206  */
207 AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num);
208 #endif
209
210 /*
211  * These data members are common to all mpms. Each new mpm
212  * should either use the appropriate ap_mpm_set_* function
213  * in their command table or create their own for custom or
214  * OS specific needs. These should work for most.
215  */
216
217 /**
218  * The maximum number of requests each child thread or
219  * process handles before dying off
220  */
221 #ifdef AP_MPM_WANT_SET_MAX_REQUESTS
222 extern int ap_max_requests_per_child;
223 const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
224                                     const char *arg);
225 #endif
226
227 /**
228  * The filename used to store the process id.
229  */
230 #ifdef AP_MPM_WANT_SET_PIDFILE
231 extern const char *ap_pid_fname;
232 const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
233                                const char *arg);
234 #endif
235
236 /**
237  * The name of lockfile used when Apache needs to lock the accept() call.
238  */
239 #ifdef AP_MPM_WANT_SET_LOCKFILE
240 extern const char *ap_lock_fname;
241 const char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
242                                 const char *arg);
243 #endif
244
245 /**
246  * The system mutex implementation to use for the accept mutex.
247  */
248 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
249 extern apr_lockmech_e ap_accept_lock_mech;
250 extern const char ap_valid_accept_mutex_string[];
251 const char *ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy,
252                                         const char *arg);
253 #endif
254
255 /*
256  * Set the scorboard file.
257  */
258 #ifdef AP_MPM_WANT_SET_SCOREBOARD
259 const char *ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy,
260                                   const char *arg);
261 #endif
262
263 /*
264  * The directory that the server changes directory to dump core.
265  */
266 #ifdef AP_MPM_WANT_SET_COREDUMPDIR
267 extern char ap_coredump_dir[MAX_STRING_LEN];
268 extern int ap_coredumpdir_configured;
269 const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
270                                    const char *arg);
271 #endif
272
273 #ifdef AP_MPM_WANT_SIGNAL_SERVER
274 int ap_signal_server(int *, apr_pool_t *);
275 void ap_mpm_rewrite_args(process_rec *);
276 #endif
277
278 #ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
279 extern apr_uint32_t ap_max_mem_free;
280 extern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
281                                            const char *arg);
282 #endif
283
284 #ifdef AP_MPM_WANT_FATAL_SIGNAL_HANDLER
285 extern apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *pconf);
286 extern apr_status_t ap_fatal_signal_child_setup(server_rec *s);
287 #endif
288
289 #if AP_ENABLE_EXCEPTION_HOOK
290 extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
291                                              const char *arg);
292 #endif
293
294 #ifdef __cplusplus
295 }
296 #endif
297
298 #endif /* !APACHE_MPM_COMMON_H */