Apache2
motorz.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 #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 
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;
119 
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  */
133 };
134 
140 };
141 
142 typedef enum
143 {
146  PT_USER
148 
149 typedef struct motorz_sb_t motorz_sb_t;
151 {
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;
165 {
168  void *baton;
171 };
172 
173 typedef struct motorz_conn_t motorz_conn_t;
175 {
193 };
Symbol export macros and hook functions.
Apache Listeners Library.
Module Magic Number.
Apache Multi-Processing Module library.
APR Platform Definitions.
APR Poll interface.
APR Portability Routines.
APR Signal Handling.
APR skip list implementation.
APR Strings library.
APR Thread Pool Library.
APR Thread and Process Library.
APR Standard Headers Support.
struct apr_bucket_alloc_t apr_bucket_alloc_t
Definition: apr_buckets.h:128
struct apr_thread_pool apr_thread_pool_t
Definition: apr_thread_pool.h:58
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1458
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
struct apr_skiplist apr_skiplist
Definition: apr_skiplist.h:56
apr_int64_t apr_time_t
Definition: apr_time.h:45
Apache Configuration.
Apache connection library.
CORE HTTP Daemon.
Apache Logging library.
Command line options.
Virtual Host package.
HTTP Daemon routines.
void(* motorz_io_file_cb)(motorz_core_t *mz, apr_socket_t *sock, int flags, void *baton)
Definition: motorz.h:159
motorz_poll_type_e
Definition: motorz.h:143
@ PT_CSD
Definition: motorz.h:144
@ PT_ACCEPT
Definition: motorz.h:145
@ PT_USER
Definition: motorz.h:146
void(* motorz_timer_cb)(motorz_core_t *mz, void *baton)
Definition: motorz.h:156
void(* motorz_io_sock_cb)(motorz_core_t *mz, apr_socket_t *sock, int flags, void *baton)
Definition: motorz.h:157
Multi-Processing Modules functions.
Apache scoreboard library.
struct ap_sb_handle_t ap_sb_handle_t
Definition: scoreboard.h:163
Apache's listeners record.
Definition: ap_listen.h:54
Definition: mpm_common.h:240
Definition: unixd.h:113
Definition: apr_poll.h:109
Definition: apr_arch_poll_private.h:124
Definition: apr_arch_proc_mutex.h:27
Definition: apr_arch_networkio.h:37
Definition: apr_arch_thread_mutex.h:28
Structure to store things which are per connection.
Definition: httpd.h:1193
A structure to contain connection state information.
Definition: httpd.h:1340
Definition: motorz.h:136
ap_pod_t * pod
Definition: motorz.h:137
apr_proc_mutex_t * mutex
Definition: motorz.h:139
ap_listen_rec * listeners
Definition: motorz.h:138
Definition: motorz.h:175
request_rec * r
Definition: motorz.h:184
conn_state_t cs
Definition: motorz.h:190
apr_socket_t * sock
Definition: motorz.h:178
apr_bucket_alloc_t * ba
Definition: motorz.h:179
apr_pool_t * pool
Definition: motorz.h:176
motorz_timer_t timer
Definition: motorz.h:192
apr_pollfd_t pfd
Definition: motorz.h:188
ap_sb_handle_t * sbh
Definition: motorz.h:180
conn_rec * c
Definition: motorz.h:182
int suspended
Definition: motorz.h:186
motorz_core_t * mz
Definition: motorz.h:177
Definition: motorz.h:117
apr_thread_mutex_t * mtx
Definition: motorz.h:129
int first_server_limit
Definition: motorz.h:120
ap_unixd_mpm_retained_data * mpm
Definition: motorz.h:118
apr_pool_t * pool
Definition: motorz.h:128
int max_daemons_limit
Definition: motorz.h:127
apr_thread_pool_t * workers
Definition: motorz.h:132
apr_pollset_t * pollset
Definition: motorz.h:130
apr_skiplist * timeout_ring
Definition: motorz.h:131
int maxclients_reported
Definition: motorz.h:121
Definition: motorz.h:151
motorz_poll_type_e type
Definition: motorz.h:152
void * baton
Definition: motorz.h:153
Definition: motorz.h:165
motorz_timer_cb cb
Definition: motorz.h:167
void * baton
Definition: motorz.h:168
apr_time_t expires
Definition: motorz.h:166
apr_pool_t * pool
Definition: motorz.h:169
motorz_core_t * mz
Definition: motorz.h:170
A structure that represents the current request.
Definition: httpd.h:856
common stuff that unix MPMs will want
Apache Mutex support library.
Apache date-time handling functions.
Worker MPM defaults.