-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmod_vhost_maxclients.c
571 lines (481 loc) · 20.5 KB
/
mod_vhost_maxclients.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/*
** mod_vhost_maxclients - Max Clients per VitualHost
**
** Copyright (c) MATSUMOTO Ryosuke 2015 -
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*/
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_protocol.h"
#include "http_core.h"
#include "http_log.h"
#include "util_time.h"
#include "ap_mpm.h"
#include "apr_strings.h"
#include "ap_regex.h"
#include "scoreboard.h"
#define MODULE_NAME "mod_vhost_maxclients"
#define MODULE_VERSION "0.7.0"
#if (AP_SERVER_MINORVERSION_NUMBER > 2)
#define __APACHE24__
#endif
#ifdef __APACHE24__
#define ap_get_scoreboard_worker ap_get_scoreboard_worker_from_indexes
#endif
#define _log_debug \
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, "DEBUG: " MODULE_NAME "/" MODULE_VERSION "%s:%d", __func__, __LINE__)
#ifdef __APACHE24__
#include "http_main.h"
#else
#define ap_server_conf NULL
#endif
#define VHOST_MAXEXTENSIONS 16
#define AP_CTIME_COMPACT_LEN 20
#if !defined(__APACHE24__) && defined(_WIN32)
/*
* libhttpd.dll does not export following variables.
* This won't work correctly, but working well for other functional.
*/
int ap_extended_status = 0;
#endif
module AP_MODULE_DECLARE_DATA vhost_maxclients_module;
static int vhost_maxclients_server_limit, vhost_maxclients_thread_limit;
static apr_file_t *vhost_maxclients_log_fp = NULL;
typedef struct {
/* vhost max clinetns */
int dryrun;
const char *log_path;
signed int vhost_maxclients;
signed int vhost_maxclients_log;
signed int vhost_maxclients_per_ip;
apr_array_header_t *ignore_extensions;
apr_array_header_t *ignore_request_regexp;
unsigned int vhost_maxclients_time_from;
unsigned int vhost_maxclients_time_to;
ap_regex_t *regexpc;
} vhost_maxclients_config;
#ifndef __APACHE24__
static apr_status_t ap_recent_ctime_compact(char *date_str, apr_time_t t)
{
apr_time_exp_t xt;
int real_year;
int real_month;
ap_explode_recent_localtime(&xt, t);
real_year = 1900 + xt.tm_year;
real_month = xt.tm_mon + 1;
*date_str++ = real_year / 1000 + '0';
*date_str++ = real_year % 1000 / 100 + '0';
*date_str++ = real_year % 100 / 10 + '0';
*date_str++ = real_year % 10 + '0';
*date_str++ = '-';
*date_str++ = real_month / 10 + '0';
*date_str++ = real_month % 10 + '0';
*date_str++ = '-';
*date_str++ = xt.tm_mday / 10 + '0';
*date_str++ = xt.tm_mday % 10 + '0';
*date_str++ = ' ';
*date_str++ = xt.tm_hour / 10 + '0';
*date_str++ = xt.tm_hour % 10 + '0';
*date_str++ = ':';
*date_str++ = xt.tm_min / 10 + '0';
*date_str++ = xt.tm_min % 10 + '0';
*date_str++ = ':';
*date_str++ = xt.tm_sec / 10 + '0';
*date_str++ = xt.tm_sec % 10 + '0';
*date_str++ = 0;
return APR_SUCCESS;
}
#endif
#define vhost_maxclients_log_error(r, fmt, ...) _vhost_maxclients_log_error(r, apr_psprintf(r->pool, fmt, __VA_ARGS__))
static void *_vhost_maxclients_log_error(request_rec *r, char *log_body)
{
char log_time[AP_CTIME_COMPACT_LEN];
char *log;
/* example for compact format: "1993-06-30 21:49:08" */
/* 1234567890123456789 */
#ifdef __APACHE24__
int time_len = AP_CTIME_COMPACT_LEN;
ap_recent_ctime_ex(log_time, r->request_time, AP_CTIME_OPTION_COMPACT, &time_len);
#else
ap_recent_ctime_compact(log_time, r->request_time);
#endif
log = apr_psprintf(r->pool, "%s %s\n", log_time, log_body);
apr_file_puts(log, vhost_maxclients_log_fp);
apr_file_flush(vhost_maxclients_log_fp);
}
static void *vhost_maxclients_create_server_config(apr_pool_t *p, server_rec *s)
{
vhost_maxclients_config *scfg = (vhost_maxclients_config *)apr_pcalloc(p, sizeof(*scfg));
scfg->dryrun = -1;
scfg->log_path = NULL;
scfg->vhost_maxclients = 0;
scfg->vhost_maxclients_log = 0;
scfg->vhost_maxclients_per_ip = 0;
scfg->ignore_extensions = apr_array_make(p, VHOST_MAXEXTENSIONS, sizeof(char *));
scfg->ignore_request_regexp = apr_array_make(p, 1, sizeof(char *));
scfg->vhost_maxclients_time_from = 0;
scfg->vhost_maxclients_time_to = 2359;
scfg->regexpc = NULL;
return scfg;
}
static void *vhost_maxclients_create_server_merge_conf(apr_pool_t *p, void *b, void *n)
{
vhost_maxclients_config *base = (vhost_maxclients_config *)b;
vhost_maxclients_config *new = (vhost_maxclients_config *)n;
vhost_maxclients_config *scfg = (vhost_maxclients_config *)apr_pcalloc(p, sizeof(*scfg));
if (new->dryrun > -1) {
scfg->dryrun = new->dryrun;
} else {
scfg->dryrun = base->dryrun;
}
scfg->log_path = base->log_path;
scfg->vhost_maxclients = new->vhost_maxclients;
scfg->vhost_maxclients_log = new->vhost_maxclients_log;
scfg->vhost_maxclients_per_ip = new->vhost_maxclients_per_ip;
scfg->ignore_extensions = new->ignore_extensions;
scfg->ignore_request_regexp = new->ignore_request_regexp;
scfg->vhost_maxclients_time_from = new->vhost_maxclients_time_from;
scfg->vhost_maxclients_time_to = new->vhost_maxclients_time_to;
scfg->regexpc = base->regexpc;
return scfg;
}
static int check_extension(char *filename, apr_array_header_t *exts)
{
int i;
for (i = 0; i < exts->nelts; i++) {
const char *extension = ((char **)exts->elts)[i];
ssize_t name_len = strlen(filename) - strlen(extension);
if (name_len >= 0 && strcmp(&filename[name_len], extension) == 0)
return 1;
}
return 0;
}
static int check_time_slot(apr_pool_t *p, unsigned int from, unsigned int to)
{
unsigned int cur;
apr_time_exp_t tm;
apr_time_exp_lt(&tm, apr_time_now());
cur = atoi(apr_psprintf(p, "%02d%02d", tm.tm_hour, tm.tm_min));
if (from > to){
to += 2400;
}
if ((from < cur) && (to > cur)){
return 0;
}
return 1;
}
static char *build_vhostport_name(request_rec *r)
{
#ifdef __APACHE24__
ssize_t vhostport_len;
char *vhostport;
vhostport_len = strlen(r->hostname) + sizeof(":65536");
vhostport = apr_pcalloc(r->pool, vhostport_len);
apr_snprintf(vhostport, vhostport_len, "%s:%d", r->hostname, r->connection->local_addr->port);
return vhostport;
#else
return (char *)r->hostname;
#endif
}
static int vhost_maxclients_handler(request_rec *r)
{
int i, j;
int vhost_count = 0;
int ip_count = 0;
char *vhostport;
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(r->server->module_config, &vhost_maxclients_module);
if (!ap_is_initial_req(r)) {
return DECLINED;
}
if (scfg->vhost_maxclients <= 0) {
return DECLINED;
}
if (r->hostname == NULL) {
return DECLINED;
}
if (r->filename == NULL) {
return DECLINED;
}
if (!ap_extended_status) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "DEBUG: only used when ExtendedStatus On");
return DECLINED;
}
/* check ignore extesions */
if (check_extension(r->filename, scfg->ignore_extensions)) {
return DECLINED;
}
/* check time */
if (check_time_slot(r->pool, scfg->vhost_maxclients_time_from, scfg->vhost_maxclients_time_to)) {
return DECLINED;
}
/* build vhostport name */
vhostport = build_vhostport_name(r);
for (i = 0; i < vhost_maxclients_server_limit; ++i) {
for (j = 0; j < vhost_maxclients_thread_limit; ++j) {
worker_score *ws_record = ap_get_scoreboard_worker(i, j);
#ifdef __APACHE24__
char *client_ip = r->connection->client_ip;
#else
char *client_ip = r->connection->remote_ip;
#endif
switch (ws_record->status) {
case SERVER_BUSY_READ:
case SERVER_BUSY_WRITE:
case SERVER_BUSY_KEEPALIVE:
case SERVER_BUSY_LOG:
case SERVER_BUSY_DNS:
case SERVER_CLOSING:
case SERVER_GRACEFUL:
/* check maxclients per vhost */
if (strcmp(vhostport, ws_record->vhost) == 0) {
if (scfg->regexpc != NULL && !ap_regexec(scfg->regexpc, ws_record->request, 0, NULL, 0)){
break;
}
vhost_count++;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "DEBUG: (increment %s): %d/%d", vhostport,
vhost_count, scfg->vhost_maxclients);
/* logging only for vhost_maxclients_log */
if (scfg->vhost_maxclients_log > 0 && vhost_count > scfg->vhost_maxclients_log) {
if (vhost_maxclients_log_fp != NULL) {
vhost_maxclients_log_error(
r, "LOG-ONLY-VHOST_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s", vhostport,
vhost_count, scfg->vhost_maxclients_log, client_ip, r->uri, r->filename);
} else {
ap_log_error(
APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"NOTICE: LOG-ONLY-VHOST_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s",
vhostport, vhost_count, scfg->vhost_maxclients_log, client_ip, r->uri, r->filename);
}
}
if (vhost_count > scfg->vhost_maxclients) {
if (scfg->dryrun > 0) {
if (vhost_maxclients_log_fp != NULL) {
vhost_maxclients_log_error(
r, "DRY-RUN-VHOST_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s", vhostport,
vhost_count, scfg->vhost_maxclients, client_ip, r->uri, r->filename);
} else {
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"DRY-RUN-VHOST_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s",
vhostport, vhost_count, scfg->vhost_maxclients, client_ip, r->uri, r->filename);
}
} else {
if (vhost_maxclients_log_fp != NULL) {
vhost_maxclients_log_error(
r, "VHOST_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s", vhostport,
vhost_count, scfg->vhost_maxclients, client_ip, r->uri, r->filename);
} else {
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"VHOST_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s", vhostport,
vhost_count, scfg->vhost_maxclients, client_ip, r->uri, r->filename);
}
}
return (scfg->dryrun > 0) ? DECLINED : HTTP_SERVICE_UNAVAILABLE;
}
/* check maxclients per ip in same vhost */
if (scfg->vhost_maxclients_per_ip > 0) {
if (strcmp(client_ip, ws_record->client) == 0) {
ip_count++;
if (ip_count > scfg->vhost_maxclients_per_ip) {
if (scfg->dryrun > 0) {
if (vhost_maxclients_log_fp != NULL) {
vhost_maxclients_log_error(
r, "DRY-RUN-CLIENT_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s",
vhostport, ip_count, scfg->vhost_maxclients_per_ip, client_ip, r->uri, r->filename);
} else {
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "NOTICE: DRY-RUN-CLIENT_COUNT return "
"503 from %s : %d / %d client_ip: %s "
"uri: %s filename: %s",
vhostport, ip_count, scfg->vhost_maxclients_per_ip, client_ip, r->uri, r->filename);
}
} else {
if (vhost_maxclients_log_fp != NULL) {
vhost_maxclients_log_error(
r, "CLIENT_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s", vhostport,
ip_count, scfg->vhost_maxclients_per_ip, client_ip, r->uri, r->filename);
} else {
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"CLIENT_COUNT return 503 from %s : %d / %d client_ip: %s uri: %s filename: %s",
vhostport, ip_count, scfg->vhost_maxclients_per_ip, client_ip, r->uri, r->filename);
}
}
return (scfg->dryrun > 0) ? DECLINED : HTTP_SERVICE_UNAVAILABLE;
}
}
}
}
break;
default:
break;
}
}
}
/* not reached vhost_maxclients */
return DECLINED;
}
static const char *set_vhost_maxclients_dryrun(cmd_parms *parms, void *mconfig, int flag)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
scfg->dryrun = flag;
return NULL;
}
static const char *set_vhost_maxclientsvhost(cmd_parms *parms, void *mconfig, const char *arg1)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
signed long int limit = strtol(arg1, (char **)NULL, 10);
if ((limit > 65535) || (limit < 0)) {
return "Integer overflow or invalid number";
}
scfg->vhost_maxclients = limit;
return NULL;
}
static const char *set_vhost_maxclientsvhost_log(cmd_parms *parms, void *mconfig, const char *arg1)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
signed long int limit = strtol(arg1, (char **)NULL, 10);
if ((limit > 65535) || (limit < 0)) {
return "Integer overflow or invalid number";
}
scfg->vhost_maxclients_log = limit;
return NULL;
}
static const char *set_vhost_maxclientsvhost_log_path(cmd_parms *parms, void *mconfig, const char *arg1)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
scfg->log_path = arg1;
return NULL;
}
static const char *set_vhost_maxclientsvhost_perip(cmd_parms *parms, void *mconfig, const char *arg1)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
signed long int limit = strtol(arg1, (char **)NULL, 10);
if ((limit > 65535) || (limit < 0)) {
return "Integer overflow or invalid number";
}
scfg->vhost_maxclients_per_ip = limit;
return NULL;
}
static const char *set_vhost_ignore_extensions(cmd_parms *parms, void *mconfig, const char *arg)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
if (VHOST_MAXEXTENSIONS < scfg->ignore_extensions->nelts) {
return "the number of ignore extensions exceeded";
}
*(const char **)apr_array_push(scfg->ignore_extensions) = arg;
return NULL;
}
static const char *set_vhost_ignore_request_regexp(cmd_parms *parms, void *mconfig, const char *arg)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
APR_ARRAY_PUSH(scfg->ignore_request_regexp,const char *) = arg;
char **regexpi = (char **) scfg->ignore_request_regexp->elts;
scfg->regexpc = ap_pregcomp(parms->pool, (char *)regexpi[0], AP_REG_EXTENDED|AP_REG_ICASE);
if (scfg->regexpc == NULL)
return "regexp error";
return NULL;
}
static const char *set_vhost_maxclients_time(cmd_parms *parms, void *mconfig, const char *arg1, const char *arg2)
{
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(parms->server->module_config, &vhost_maxclients_module);
scfg->vhost_maxclients_time_from = atoi(arg1);
scfg->vhost_maxclients_time_to = atoi(arg2);
if(scfg->vhost_maxclients_time_from < 0 || scfg->vhost_maxclients_time_from > 2359){
return "VhostMaxClientsTimeSlot_From is invalid. should be set range 0 < VhostMaxClientsTimeSlot_From < 2359";
}
if (scfg->vhost_maxclients_time_to < 0 || scfg->vhost_maxclients_time_to > 2359){
return "VhostMaxClientsTimeSlot_To is invalid. should be set range 0 < VhostMaxClientsTimeSlot_To < 2359";
}
return NULL;
}
static command_rec vhost_maxclients_cmds[] = {
AP_INIT_FLAG("VhostMaxClientsDryRun", set_vhost_maxclients_dryrun, NULL, ACCESS_CONF | RSRC_CONF,
"Enable dry-run which don't return 503, logging only: On / Off (default Off)"),
AP_INIT_TAKE1("VhostMaxClients", set_vhost_maxclientsvhost, NULL, RSRC_CONF | ACCESS_CONF,
"maximum connections per Vhost"),
AP_INIT_TAKE1("VhostMaxClientsLogOnly", set_vhost_maxclientsvhost_log, NULL, RSRC_CONF | ACCESS_CONF,
"loggign only: maximum connections per Vhost"),
AP_INIT_TAKE1("VhostMaxClientsLogPath", set_vhost_maxclientsvhost_log_path, NULL, RSRC_CONF | ACCESS_CONF,
"logging file path instead of error_log"),
AP_INIT_TAKE1("VhostMaxClientsPerIP", set_vhost_maxclientsvhost_perip, NULL, RSRC_CONF | ACCESS_CONF,
"maximum connections per IP of Vhost"),
AP_INIT_ITERATE("IgnoreVhostMaxClientsExt", set_vhost_ignore_extensions, NULL, ACCESS_CONF | RSRC_CONF,
"Set Ignore Extensions."),
AP_INIT_TAKE1("IgnoreVhostMaxClientsRequestRegexp", set_vhost_ignore_request_regexp, NULL, ACCESS_CONF | RSRC_CONF,
"Set Ignore Request."),
AP_INIT_TAKE2("VhostMaxClientsTimeSlot", set_vhost_maxclients_time, NULL, RSRC_CONF | ACCESS_CONF,
"Time to enable the VhostMaxClients. (default 0:00 ~ 23:59)"),
{NULL},
};
static int vhost_maxclients_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *server)
{
void *data;
const char *userdata_key = "vhost_maxclients_init";
vhost_maxclients_config *scfg =
(vhost_maxclients_config *)ap_get_module_config(server->module_config, &vhost_maxclients_module);
apr_pool_userdata_get(&data, userdata_key, server->process->pool);
if (!data) {
apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, server->process->pool);
return OK;
}
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &vhost_maxclients_thread_limit);
ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &vhost_maxclients_server_limit);
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
MODULE_NAME "/" MODULE_VERSION " enabled: %d/%d thread_limit/server_limit",
vhost_maxclients_thread_limit, vhost_maxclients_server_limit);
/* open custom log instead of error_log */
if (scfg->log_path != NULL) {
if (apr_file_open(&vhost_maxclients_log_fp, scfg->log_path, APR_WRITE | APR_APPEND | APR_CREATE, APR_OS_DEFAULT,
p) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, server, "%s ERROR %s: vhost_maxclients log file oepn failed: %s",
MODULE_NAME, __func__, scfg->log_path);
return HTTP_INTERNAL_SERVER_ERROR;
}
}
return OK;
}
static void vhost_maxclients_register_hooks(apr_pool_t *p)
{
ap_hook_post_config(vhost_maxclients_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_access_checker(vhost_maxclients_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
#ifdef __APACHE24__
AP_DECLARE_MODULE(vhost_maxclients) = {
#else
module AP_MODULE_DECLARE_DATA vhost_maxclients_module = {
#endif
STANDARD20_MODULE_STUFF, NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
vhost_maxclients_create_server_config, /* create per-server config
structures */
vhost_maxclients_create_server_merge_conf, /* merge per-server config structures */
vhost_maxclients_cmds, /* table of config file commands */
vhost_maxclients_register_hooks};