]> granicus.if.org Git - apache/blob - server/mpm/motorz/motorz.h
mpm_event,worker: Mask signals for threads created by modules in child init.
[apache] / server / mpm / motorz / motorz.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 #include "apr.h"
18 #include "apr_portable.h"
19 #include "apr_strings.h"
20 #include "apr_thread_proc.h"
21 #include "apr_signal.h"
22
23 #define APR_WANT_STDIO
24 #define APR_WANT_STRFUNC
25 #include "apr_want.h"
26
27 #if APR_HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
30 #if APR_HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #endif
33
34 #include "ap_config.h"
35 #include "httpd.h"
36 #include "mpm_default.h"
37 #include "http_main.h"
38 #include "http_log.h"
39 #include "http_config.h"
40 #include "http_core.h"          /* for get_remote_host */
41 #include "http_connection.h"
42 #include "scoreboard.h"
43 #include "ap_mpm.h"
44 #include "util_mutex.h"
45 #include "unixd.h"
46 #include "http_vhost.h"
47 #include "mpm_common.h"
48 #include "ap_listen.h"
49 #include "ap_mmn.h"
50 #include "apr_poll.h"
51 #include "apr_skiplist.h"
52 #include "apr_thread_pool.h"
53 #include "util_time.h"
54
55 #include <stdlib.h>
56
57 #ifdef HAVE_TIME_H
58 #include <time.h>
59 #endif
60 #ifdef HAVE_SYS_PROCESSOR_H
61 #include <sys/processor.h> /* for bindprocessor() */
62 #endif
63
64 #include <signal.h>
65 #include <sys/times.h>
66
67 /* Limit on the total --- clients will be locked out if more servers than
68  * this are needed.  It is intended solely to keep the server from crashing
69  * when things get out of hand.
70  *
71  * We keep a hard maximum number of servers, for two reasons --- first off,
72  * in case something goes seriously wrong, we want to stop the fork bomb
73  * short of actually crashing the machine we're running on by filling some
74  * kernel table.  Secondly, it keeps the size of the scoreboard file small
75  * enough that we can read the whole thing without worrying too much about
76  * the overhead.
77  */
78 #ifndef DEFAULT_SERVER_LIMIT
79 #define DEFAULT_SERVER_LIMIT 256
80 #endif
81
82 /* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT.  We want
83  * some sort of compile-time limit to help catch typos.
84  */
85 #ifndef MAX_SERVER_LIMIT
86 #define MAX_SERVER_LIMIT 200000
87 #endif
88
89 /* Limit on the threads per process.  Clients will be locked out if more than
90  * this are needed.
91  *
92  * We keep this for one reason it keeps the size of the scoreboard file small
93  * enough that we can read the whole thing without worrying too much about
94  * the overhead.
95  */
96 #ifndef DEFAULT_THREAD_LIMIT
97 #define DEFAULT_THREAD_LIMIT 64
98 #endif
99
100 /* Admin can't tune ThreadLimit beyond MAX_THREAD_LIMIT.  We want
101  * some sort of compile-time limit to help catch typos.
102  */
103 #ifndef MAX_THREAD_LIMIT
104 #define MAX_THREAD_LIMIT 100000
105 #endif
106
107 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
108
109 /**
110  * typedefs
111  */
112 /* data retained by prefork across load/unload of the module
113  * allocated on first call to pre-config hook; located on
114  * subsequent calls to pre-config hook
115  */
116 typedef struct motorz_core_t motorz_core_t;
117 struct motorz_core_t {
118     ap_unixd_mpm_retained_data *mpm;
119
120     int first_server_limit;
121     int maxclients_reported;
122     /*
123      * The max child slot ever assigned, preserved across restarts.  Necessary
124      * to deal with MaxRequestWorkers changes across AP_SIG_GRACEFUL restarts.  We
125      * use this value to optimize routines that have to scan the entire scoreboard.
126      */
127     int max_daemons_limit;
128     apr_pool_t *pool;
129     apr_thread_mutex_t *mtx;
130     apr_pollset_t *pollset;
131     apr_skiplist *timeout_ring;
132     apr_thread_pool_t *workers;
133 };
134
135 typedef struct motorz_child_bucket motorz_child_bucket;
136 struct motorz_child_bucket {
137     ap_pod_t *pod;
138     ap_listen_rec *listeners;
139     apr_proc_mutex_t *mutex;
140 };
141
142 typedef enum
143 {
144     PT_CSD,
145     PT_ACCEPT,
146     PT_USER
147 } motorz_poll_type_e;
148
149 typedef struct motorz_sb_t motorz_sb_t;
150 struct motorz_sb_t
151 {
152     motorz_poll_type_e type;
153     void *baton;
154 };
155
156 typedef void (*motorz_timer_cb) (motorz_core_t *mz, void *baton);
157 typedef void (*motorz_io_sock_cb) (motorz_core_t *mz, apr_socket_t *sock,
158                                    int flags, void *baton);
159 typedef void (*motorz_io_file_cb) (motorz_core_t *mz, apr_socket_t *sock,
160                                    int flags, void *baton);
161
162
163 typedef struct motorz_timer_t motorz_timer_t;
164 struct motorz_timer_t
165 {
166     apr_time_t expires;
167     motorz_timer_cb cb;
168     void *baton;
169     apr_pool_t *pool;
170     motorz_core_t *mz;
171 };
172
173 typedef struct motorz_conn_t motorz_conn_t;
174 struct motorz_conn_t
175 {
176     apr_pool_t *pool;
177     motorz_core_t *mz;
178     apr_socket_t *sock;
179     apr_bucket_alloc_t *ba;
180     ap_sb_handle_t *sbh;
181     /** connection record this struct refers to */
182     conn_rec *c;
183     /** request record (if any) this struct refers to */
184     request_rec *r;
185     /** is the current conn_rec suspended? */
186     int suspended;
187     /** poll file descriptor information */
188     apr_pollfd_t pfd;
189     /** public parts of the connection state */
190     conn_state_t cs;
191     /** timer associated with the connection */
192     motorz_timer_t timer;
193 };