1
diff -urN peruser.rc1/docs/conf/extra/httpd-mpm.conf.in peruser.rc2/docs/conf/extra/httpd-mpm.conf.in
2
--- peruser.rc1/docs/conf/extra/httpd-mpm.conf.in 2011-11-06 09:45:44.000000000 +0100
3
+++ peruser.rc2/docs/conf/extra/httpd-mpm.conf.in 2011-11-05 18:16:00.000000000 +0100
9
-# IdleTimeout: maximum time before a child is killed after being idle, 0 to disable
10
-# ExpireTimeout: maximum time a child can live, 0 to disable
11
-# MinSpareProcessors: minimum number of idle children, to handle request spikes
12
-# MaxProcessors: Maximum number of processors per vhost
13
-# ServerLimit: maximum value of MaxClients for this run of Apache
14
-# MaxClients: maximum number of children alive at the same time
15
-# MaxMultiplexers: maximum number of multiplexers the server can have
16
-<IfModule mpm_peruser_module>
19
- MinSpareProcessors 2
27
# StartServers: number of server processes to start
28
# MinSpareServers: minimum number of server processes which are kept spare
29
diff -urN peruser.rc1/modules/generators/mod_status.c peruser.rc2/modules/generators/mod_status.c
30
--- peruser.rc1/modules/generators/mod_status.c 2011-11-06 09:45:44.000000000 +0100
31
+++ peruser.rc2/modules/generators/mod_status.c 2011-11-06 09:44:35.000000000 +0100
34
/* ID values for command table */
36
-#define STAT_OPT_END -1
37
-#define STAT_OPT_REFRESH 0
38
-#define STAT_OPT_NOTABLE 1
39
-#define STAT_OPT_AUTO 2
40
-#define STAT_OPT_STATS 3
41
+#define STAT_OPT_END -1
42
+#define STAT_OPT_REFRESH 0
43
+#define STAT_OPT_NOTABLE 1
44
+#define STAT_OPT_AUTO 2
45
+#define STAT_OPT_PERUSER_STATS 3
50
{STAT_OPT_REFRESH, "refresh", "Refresh"},
51
{STAT_OPT_NOTABLE, "notable", NULL},
52
{STAT_OPT_AUTO, "auto", NULL},
53
- {STAT_OPT_STATS, "stats", NULL},
54
+ {STAT_OPT_PERUSER_STATS, "peruser_stats", NULL},
55
{STAT_OPT_END, NULL, NULL}
64
worker_score *ws_record;
65
process_score *ps_record;
75
pid_buffer = apr_palloc(r->pool, server_limit * sizeof(pid_t));
76
stat_buffer = apr_palloc(r->pool, server_limit * thread_limit * sizeof(char));
79
case STAT_OPT_NOTABLE:
82
- case STAT_OPT_STATS:
84
+ case STAT_OPT_PERUSER_STATS:
88
ap_set_content_type(r, "text/plain; charset=ISO-8859-1");
90
(short_report ? AP_STATUS_SHORT : 0) |
91
(no_table_report ? AP_STATUS_NOTABLE : 0) |
92
(ap_extended_status ? AP_STATUS_EXTENDED : 0) |
93
- (stats_report ? AP_STATUS_STATS : 0);
94
+ (peruser_stats ? AP_STATUS_PERUSER_STATS : 0);
96
ap_run_status_hook(r, flags);
98
diff -urN peruser.rc1/modules/generators/mod_status.h peruser.rc2/modules/generators/mod_status.h
99
--- peruser.rc1/modules/generators/mod_status.h 2011-11-06 09:45:44.000000000 +0100
100
+++ peruser.rc2/modules/generators/mod_status.h 2011-11-06 09:44:35.000000000 +0100
102
#include "ap_config.h"
105
-#define AP_STATUS_SHORT (0x1) /* short, non-HTML report requested */
106
-#define AP_STATUS_NOTABLE (0x2) /* HTML report without tables */
107
-#define AP_STATUS_EXTENDED (0x4) /* detailed report */
108
-#define AP_STATUS_STATS (0x8) /* extended user statistics report */
109
+#define AP_STATUS_SHORT (0x1) /* short, non-HTML report requested */
110
+#define AP_STATUS_NOTABLE (0x2) /* HTML report without tables */
111
+#define AP_STATUS_EXTENDED (0x4) /* detailed report */
112
+#define AP_STATUS_PERUSER_STATS (0x8) /* peruser mpm extended status */
115
#define STATUS_DECLARE(type) type
116
diff -urN peruser.rc1/server/mpm/experimental/peruser/mpm.h peruser.rc2/server/mpm/experimental/peruser/mpm.h
117
--- peruser.rc1/server/mpm/experimental/peruser/mpm.h 2011-11-06 09:45:44.000000000 +0100
118
+++ peruser.rc2/server/mpm/experimental/peruser/mpm.h 2011-11-06 09:44:35.000000000 +0100
120
#define SERVER_DYING 1
121
#define SERVER_ALIVE 2
123
-typedef struct ap_ctable {
125
- unsigned char status;
128
static const char* child_clone();
131
diff -urN peruser.rc1/server/mpm/experimental/peruser/peruser.c peruser.rc2/server/mpm/experimental/peruser/peruser.c
132
--- peruser.rc1/server/mpm/experimental/peruser/peruser.c 2011-11-06 09:45:44.000000000 +0100
133
+++ peruser.rc2/server/mpm/experimental/peruser/peruser.c 2011-11-06 09:44:35.000000000 +0100
136
/* ====================================================================
137
* The Apache Software License, Version 1.1
140
#error "Peruser MPM requres shared memory support."
144
/* should be APR-ized */
149
#include <sys/times.h>
152
#ifdef MPM_PERUSER_DEBUG
153
# define _DBG(text,par...) \
154
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, \
156
#define AP_PERUSER_THISCHILD -1
157
#define AP_PERUSER_OTHERCHILD -2
160
/* Limit on the total --- clients will be locked out if more servers than
161
* this are needed. It is intended solely to keep the server from crashing
162
* when things get out of hand.
163
@@ -206,20 +202,20 @@
167
-int ap_threads_per_child=0; /* Worker threads per child */
168
+int ap_threads_per_child = 0; /* Worker threads per child */
169
static apr_proc_mutex_t *accept_mutex;
170
-static int ap_min_processors=DEFAULT_MIN_PROCESSORS;
171
-static int ap_min_free_processors=DEFAULT_MIN_FREE_PROCESSORS;
172
-static int ap_max_free_processors=DEFAULT_MAX_FREE_PROCESSORS;
173
-static int ap_max_processors=DEFAULT_MAX_PROCESSORS;
174
-static int ap_min_multiplexers=DEFAULT_MIN_MULTIPLEXERS;
175
-static int ap_max_multiplexers=DEFAULT_MAX_MULTIPLEXERS;
176
-static int ap_daemons_limit=0; /* MaxClients */
177
-static int expire_timeout=DEFAULT_EXPIRE_TIMEOUT;
178
-static int idle_timeout=DEFAULT_IDLE_TIMEOUT;
179
-static int multiplexer_idle_timeout=DEFAULT_MULTIPLEXER_IDLE_TIMEOUT;
180
-static int processor_wait_timeout=DEFAULT_PROCESSOR_WAIT_TIMEOUT;
181
-static int processor_wait_steps=DEFAULT_PROCESSOR_WAIT_STEPS;
182
+static int ap_min_processors = DEFAULT_MIN_PROCESSORS;
183
+static int ap_min_free_processors = DEFAULT_MIN_FREE_PROCESSORS;
184
+static int ap_max_free_processors = DEFAULT_MAX_FREE_PROCESSORS;
185
+static int ap_max_processors = DEFAULT_MAX_PROCESSORS;
186
+static int ap_min_multiplexers = DEFAULT_MIN_MULTIPLEXERS;
187
+static int ap_max_multiplexers = DEFAULT_MAX_MULTIPLEXERS;
188
+static int ap_daemons_limit = 0; /* MaxClients */
189
+static int expire_timeout = DEFAULT_EXPIRE_TIMEOUT;
190
+static int idle_timeout = DEFAULT_IDLE_TIMEOUT;
191
+static int multiplexer_idle_timeout = DEFAULT_MULTIPLEXER_IDLE_TIMEOUT;
192
+static int processor_wait_timeout = DEFAULT_PROCESSOR_WAIT_TIMEOUT;
193
+static int processor_wait_steps = DEFAULT_PROCESSOR_WAIT_STEPS;
194
static int server_limit = DEFAULT_SERVER_LIMIT;
195
static int first_server_limit;
196
static int changed_limit_at_restart;
197
@@ -233,11 +229,11 @@
201
- const char *name; /* Server environment's unique string identifier */
202
+ const char *name; /* Server environment's unique string identifier */
204
/* security settings */
205
- uid_t uid; /* user id */
206
- gid_t gid; /* group id */
207
+ uid_t uid; /* user id */
208
+ gid_t gid; /* group id */
209
const char *chroot; /* directory to chroot() to, can be null */
211
const char *cgroup; /* cgroup directory, can be null */
212
@@ -250,13 +246,18 @@
216
- int input; /* The socket descriptor */
217
- int output; /* The socket descriptor */
218
+ int input; /* The socket descriptor */
219
+ int output; /* The socket descriptor */
222
/* we use these to reduce log clutter (report only on first failure) */
223
short error_cgroup; /* When writing pid to cgroup fails */
224
- short error_pass; /* When unable to pass request to the processor (eg all workers busy) */
225
+ short error_pass; /* When unable to pass request to the processor */
228
+ unsigned long stats_requests; /* requests handled */
229
+ unsigned long stats_connections; /* connections handled */
230
+ unsigned long stats_dropped; /* connections dropped because multiplexer was not able to pass */
234
@@ -270,13 +271,12 @@
242
- int id; /* index in child_info_table */
243
- pid_t pid; /* process id */
244
- int status; /* status of child */
245
+ int id; /* index in child_info_table */
246
+ pid_t pid; /* process id */
247
+ int status; /* status of child */
248
int type; /* multiplexer or processor */
255
- /* identification */
256
- int id; /* index in child_info_table */
257
- pid_t pid; /* process id */
258
- int status; /* status of child */
259
- int type; /* multiplexer or processor */
260
- apr_time_t last_used;
261
-} child_grace_info_t;
266
} child_info_control;
268
@@ -314,22 +304,18 @@
269
short missing_senv_reported;
270
} peruser_server_conf;
273
typedef struct peruser_header
280
/* Tables used to determine the user and group each child process should
281
* run as. The hash table is used to correlate a server name with a child
284
static apr_size_t child_info_size;
285
static child_info *child_info_image = NULL;
286
-static child_grace_info_t *child_grace_info_table;
287
-struct ap_ctable *ap_child_table;
289
#define NUM_CHILDS (child_info_image != NULL ? child_info_image->control->num : 0)
290
#define CHILD_INFO_TABLE (child_info_image != NULL ? child_info_image->table : NULL)
291
@@ -344,16 +330,10 @@
293
static /* but must be exported to mpm_winnt */
295
- apr_shm_t *child_info_shm = NULL;
296
- apr_shm_t *server_env_shm = NULL;
297
+apr_shm_t *child_info_shm = NULL;
298
+apr_shm_t *server_env_shm = NULL;
302
- * The max child slot ever assigned, preserved across restarts. Necessary
303
- * to deal with MaxClients changes across AP_SIG_GRACEFUL restarts. We
304
- * use this value to optimize routines that have to scan the entire scoreboard.
306
-int ap_max_daemons_limit = -1;
307
server_rec *ap_server_conf;
309
module AP_MODULE_DECLARE_DATA mpm_peruser_module;
311
static apr_file_t *pipe_of_death_in = NULL;
312
static apr_file_t *pipe_of_death_out = NULL;
315
/* one_process --- debugging mode variable; can be set from the command line
316
* with the -X flag. If set, this gets you the child_main loop running
317
* in the process which originally started up (no detach, no make_child),
318
@@ -376,13 +355,13 @@
320
static int one_process = 0;
322
-static apr_pool_t *pconf; /* Pool for config stuff */
323
-static apr_pool_t *pchild; /* Pool for httpd child stuff */
324
+static apr_pool_t *pconf; /* Pool for config stuff */
325
+static apr_pool_t *pchild; /* Pool for httpd child stuff */
327
-static pid_t ap_my_pid; /* it seems silly to call getpid all the time */
328
+static pid_t ap_my_pid; /* it seems silly to call getpid all the time */
329
static pid_t parent_pid;
330
static int my_child_num;
331
-ap_generation_t volatile ap_my_generation=0;
332
+ap_generation_t volatile ap_my_generation = 0;
336
@@ -391,12 +370,11 @@
338
static int die_now = 0;
340
-int grace_children = 0;
341
-int grace_children_alive = 0;
342
int server_env_cleanup = 1;
343
const char *multiplexer_chroot = NULL;
344
+server_env_t *multiplexer_senv;
346
-// function added to mod_ssl and exported (there was nothing useful for us in the current api)
347
+/* function added to mod_ssl and exported (there was nothing useful for us) */
348
typedef int (*ssl_server_is_https_t)(server_rec*);
349
ssl_server_is_https_t ssl_server_is_https = NULL;
351
@@ -409,28 +387,28 @@
353
static void chdir_for_gprof(void)
355
- core_server_config *sconf =
356
- ap_get_module_config(ap_server_conf->module_config, &core_module);
357
+ core_server_config *sconf =
358
+ ap_get_module_config(ap_server_conf->module_config, &core_module);
359
char *dir = sconf->gprof_dir;
365
- int len = strlen(sconf->gprof_dir) - 1;
366
- if(*(dir + len) == '%') {
368
- apr_snprintf(buf, sizeof(buf), "%sgprof.%d", dir, (int)getpid());
370
- use_dir = ap_server_root_relative(pconf, buf[0] ? buf : dir);
371
- res = apr_dir_make(use_dir, 0755, pconf);
372
- if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
373
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
374
- "gprof: error creating directory %s", dir);
377
+ int len = strlen(sconf->gprof_dir) - 1;
378
+ if(*(dir + len) == '%') {
380
+ apr_snprintf(buf, sizeof(buf), "%sgprof.%d", dir, (int)getpid());
382
+ use_dir = ap_server_root_relative(pconf, buf[0] ? buf : dir);
383
+ res = apr_dir_make(use_dir, 0755, pconf);
384
+ if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
385
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
386
+ "gprof: error creating directory %s", dir);
390
- use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
391
+ use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
395
@@ -441,11 +419,13 @@
397
char* child_type_string(int type)
401
- case CHILD_TYPE_MULTIPLEXER: return "MULTIPLEXER";
402
- case CHILD_TYPE_PROCESSOR: return "PROCESSOR";
403
- case CHILD_TYPE_WORKER: return "WORKER";
405
+ case CHILD_TYPE_MULTIPLEXER:
406
+ return "MULTIPLEXER";
407
+ case CHILD_TYPE_PROCESSOR:
408
+ return "PROCESSOR";
409
+ case CHILD_TYPE_WORKER:
414
@@ -453,32 +433,47 @@
416
char* child_status_string(int status)
420
- case CHILD_STATUS_STANDBY: return "STANDBY";
421
- case CHILD_STATUS_STARTING: return "STARTING";
422
- case CHILD_STATUS_READY: return "READY";
423
- case CHILD_STATUS_ACTIVE: return "ACTIVE";
424
- case CHILD_STATUS_RESTART: return "RESTART";
426
+ case CHILD_STATUS_STANDBY:
428
+ case CHILD_STATUS_STARTING:
430
+ case CHILD_STATUS_READY:
432
+ case CHILD_STATUS_ACTIVE:
434
+ case CHILD_STATUS_RESTART:
441
-char* scoreboard_status_string(int status) {
444
- case SERVER_DEAD: return "DEAD";
445
- case SERVER_STARTING: return "STARTING";
446
- case SERVER_READY: return "READY";
447
- case SERVER_BUSY_READ: return "BUSY_READ";
448
- case SERVER_BUSY_WRITE: return "BUSY_WRITE";
449
- case SERVER_BUSY_KEEPALIVE: return "BUSY_KEEPALIVE";
450
- case SERVER_BUSY_LOG: return "BUSY_LOG";
451
- case SERVER_BUSY_DNS: return "BUSY_DNS";
452
- case SERVER_CLOSING: return "CLOSING";
453
- case SERVER_GRACEFUL: return "GRACEFUL";
454
- case SERVER_NUM_STATUS: return "NUM_STATUS";
455
+char* scoreboard_status_string(int status)
460
+ case SERVER_STARTING:
464
+ case SERVER_BUSY_READ:
465
+ return "BUSY_READ";
466
+ case SERVER_BUSY_WRITE:
467
+ return "BUSY_WRITE";
468
+ case SERVER_BUSY_KEEPALIVE:
469
+ return "BUSY_KEEPALIVE";
470
+ case SERVER_BUSY_LOG:
472
+ case SERVER_BUSY_DNS:
474
+ case SERVER_CLOSING:
476
+ case SERVER_GRACEFUL:
478
+ case SERVER_NUM_STATUS:
479
+ return "NUM_STATUS";
483
@@ -487,43 +482,44 @@
484
void dump_child_table()
486
#ifdef MPM_PERUSER_DEBUG
488
- server_env_t *senv;
490
+ server_env_t *senv;
492
- _DBG("%-3s %-5s %-8s %-12s %-4s %-4s %-25s %5s %6s %7s",
493
- "ID", "PID", "STATUS", "TYPE", "UID", "GID", "CHROOT", "INPUT", "OUTPUT", "SOCK_FD");
494
+ _DBG("%-3s %-5s %-8s %-12s %-4s %-4s %-25s %5s %6s %7s",
495
+ "ID", "PID", "STATUS", "TYPE", "UID", "GID", "CHROOT", "INPUT",
496
+ "OUTPUT", "SOCK_FD");
498
- for(x = 0; x < NUM_CHILDS; x++)
500
- senv = CHILD_INFO_TABLE[x].senv;
501
- _DBG("%-3d %-5d %-8s %-12s %-4d %-4d %-25s %-5d %-6d %-7d",
502
- CHILD_INFO_TABLE[x].id,
503
- CHILD_INFO_TABLE[x].pid,
504
- child_status_string(CHILD_INFO_TABLE[x].status),
505
- child_type_string(CHILD_INFO_TABLE[x].type),
506
- senv == NULL ? -1 : senv->uid,
507
- senv == NULL ? -1 : senv->gid,
508
- senv == NULL ? NULL : senv->chroot,
509
- senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->input,
510
- senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->output,
511
- CHILD_INFO_TABLE[x].sock_fd);
513
+ for(x = 0; x < NUM_CHILDS; x++)
515
+ senv = CHILD_INFO_TABLE[x].senv;
516
+ _DBG("%-3d %-5d %-8s %-12s %-4d %-4d %-25s %-5d %-6d %-7d",
517
+ CHILD_INFO_TABLE[x].id,
518
+ CHILD_INFO_TABLE[x].pid,
519
+ child_status_string(CHILD_INFO_TABLE[x].status),
520
+ child_type_string(CHILD_INFO_TABLE[x].type),
521
+ senv == NULL ? -1 : senv->uid,
522
+ senv == NULL ? -1 : senv->gid,
523
+ senv == NULL ? NULL : senv->chroot,
524
+ senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->input,
525
+ senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->output,
526
+ CHILD_INFO_TABLE[x].sock_fd);
531
void dump_server_env_image()
533
#ifdef MPM_PERUSER_DEBUG
535
- _DBG("%-3s %-7s %-7s %-7s", "N", "INPUT", "OUTPUT", "CHROOT");
536
- for(x = 0; x < NUM_SENV; x++)
538
- _DBG("%-3d %-7d %-7d %-7s", x, SENV[x].input, SENV[x].output, SENV[x].chroot);
541
+ _DBG("%-3s %-7s %-7s %-7s", "N", "INPUT", "OUTPUT", "CHROOT");
542
+ for(x = 0; x < NUM_SENV; x++)
544
+ _DBG("%-3d %-7d %-7d %-7s", x, SENV[x].input, SENV[x].output,
551
/* XXX - I don't know if TPF will ever use this module or not, so leave
552
* the ap_check_signals calls in but disable them - manoj */
553
#define ap_check_signals()
554
@@ -536,20 +532,20 @@
556
mpm_state = AP_MPMQ_STOPPING;
558
- if (CHILD_INFO_TABLE[my_child_num].type != CHILD_TYPE_MULTIPLEXER &&
559
- CHILD_INFO_TABLE[my_child_num].senv)
560
+ if (CHILD_INFO_TABLE[my_child_num].type != CHILD_TYPE_MULTIPLEXER
561
+ && CHILD_INFO_TABLE[my_child_num].senv)
563
- retval = close(CHILD_INFO_TABLE[my_child_num].senv->input);
564
- _DBG("close(CHILD_INFO_TABLE[%d].senv->input) = %d",
565
- my_child_num, retval);
567
- retval = close(CHILD_INFO_TABLE[my_child_num].senv->output);
568
- _DBG("close(CHILD_INFO_TABLE[%d].senv->output) = %d",
569
- my_child_num, retval);
570
+ retval = close(CHILD_INFO_TABLE[my_child_num].senv->input);
571
+ _DBG("close(CHILD_INFO_TABLE[%d].senv->input) = %d",
572
+ my_child_num, retval);
574
+ retval = close(CHILD_INFO_TABLE[my_child_num].senv->output);
575
+ _DBG("close(CHILD_INFO_TABLE[%d].senv->output) = %d",
576
+ my_child_num, retval);
580
- apr_pool_destroy(pchild);
581
+ apr_pool_destroy(pchild);
583
ap_mpm_pod_close(pod);
586
if (rv != APR_SUCCESS) {
587
const char *msg = "couldn't grab the accept mutex";
589
- if (ap_my_generation !=
590
- ap_scoreboard_image->global->running_generation) {
591
+ if (ap_my_generation != ap_scoreboard_image->global->running_generation)
593
ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, msg);
597
if (rv != APR_SUCCESS) {
598
const char *msg = "couldn't release the accept mutex";
600
- if (ap_my_generation !=
601
- ap_scoreboard_image->global->running_generation) {
602
+ if (ap_my_generation != ap_scoreboard_image->global->running_generation)
604
ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, msg);
605
/* don't exit here... we have a connection to
606
* process, after which point we'll see that the
607
@@ -608,65 +604,65 @@
609
AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
611
- switch(query_code){
612
- case AP_MPMQ_MAX_DAEMON_USED:
613
- *result = ap_daemons_limit;
614
- return APR_SUCCESS;
615
- case AP_MPMQ_IS_THREADED:
616
- *result = AP_MPMQ_NOT_SUPPORTED;
617
- return APR_SUCCESS;
618
- case AP_MPMQ_IS_FORKED:
619
- *result = AP_MPMQ_DYNAMIC;
620
- return APR_SUCCESS;
621
- case AP_MPMQ_HARD_LIMIT_DAEMONS:
622
- *result = server_limit;
623
- return APR_SUCCESS;
624
- case AP_MPMQ_HARD_LIMIT_THREADS:
625
- *result = HARD_THREAD_LIMIT;
626
- return APR_SUCCESS;
627
- case AP_MPMQ_MAX_THREADS:
629
- return APR_SUCCESS;
630
- case AP_MPMQ_MIN_SPARE_DAEMONS:
631
- *result = ap_min_free_processors;
632
- return APR_SUCCESS;
633
- case AP_MPMQ_MIN_SPARE_THREADS:
635
- return APR_SUCCESS;
636
- case AP_MPMQ_MAX_SPARE_THREADS:
638
- return APR_SUCCESS;
639
- case AP_MPMQ_MAX_REQUESTS_DAEMON:
640
- *result = ap_max_requests_per_child;
641
- return APR_SUCCESS;
642
- case AP_MPMQ_MAX_DAEMONS:
643
- *result = server_limit;
644
- return APR_SUCCESS;
645
- case AP_MPMQ_MPM_STATE:
646
- *result = mpm_state;
647
- return APR_SUCCESS;
648
+ switch (query_code) {
649
+ case AP_MPMQ_MAX_DAEMON_USED:
650
+ *result = ap_daemons_limit;
651
+ return APR_SUCCESS;
652
+ case AP_MPMQ_IS_THREADED:
653
+ *result = AP_MPMQ_NOT_SUPPORTED;
654
+ return APR_SUCCESS;
655
+ case AP_MPMQ_IS_FORKED:
656
+ *result = AP_MPMQ_DYNAMIC;
657
+ return APR_SUCCESS;
658
+ case AP_MPMQ_HARD_LIMIT_DAEMONS:
659
+ *result = server_limit;
660
+ return APR_SUCCESS;
661
+ case AP_MPMQ_HARD_LIMIT_THREADS:
662
+ *result = HARD_THREAD_LIMIT;
663
+ return APR_SUCCESS;
664
+ case AP_MPMQ_MAX_THREADS:
666
+ return APR_SUCCESS;
667
+ case AP_MPMQ_MIN_SPARE_DAEMONS:
668
+ *result = ap_min_free_processors;
669
+ return APR_SUCCESS;
670
+ case AP_MPMQ_MIN_SPARE_THREADS:
672
+ return APR_SUCCESS;
673
+ case AP_MPMQ_MAX_SPARE_THREADS:
675
+ return APR_SUCCESS;
676
+ case AP_MPMQ_MAX_REQUESTS_DAEMON:
677
+ *result = ap_max_requests_per_child;
678
+ return APR_SUCCESS;
679
+ case AP_MPMQ_MAX_DAEMONS:
680
+ *result = server_limit;
681
+ return APR_SUCCESS;
682
+ case AP_MPMQ_MPM_STATE:
683
+ *result = mpm_state;
684
+ return APR_SUCCESS;
689
#if defined(NEED_WAITPID)
691
- Systems without a real waitpid sometimes lose a child's exit while waiting
692
- for another. Search through the scoreboard for missing children.
693
+ Systems without a real waitpid sometimes lose a child's exit while waiting
694
+ for another. Search through the scoreboard for missing children.
696
int reap_children(int *exitcode, apr_exit_why_e *status)
700
- for (n = 0; n < ap_max_daemons_limit; ++n) {
701
- if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD &&
702
- kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) {
703
- ap_update_child_status_from_indexes(n, 0, SERVER_DEAD, NULL);
704
- /* just mark it as having a successful exit status */
705
+ for (n = 0; n < NUM_CHILDS; ++n) {
706
+ if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD &&
707
+ kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) {
708
+ ap_update_child_status_from_indexes(n, 0, SERVER_DEAD, NULL);
709
+ /* just mark it as having a successful exit status */
710
*status = APR_PROC_EXIT;
720
retval = chdir(ap_coredump_dir);
721
apr_signal(sig, SIG_DFL);
722
if (ap_my_pid == parent_pid) {
723
- ap_log_error(APLOG_MARK, APLOG_NOTICE,
725
- "seg fault or similar nasty error detected "
726
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
727
+ "seg fault or similar nasty error detected "
728
"in the parent process");
733
static void just_die(int sig)
735
-_DBG("function called");
736
+ _DBG("function called");
740
@@ -713,11 +708,11 @@
741
static void sig_term(int sig)
743
if (shutdown_pending == 1) {
744
- /* Um, is this _probably_ not an error, if the user has
745
- * tried to do a shutdown twice quickly, so we won't
746
- * worry about reporting it.
749
+ /* Um, is this _probably_ not an error, if the user has
750
+ * tried to do a shutdown twice quickly, so we won't
751
+ * worry about reporting it.
755
shutdown_pending = 1;
757
@@ -728,20 +723,16 @@
758
static void restart(int sig)
760
if (restart_pending == 1) {
761
- /* Probably not an error - don't bother reporting it */
763
+ /* Probably not an error - don't bother reporting it */
767
is_graceful = (sig == AP_SIG_GRACEFUL);
770
/* Sets die_now if we received a character on the pipe_of_death */
771
-static apr_status_t check_pipe_of_death
777
+static apr_status_t check_pipe_of_death(void **csd, ap_listen_rec *lr,
778
+ apr_pool_t *ptrans)
782
@@ -749,24 +740,22 @@
784
_DBG("WATCH: die_now=%d", die_now);
786
- if (die_now) return APR_SUCCESS;
788
+ return APR_SUCCESS;
790
/* apr_thread_mutex_lock(pipe_of_death_mutex); */
791
ret = apr_socket_recv(lr->sd, &pipe_read_char, &n);
792
- if (APR_STATUS_IS_EAGAIN(ret))
794
- /* It lost the lottery. It must continue to suffer
795
- * through a life of servitude. */
796
- _DBG("POD read EAGAIN");
798
+ if (APR_STATUS_IS_EAGAIN(ret)) {
799
+ /* It lost the lottery. It must continue to suffer
800
+ * through a life of servitude. */
801
+ _DBG("POD read EAGAIN");
806
- if (pipe_read_char != AP_PERUSER_CHAR_OF_DEATH)
808
- _DBG("got wrong char %c", pipe_read_char);
809
- return APR_SUCCESS;
812
+ if (pipe_read_char != AP_PERUSER_CHAR_OF_DEATH) {
813
+ _DBG("got wrong char %c", pipe_read_char);
814
+ return APR_SUCCESS;
816
/* It won the lottery (or something else is very
817
* wrong). Embrace death with open arms. */
819
@@ -785,53 +774,63 @@
823
- sa.sa_handler = sig_coredump;
824
+ sa.sa_handler = sig_coredump;
825
#if defined(SA_ONESHOT)
826
- sa.sa_flags = SA_ONESHOT;
827
+ sa.sa_flags = SA_ONESHOT;
828
#elif defined(SA_RESETHAND)
829
- sa.sa_flags = SA_RESETHAND;
830
+ sa.sa_flags = SA_RESETHAND;
832
- if (sigaction(SIGSEGV, &sa, NULL) < 0)
833
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGSEGV)");
834
+ if (sigaction(SIGSEGV, &sa, NULL) < 0)
835
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
836
+ "sigaction(SIGSEGV)");
838
- if (sigaction(SIGBUS, &sa, NULL) < 0)
839
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGBUS)");
840
+ if (sigaction(SIGBUS, &sa, NULL) < 0)
841
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
842
+ "sigaction(SIGBUS)");
845
- if (sigaction(SIGABORT, &sa, NULL) < 0)
846
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABORT)");
847
+ if (sigaction(SIGABORT, &sa, NULL) < 0)
848
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
849
+ "sigaction(SIGABORT)");
852
- if (sigaction(SIGABRT, &sa, NULL) < 0)
853
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABRT)");
854
+ if (sigaction(SIGABRT, &sa, NULL) < 0)
855
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
856
+ "sigaction(SIGABRT)");
859
- if (sigaction(SIGILL, &sa, NULL) < 0)
860
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGILL)");
861
+ if (sigaction(SIGILL, &sa, NULL) < 0)
862
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
863
+ "sigaction(SIGILL)");
868
sa.sa_handler = sig_term;
869
if (sigaction(SIGTERM, &sa, NULL) < 0)
870
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
871
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
872
+ "sigaction(SIGTERM)");
874
if (sigaction(SIGINT, &sa, NULL) < 0)
875
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
876
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
877
+ "sigaction(SIGINT)");
880
sa.sa_handler = SIG_DFL;
881
if (sigaction(SIGXCPU, &sa, NULL) < 0)
882
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
883
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
884
+ "sigaction(SIGXCPU)");
887
sa.sa_handler = SIG_IGN;
888
if (sigaction(SIGXFSZ, &sa, NULL) < 0)
889
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
890
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
891
+ "sigaction(SIGXFSZ)");
894
sa.sa_handler = SIG_IGN;
895
if (sigaction(SIGPIPE, &sa, NULL) < 0)
896
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
897
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
898
+ "sigaction(SIGPIPE)");
901
/* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
902
@@ -840,29 +839,31 @@
903
sigaddset(&sa.sa_mask, AP_SIG_GRACEFUL);
904
sa.sa_handler = restart;
905
if (sigaction(SIGHUP, &sa, NULL) < 0)
906
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
907
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
908
+ "sigaction(SIGHUP)");
909
if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0)
910
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
911
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
912
+ "sigaction(" AP_SIG_GRACEFUL_STRING ")");
915
- apr_signal(SIGSEGV, sig_coredump);
916
+ apr_signal(SIGSEGV, sig_coredump);
918
- apr_signal(SIGBUS, sig_coredump);
919
+ apr_signal(SIGBUS, sig_coredump);
922
- apr_signal(SIGABORT, sig_coredump);
923
+ apr_signal(SIGABORT, sig_coredump);
924
#endif /* SIGABORT */
926
- apr_signal(SIGABRT, sig_coredump);
927
+ apr_signal(SIGABRT, sig_coredump);
930
- apr_signal(SIGILL, sig_coredump);
931
+ apr_signal(SIGILL, sig_coredump);
934
- apr_signal(SIGXCPU, SIG_DFL);
935
+ apr_signal(SIGXCPU, SIG_DFL);
938
- apr_signal(SIGXFSZ, SIG_DFL);
939
+ apr_signal(SIGXFSZ, SIG_DFL);
943
@@ -896,14 +897,12 @@
948
static int total_processors(int child_num)
952
- for(i = 0, total = 0; i < NUM_CHILDS; ++i)
954
- if(CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv)
955
+ for (i = 0, total = 0; i < NUM_CHILDS; ++i) {
956
+ if (CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv)
960
@@ -914,10 +913,11 @@
964
- for(i = 0, total = 0; i < NUM_CHILDS; ++i)
966
- if( (CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv) && (CHILD_INFO_TABLE[i].pid > 0 ) )
967
+ for (i = 0, total = 0; i < NUM_CHILDS; ++i) {
968
+ if (CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv
969
+ && CHILD_INFO_TABLE[i].pid > 0) {
975
@@ -927,13 +927,15 @@
979
- if(env_num >= NUM_SENV)
981
+ if (env_num >= NUM_SENV) {
985
- for(i = 0, total = 0; i < NUM_CHILDS; ++i)
987
- if((CHILD_INFO_TABLE[i].senv == &SENV[env_num]) && (CHILD_INFO_TABLE[i].pid > 0))
988
+ for (i = 0, total = 0; i < NUM_CHILDS; ++i) {
989
+ if (CHILD_INFO_TABLE[i].senv == &SENV[env_num]
990
+ && CHILD_INFO_TABLE[i].pid > 0) {
996
@@ -943,11 +945,10 @@
1000
- for(i = 0, total = 0; i < NUM_CHILDS; ++i)
1002
- if(CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv &&
1003
- (CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY))
1005
+ for (i = 0, total = 0; i < NUM_CHILDS; ++i) {
1006
+ if (CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv
1007
+ && (CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY
1008
+ || CHILD_INFO_TABLE[i].status == CHILD_STATUS_STARTING)) {
1012
@@ -959,69 +960,77 @@
1016
- for(i = 0, total = 0; i < NUM_CHILDS; ++i)
1018
- if(CHILD_INFO_TABLE[i].senv == &SENV[env_num] && (CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY) )
1019
+ for (i = 0, total = 0; i < NUM_CHILDS; ++i) {
1020
+ if (CHILD_INFO_TABLE[i].senv == &SENV[env_num]
1021
+ && (CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY
1022
+ || CHILD_INFO_TABLE[i].status == CHILD_STATUS_STARTING)) {
1031
-static int wait_for_workers(child_info_t *processor) {
1032
+static int wait_for_workers(child_info_t *processor)
1034
int i, wait_step_size, wait_time;
1037
wait_step_size = 100 / processor_wait_steps;
1039
/* Check if the processor is available */
1040
- if (total_processors(processor->id) == processor->senv->max_processors &&
1041
- idle_processors(processor->id) == 0 && processor_wait_timeout > 0) {
1042
+ if (total_processors(processor->id) == processor->senv->max_processors
1043
+ && idle_processors(processor->id) == 0 && processor_wait_timeout > 0) {
1045
/* The processor is currently busy, try to wait (a little) */
1046
_DBG("processor seems to be busy, trying to wait for it");
1048
if (processor->senv->availability == 0) {
1049
processor->senv->availability = 0;
1051
- _DBG("processor is very busy (availability = 0) - not passing request");
1052
+ _DBG("processor is busy (availability = 0) - not passing request");
1054
if (processor->senv->error_pass == 0) {
1055
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf,
1056
- "Too many requests for processor %s, increase MaxProcessors", processor->senv->name);
1057
+ "Too many requests for processor %s, "
1058
+ "increase MaxProcessors", processor->senv->name);
1062
/* No point in waiting for the processor, it's very busy */
1066
- /* We sleep a little (depending how available the processor usually is) */
1068
+ /* We sleep a little (depending how available the processor is) */
1069
wait_time = (processor_wait_timeout / processor_wait_steps) * 1000000;
1071
- for(i = 0; i <= processor->senv->availability; i += wait_step_size) {
1072
+ for (i = 0; i <= processor->senv->availability; i += wait_step_size) {
1075
/* Check if the processor is ready */
1076
- if (total_processors(processor->id) < processor->senv->max_processors ||
1077
- idle_processors(processor->id) > 0) {
1078
+ if (total_processors(processor->id)
1079
+ < processor->senv->max_processors
1080
+ || idle_processors(processor->id) > 0)
1082
/* The processor has freed - lets use it */
1083
_DBG("processor freed before wait time expired");
1089
if (processor->senv->availability <= wait_step_size) {
1090
processor->senv->availability = 0;
1092
- else processor->senv->availability -= wait_step_size;
1095
+ processor->senv->availability -= wait_step_size;
1097
/* Check if we waited all the time */
1098
if (i > processor->senv->availability) {
1099
_DBG("processor is busy - not passing request (availability = %d)",
1100
- processor->senv->availability);
1101
+ processor->senv->availability);
1103
if (processor->senv->error_pass == 0) {
1104
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf,
1105
- "Too many requests for processor %s, increase MaxProcessors", processor->senv->name);
1106
+ "Too many requests for processor %s, "
1107
+ "increase MaxProcessors", processor->senv->name);
1111
@@ -1033,10 +1042,12 @@
1114
/* Smoothly increment the availability back to 100 */
1115
- if (processor->senv->availability >= 100-wait_step_size) {
1116
+ if (processor->senv->availability >= 100 - wait_step_size) {
1117
processor->senv->availability = 100;
1119
- else processor->senv->availability += wait_step_size;
1121
+ processor->senv->availability += wait_step_size;
1126
@@ -1048,7 +1059,8 @@
1127
* a socket or a whole request by inspecting the header_length of the
1128
* message. If it is zero then only a socket was sent.
1130
-static int pass_socket(apr_socket_t *thesock, child_info_t *processor, apr_pool_t *pool)
1131
+static int pass_socket(apr_socket_t *thesock, child_info_t *processor,
1136
@@ -1061,63 +1073,64 @@
1137
apr_size_t body_len = 0;
1143
_DBG("server %s in child %d has no child_info associated",
1144
- "(unkonwn)", my_child_num);
1145
+ "(unknown)", my_child_num);
1150
/* Make sure there are free workers on the other end */
1151
- if (wait_for_workers(processor) == -1) return -1;
1152
+ if (wait_for_workers(processor) == -1) {
1156
_DBG("passing request to another child.", 0);
1158
apr_os_sock_get(&sock_fd, thesock);
1160
/* passing remote_addr too, see comments below */
1161
apr_socket_addr_get(&remote_addr, APR_REMOTE, thesock);
1167
iov[0].iov_base = &header_len;
1168
- iov[0].iov_len = sizeof(header_len);
1169
+ iov[0].iov_len = sizeof(header_len);
1170
iov[1].iov_base = &body_len;
1171
- iov[1].iov_len = sizeof(body_len);
1172
+ iov[1].iov_len = sizeof(body_len);
1173
iov[2].iov_base = remote_addr;
1174
- iov[2].iov_len = sizeof(*remote_addr);
1175
+ iov[2].iov_len = sizeof(*remote_addr);
1176
iov[3].iov_base = h.headers;
1177
- iov[3].iov_len = 0;
1178
+ iov[3].iov_len = 0;
1179
iov[4].iov_base = body;
1180
- iov[4].iov_len = body_len;
1181
+ iov[4].iov_len = body_len;
1183
- msg.msg_name = NULL;
1184
+ msg.msg_name = NULL;
1185
msg.msg_namelen = 0;
1186
- msg.msg_iov = iov;
1187
- msg.msg_iovlen = 5;
1188
+ msg.msg_iov = iov;
1189
+ msg.msg_iovlen = 5;
1191
cmsg = apr_palloc(pool, sizeof(*cmsg) + sizeof(sock_fd));
1192
- cmsg->cmsg_len = CMSG_LEN(sizeof(sock_fd));
1193
+ cmsg->cmsg_len = CMSG_LEN(sizeof(sock_fd));
1194
cmsg->cmsg_level = SOL_SOCKET;
1195
- cmsg->cmsg_type = SCM_RIGHTS;
1196
+ cmsg->cmsg_type = SCM_RIGHTS;
1198
memcpy(CMSG_DATA(cmsg), &sock_fd, sizeof(sock_fd));
1200
- msg.msg_control = cmsg;
1201
+ msg.msg_control = cmsg;
1202
msg.msg_controllen = cmsg->cmsg_len;
1204
- if (processor->status == CHILD_STATUS_STANDBY)
1206
+ if (processor->status == CHILD_STATUS_STANDBY) {
1207
_DBG("Activating child #%d", processor->id);
1208
processor->status = CHILD_STATUS_STARTING;
1211
- _DBG("Writing message to %d, passing sock_fd: %d", processor->senv->output, sock_fd);
1212
+ _DBG("Writing message to %d, passing sock_fd: %d", processor->senv->output,
1214
_DBG("header_len=%d headers=\"%s\"", header_len, h.headers);
1215
_DBG("body_len=%d body=\"%s\"", body_len, body);
1217
- if ((rv = sendmsg(processor->senv->output, &msg, 0)) == -1)
1219
+ if ((rv = sendmsg(processor->senv->output, &msg, 0)) == -1) {
1220
apr_pool_destroy(pool);
1221
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1222
"Writing message failed %d %d", rv, errno);
1223
@@ -1135,7 +1148,7 @@
1226
static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id,
1227
- apr_bucket_alloc_t *bucket_alloc, apr_pool_t *pool)
1228
+ apr_bucket_alloc_t *bucket_alloc, apr_pool_t *pool)
1230
conn_rec *current_conn;
1232
@@ -1152,41 +1165,49 @@
1233
current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id,
1235
_DBG("Looking up the right vhost");
1238
ap_update_vhost_given_ip(current_conn);
1239
- _DBG("Base server is %s, name based vhosts %s", current_conn->base_server->server_hostname,
1240
+ _DBG("Base server is %s, name based vhosts %s",
1241
+ current_conn->base_server->server_hostname,
1242
current_conn->vhost_lookup_data ? "on" : "off");
1244
- // check for ssl configuration for this server (ssl_server_is_https is NULL if we have no mod_ssl)
1245
- if(ssl_server_is_https) ssl_on = ssl_server_is_https(current_conn->base_server);
1247
+ /* check for ssl configuration for this server
1248
+ * (ssl_server_is_https is NULL if we have no mod_ssl) */
1249
+ if (ssl_server_is_https) {
1250
+ ssl_on = ssl_server_is_https(current_conn->base_server);
1254
- if (current_conn && (!current_conn->vhost_lookup_data || ssl_on) && CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) {
1255
- _DBG("We are not using name based vhosts (or SSL is enabled), we'll directly pass the socket.");
1256
+ if (current_conn && (!current_conn->vhost_lookup_data || ssl_on)
1257
+ && CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) {
1258
+ _DBG("We are not using name based vhosts (or SSL is enabled), "
1259
+ "we'll directly pass the socket.");
1261
sconf = PERUSER_SERVER_CONF(current_conn->base_server->module_config);
1263
if (sconf->senv != NULL) {
1264
processor = &CHILD_INFO_TABLE[sconf->senv->processor_id];
1266
- _DBG("Forwarding without further inspection, processor %d", processor->id);
1267
- if (processor->status == CHILD_STATUS_STANDBY)
1269
- _DBG("Activating child #%d", processor->id);
1270
- processor->status = CHILD_STATUS_STARTING;
1273
+ _DBG("Forwarding without further inspection, processor %d",
1276
+ if (processor->status == CHILD_STATUS_STANDBY) {
1277
+ _DBG("Activating child #%d", processor->id);
1278
+ processor->status = CHILD_STATUS_STARTING;
1281
_DBG("Creating new pool",0);
1282
apr_pool_create(&ptrans, pool);
1284
_DBG("Passing request.",0);
1285
if (pass_socket(sock, processor, ptrans) == -1) {
1286
if (processor->senv->error_pass == 0) {
1287
- ap_log_error(APLOG_MARK, APLOG_ERR, 0,
1288
- ap_server_conf, "Could not pass request to proper "
1289
- "child, request will not be honoured.");
1290
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
1291
+ "Could not pass request to proper child, "
1292
+ "request will not be honoured.");
1296
processor->senv->error_pass = 1;
1299
@@ -1197,60 +1218,58 @@
1300
_DBG("Base server has no senv set!");
1302
if (sconf->missing_senv_reported == 0) {
1303
- ap_log_error(APLOG_MARK, APLOG_ERR, 0,
1304
- ap_server_conf, "Virtualhost %s has no server environment set, "
1305
- "request will not be honoured.", current_conn->base_server->server_hostname);
1306
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
1307
+ "Virtualhost %s has no server environment set, "
1308
+ "request will not be honoured.",
1309
+ current_conn->base_server->server_hostname);
1312
sconf->missing_senv_reported = 1;
1317
- _DBG("freeing connection",0);
1318
+ if (current_conn) {
1319
+ _DBG("freeing connection", 0);
1320
ap_lingering_close(current_conn);
1323
- _DBG("doing longjmp",0);
1324
+ _DBG("doing longjmp", 0);
1325
longjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer, 1);
1330
- if ((rv = apr_os_sock_get(&sock_fd, sock)) != APR_SUCCESS)
1332
+ if ((rv = apr_os_sock_get(&sock_fd, sock)) != APR_SUCCESS) {
1333
ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "apr_os_sock_get");
1336
_DBG("child_num=%d sock=%ld sock_fd=%d", my_child_num, sock, sock_fd);
1337
- _DBG("type=%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type), my_child_num);
1338
+ _DBG("type=%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type),
1342
if (sock_fd >= FD_SETSIZE)
1344
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
1345
- "new file descriptor %d is too large; you probably need "
1346
- "to rebuild Apache with a larger FD_SETSIZE "
1348
- sock_fd, FD_SETSIZE);
1349
+ "new file descriptor %d is too large; you probably need "
1350
+ "to rebuild Apache with a larger FD_SETSIZE "
1352
+ sock_fd, FD_SETSIZE);
1353
apr_socket_close(sock);
1354
_DBG("child_num=%d: exiting with error", my_child_num);
1359
- if (CHILD_INFO_TABLE[my_child_num].sock_fd < 0)
1361
+ if (CHILD_INFO_TABLE[my_child_num].sock_fd < 0) {
1362
ap_sock_disable_nagle(sock);
1365
if (!current_conn) {
1366
ap_create_sb_handle(&sbh, p, conn_id, 0);
1367
- current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id,
1368
- sbh, bucket_alloc);
1369
+ current_conn = ap_run_create_connection(p, ap_server_conf, sock,
1370
+ conn_id, sbh, bucket_alloc);
1375
+ if (current_conn) {
1376
ap_process_connection(current_conn, sock);
1377
ap_lingering_close(current_conn);
1379
@@ -1262,31 +1281,37 @@
1380
apr_bucket_brigade *bb;
1383
- _DBG("function entered",0);
1384
+ _DBG("function entered", 0);
1386
/* -- fetch our sockets from the pool -- */
1387
- apr_pool_userdata_get((void **)&bb, "PERUSER_SOCKETS", conn->pool);
1390
- /* -- find the 'core' filter and give the socket data to it -- */
1391
- for (filter = conn->output_filters; filter != NULL; filter = filter->next)
1393
- if (!strcmp(filter->frec->name, "core")) break;
1395
- if (filter != NULL)
1397
- net = filter->ctx;
1398
- net->in_ctx = apr_palloc(conn->pool, sizeof(*net->in_ctx));
1399
- net->in_ctx->b = bb;
1400
- net->in_ctx->tmpbb = apr_brigade_create(net->in_ctx->b->p,
1401
- net->in_ctx->b->bucket_alloc);
1402
+ apr_pool_userdata_get((void **) &bb, "PERUSER_SOCKETS", conn->pool);
1408
+ /* -- find the 'core' filter and give the socket data to it -- */
1409
+ for (filter = conn->output_filters; filter != NULL;
1410
+ filter = filter->next) {
1411
+ if (!strcmp(filter->frec->name, "core")) {
1415
- _DBG("leaving (DECLINED)", 0);
1417
+ if (filter == NULL) {
1421
+ net = filter->ctx;
1422
+ net->in_ctx = apr_palloc(conn->pool, sizeof(*net->in_ctx));
1423
+ net->in_ctx->b = bb;
1424
+ net->in_ctx->tmpbb = apr_brigade_create(net->in_ctx->b->p,
1425
+ net->in_ctx->b->bucket_alloc);
1430
-static int pass_request(request_rec *r, child_info_t *processor)
1431
+static int pass_request(request_rec *r, child_info_t *child)
1435
@@ -1307,60 +1332,75 @@
1436
const apr_table_entry_t *headers_in;
1439
- apr_socket_t *thesock = ap_get_module_config(r->connection->conn_config, &core_module);
1440
+ apr_socket_t *thesock = ap_get_module_config(r->connection->conn_config,
1443
- if ((!r->the_request) || (!strlen(r->the_request)))
1445
+ if (!r->the_request || !strlen(r->the_request)) {
1446
_DBG("empty request. dropping it (%ld)", r->the_request);
1453
_DBG("server %s in child %d has no child_info associated",
1454
- r->hostname, my_child_num);
1455
+ r->hostname, my_child_num);
1459
_DBG("passing request to another child. Vhost: %s, child %d %d",
1460
- apr_table_get(r->headers_in, "Host"), my_child_num, processor->senv->output);
1461
- _DBG("r->the_request=\"%s\" len=%d", r->the_request, strlen(r->the_request));
1462
+ apr_table_get(r->headers_in, "Host"), my_child_num,
1463
+ child->senv->output);
1465
+ _DBG("r->the_request=\"%s\" len=%d", r->the_request,
1466
+ strlen(r->the_request));
1468
/* Make sure there are free workers on the other end */
1469
- if (wait_for_workers(processor) == -1) return -1;
1470
+ if (child->type != CHILD_TYPE_MULTIPLEXER && wait_for_workers(child) == -1) {
1474
+ ap_get_brigade(r->connection->input_filters, bb, AP_MODE_EXHAUSTIVE,
1475
+ APR_NONBLOCK_READ, len);
1477
- ap_get_brigade(r->connection->input_filters, bb, AP_MODE_EXHAUSTIVE, APR_NONBLOCK_READ, len);
1479
/* Scan the brigade looking for heap-buckets */
1481
_DBG("Scanning the brigade",0);
1482
bucket = APR_BRIGADE_FIRST(bb);
1483
- while (bucket != APR_BRIGADE_SENTINEL(bb) &&
1484
- APR_BUCKET_IS_HEAP(bucket)) {
1485
- _DBG("HEAP BUCKET is found, length=%d", bucket->length);
1487
+ while (bucket != APR_BRIGADE_SENTINEL(bb) && APR_BUCKET_IS_HEAP(bucket)) {
1488
+ _DBG("HEAP BUCKET is found, length=%d", bucket->length);
1490
bucket = APR_BUCKET_NEXT(bucket);
1492
if (!APR_BUCKET_IS_HEAP(bucket)) {
1493
- _DBG("NON-HEAP BUCKET is found, extracting the part of brigade before it",0);
1494
+ _DBG("NON-HEAP BUCKET is found, extracting the part of brigade "
1498
bb = apr_brigade_split(body_bb, bucket);
1500
/* Do we need to apr_destroy_brigade(bb) here?
1501
* Yeah, I know we do apr_pool_destroy(r->pool) before return, but
1502
* ap_get_brigade is in non-blocking mode (however len is zero).
1504
- if (apr_brigade_pflatten(body_bb, &body, &body_len, r->pool) != APR_SUCCESS) {
1505
+ if (apr_brigade_pflatten(body_bb, &body, &body_len, r->pool)
1508
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1509
- "Unable to flatten brigade, declining request");
1510
+ "Unable to flatten brigade, declining request");
1512
apr_pool_destroy(r->pool);
1516
_DBG("Brigade is flattened as body (body_len=%d)", body_len);
1519
- _DBG("Scanning is finished",0);
1521
+ _DBG("Scanning is finished");
1523
apr_os_sock_get(&sock_fd, thesock);
1525
/* looks like a bug while sending/receiving SCM_RIGHTS related to ipv6
1526
- workaround: send remote_addr structure too */
1527
+ workaround: send remote_addr structure too */
1528
apr_socket_addr_get(&remote_addr, APR_REMOTE, thesock);
1531
@@ -1369,58 +1409,59 @@
1532
headers_in = (const apr_table_entry_t *) headers_in_array->elts;
1534
h.headers = apr_pstrcat(h.p, r->the_request, CRLF, NULL);
1536
for (counter = 0; counter < headers_in_array->nelts; counter++) {
1537
- if (headers_in[counter].key == NULL
1538
- || headers_in[counter].val == NULL) {
1541
- h.headers = apr_pstrcat(h.p, h.headers, headers_in[counter].key, ": ",
1542
- headers_in[counter].val, CRLF, NULL);
1543
+ if (headers_in[counter].key == NULL ||
1544
+ headers_in[counter].val == NULL) {
1548
+ h.headers = apr_pstrcat(h.p, h.headers, headers_in[counter].key, ": ",
1549
+ headers_in[counter].val, CRLF, NULL);
1552
h.headers = apr_pstrcat(h.p, h.headers, CRLF, NULL);
1553
ap_xlate_proto_to_ascii(h.headers, strlen(h.headers));
1555
header_len = strlen(h.headers);
1557
iov[0].iov_base = &header_len;
1558
- iov[0].iov_len = sizeof(header_len);
1559
+ iov[0].iov_len = sizeof(header_len);
1560
iov[1].iov_base = &body_len;
1561
- iov[1].iov_len = sizeof(body_len);
1562
+ iov[1].iov_len = sizeof(body_len);
1563
iov[2].iov_base = remote_addr;
1564
- iov[2].iov_len = sizeof(*remote_addr);
1565
+ iov[2].iov_len = sizeof(*remote_addr);
1566
iov[3].iov_base = h.headers;
1567
- iov[3].iov_len = strlen(h.headers) + 1;
1568
+ iov[3].iov_len = strlen(h.headers) + 1;
1569
iov[4].iov_base = body;
1570
- iov[4].iov_len = body_len;
1571
+ iov[4].iov_len = body_len;
1573
- msg.msg_name = NULL;
1574
+ msg.msg_name = NULL;
1575
msg.msg_namelen = 0;
1576
- msg.msg_iov = iov;
1577
- msg.msg_iovlen = 5;
1578
+ msg.msg_iov = iov;
1579
+ msg.msg_iovlen = 5;
1581
cmsg = apr_palloc(r->pool, sizeof(*cmsg) + sizeof(sock_fd));
1582
- cmsg->cmsg_len = CMSG_LEN(sizeof(sock_fd));
1583
+ cmsg->cmsg_len = CMSG_LEN(sizeof(sock_fd));
1584
cmsg->cmsg_level = SOL_SOCKET;
1585
- cmsg->cmsg_type = SCM_RIGHTS;
1586
+ cmsg->cmsg_type = SCM_RIGHTS;
1588
memcpy(CMSG_DATA(cmsg), &sock_fd, sizeof(sock_fd));
1590
- msg.msg_control = cmsg;
1591
+ msg.msg_control = cmsg;
1592
msg.msg_controllen = cmsg->cmsg_len;
1594
- if (processor->status == CHILD_STATUS_STANDBY)
1596
- _DBG("Activating child #%d", processor->id);
1597
- processor->status = CHILD_STATUS_STARTING;
1598
+ if (child->status == CHILD_STATUS_STANDBY) {
1599
+ _DBG("Activating child #%d", child->id);
1600
+ child->status = CHILD_STATUS_STARTING;
1603
- _DBG("Writing message to %d, passing sock_fd: %d", processor->senv->output, sock_fd);
1604
+ _DBG("Writing message to %d, passing sock_fd: %d", child->senv->output,
1606
_DBG("header_len=%d headers=\"%s\"", header_len, h.headers);
1607
_DBG("body_len=%d body=\"%s\"", body_len, body);
1609
- if ((rv = sendmsg(processor->senv->output, &msg, 0)) == -1)
1611
+ if ((rv = sendmsg(child->senv->output, &msg, 0)) == -1) {
1612
apr_pool_destroy(r->pool);
1613
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
1614
"Writing message failed %d %d", rv, errno);
1615
@@ -1437,12 +1478,9 @@
1620
-static apr_status_t receive_from_multiplexer(
1621
- void **trans_sock, /* will be filled out w/ the received socket */
1622
- ap_listen_rec *lr, /* listener to receive from */
1623
- apr_pool_t *ptrans /* transaction wide pool */
1625
+static apr_status_t receive_connection(void **trans_sock,
1626
+ ap_listen_rec *lr,
1627
+ apr_pool_t *ptrans)
1630
struct cmsghdr *cmsg;
1631
@@ -1459,27 +1497,27 @@
1633
/* -- bucket's, brigades and their allocators */
1634
apr_bucket_alloc_t *alloc = apr_bucket_alloc_create(ptrans);
1635
- apr_bucket_brigade *bb = apr_brigade_create(ptrans, alloc);
1636
- apr_bucket *bucket;
1637
+ apr_bucket_brigade *bb = apr_brigade_create(ptrans, alloc);
1638
+ apr_bucket *bucket;
1640
/* prepare the buffers for receiving data from remote side */
1641
iov[0].iov_base = &header_len;
1642
- iov[0].iov_len = sizeof(header_len);
1643
+ iov[0].iov_len = sizeof(header_len);
1644
iov[1].iov_base = &body_len;
1645
- iov[1].iov_len = sizeof(body_len);
1646
+ iov[1].iov_len = sizeof(body_len);
1647
iov[2].iov_base = &remote_addr;
1648
- iov[2].iov_len = sizeof(remote_addr);
1649
- iov[3].iov_base = (char*)&buff;
1650
- iov[3].iov_len = HUGE_STRING_LEN;
1651
+ iov[2].iov_len = sizeof(remote_addr);
1652
+ iov[3].iov_base = (char*) &buff;
1653
+ iov[3].iov_len = HUGE_STRING_LEN;
1655
cmsg = apr_palloc(ptrans, sizeof(*cmsg) + sizeof(trans_sock_fd));
1656
cmsg->cmsg_len = CMSG_LEN(sizeof(trans_sock_fd));
1658
- msg.msg_name = NULL;
1659
- msg.msg_namelen = 0;
1660
- msg.msg_iov = iov;
1661
- msg.msg_iovlen = 4;
1662
- msg.msg_control = cmsg;
1663
+ msg.msg_name = NULL;
1664
+ msg.msg_namelen = 0;
1665
+ msg.msg_iov = iov;
1666
+ msg.msg_iovlen = 4;
1667
+ msg.msg_control = cmsg;
1668
msg.msg_controllen = cmsg->cmsg_len;
1670
/* -- receive data from socket -- */
1671
@@ -1491,69 +1529,73 @@
1673
if (ret == -1 && errno == EAGAIN) {
1674
_DBG("receive_from_multiplexer recvmsg() EAGAIN, someone was faster");
1679
else if (ret == -1) {
1680
_DBG("recvmsg failed with error \"%s\"", strerror(errno));
1683
// Error, better kill this child to be on the safe side
1684
return APR_EGENERAL;
1686
- else _DBG("recvmsg returned %d", ret);
1688
+ _DBG("recvmsg returned %d", ret);
1690
/* -- extract socket from the cmsg -- */
1691
memcpy(&trans_sock_fd, CMSG_DATA(cmsg), sizeof(trans_sock_fd));
1693
/* here *trans_sock always == NULL (socket reset at got_fd), so
1694
- we can use apr_os_sock_make() instead of apr_os_sock_put() */
1695
- sockinfo.os_sock = &trans_sock_fd;
1696
- sockinfo.local = NULL;
1697
- sockinfo.remote = (struct sockaddr *)&remote_addr.sa.sin;
1698
- sockinfo.family = remote_addr.family;
1699
- sockinfo.type = SOCK_STREAM;
1700
+ we can use apr_os_sock_make() instead of apr_os_sock_put() */
1702
+ sockinfo.os_sock = &trans_sock_fd;
1703
+ sockinfo.local = NULL;
1704
+ sockinfo.remote = (struct sockaddr *) &remote_addr.sa.sin;
1705
+ sockinfo.family = remote_addr.family;
1706
+ sockinfo.type = SOCK_STREAM;
1707
#ifdef APR_ENABLE_FOR_1_0
1708
sockinfo.protocol = 0;
1710
- apr_os_sock_make((apr_socket_t **)trans_sock, &sockinfo, ptrans);
1711
+ apr_os_sock_make((apr_socket_t **) trans_sock, &sockinfo, ptrans);
1712
apr_os_sock_get(&fd_tmp, *trans_sock);
1714
_DBG("trans_sock=%ld fdx=%d sock_fd=%d",
1715
- *trans_sock, trans_sock_fd, fd_tmp);
1716
+ *trans_sock, trans_sock_fd, fd_tmp);
1718
apr_cpystrn(headers, buff, header_len + 1);
1719
_DBG("header_len=%d headers=\"%s\"", header_len, headers);
1723
_DBG("header_len > 0, we got a request", 0);
1724
/* -- store received data into an brigade and add
1725
- it to the current transaction's pool -- */
1726
+ it to the current transaction's pool -- */
1727
bucket = apr_bucket_eos_create(alloc);
1728
APR_BRIGADE_INSERT_HEAD(bb, bucket);
1729
bucket = apr_bucket_socket_create(*trans_sock, alloc);
1730
APR_BRIGADE_INSERT_HEAD(bb, bucket);
1734
- body = (char*)&buff[header_len + 1];
1735
+ body = (char*) &buff[header_len + 1];
1736
_DBG("body_len=%d body=\"%s\"", body_len, body);
1739
bucket = apr_bucket_heap_create(body, body_len, NULL, alloc);
1740
APR_BRIGADE_INSERT_HEAD(bb, bucket);
1744
_DBG("There is no body",0);
1748
bucket = apr_bucket_heap_create(headers, header_len, NULL, alloc);
1751
APR_BRIGADE_INSERT_HEAD(bb, bucket);
1752
apr_pool_userdata_set(bb, "PERUSER_SOCKETS", NULL, ptrans);
1756
_DBG("header_len == 0, we got a socket only", 0);
1758
- _DBG("returning 0", 0);
1764
/* Set group privileges.
1766
* Note that we use the username as set in the config files, rather than
1767
@@ -1563,8 +1605,7 @@
1769
static int set_group_privs(uid_t uid, gid_t gid)
1777
@@ -1572,27 +1613,24 @@
1778
* Set the GID before initgroups(), since on some platforms
1779
* setgid() is known to zap the group list.
1781
- if (setgid(gid) == -1)
1783
+ if (setgid(gid) == -1) {
1784
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1785
"setgid: unable to set group id to Group %u",
1791
/* if getpwuid() fails, just skip initgroups() */
1793
- if ((ent = getpwuid(uid)) != NULL)
1795
+ if ((ent = getpwuid(uid)) != NULL) {
1796
name = ent->pw_name;
1798
/* Reset `groups' attributes. */
1800
- if (initgroups(name, gid) == -1)
1802
+ if (initgroups(name, gid) == -1) {
1803
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1804
"initgroups: unable to set groups for User %s "
1805
- "and Group %u", name, (unsigned)gid);
1806
+ "and Group %u", name, (unsigned) gid);
1810
@@ -1600,7 +1638,8 @@
1814
-static int peruser_setup_cgroup(int childnum, server_env_t *senv, apr_pool_t *pool)
1815
+static int peruser_setup_cgroup(int childnum, server_env_t *senv,
1820
@@ -1612,22 +1651,23 @@
1821
length = strlen(senv->cgroup) + CGROUP_TASKS_FILE_LEN;
1822
tasks_file = malloc(length);
1824
- if (!tasks_file) return -1;
1825
+ if (!tasks_file) {
1829
pos = apr_cpystrn(tasks_file, senv->cgroup, length);
1830
apr_cpystrn(pos, CGROUP_TASKS_FILE, CGROUP_TASKS_FILE_LEN);
1832
/* Prepare the data to be written to tasks file */
1833
content = apr_itoa(pool, ap_my_pid);
1834
- content_len = strlen(content);
1835
+ content_len = strlen(content);
1837
_DBG("writing pid %s to tasks file %s", content, tasks_file);
1839
if (apr_file_open(&file, tasks_file, APR_WRITE, APR_OS_DEFAULT, pool)) {
1840
if (senv->error_cgroup == 0) {
1841
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1842
- "cgroup: unable to open file %s",
1844
+ "cgroup: unable to open file %s", tasks_file);
1847
senv->error_cgroup = 1;
1848
@@ -1638,9 +1678,9 @@
1849
if (apr_file_write(file, content, &content_len)) {
1850
if (senv->error_cgroup == 0) {
1851
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1852
- "cgroup: unable to write pid to file %s",
1854
+ "cgroup: unable to write pid to file %s", tasks_file);
1857
senv->error_cgroup = 1;
1860
@@ -1664,17 +1704,17 @@
1861
nice(senv->nice_lvl);
1864
- if(senv->chroot) {
1865
+ if (senv->chroot) {
1866
_DBG("chdir to %s", senv->chroot);
1868
- if(chdir(senv->chroot)) {
1869
+ if (chdir(senv->chroot)) {
1870
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1871
"chdir: unable to change to directory: %s",
1876
- if(chroot(senv->chroot)) {
1877
+ if (chroot(senv->chroot)) {
1878
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1879
"chroot: unable to chroot to directory: %s",
1881
@@ -1682,41 +1722,44 @@
1885
- if(senv->cgroup) {
1886
- peruser_setup_cgroup(childnum, senv, pool);
1887
+ if (senv->cgroup) {
1888
+ peruser_setup_cgroup(childnum, senv, pool);
1891
if (senv->uid == -1 && senv->gid == -1) {
1892
return unixd_setup_child();
1895
if (set_group_privs(senv->uid, senv->gid)) {
1899
/* Only try to switch if we're running as root */
1902
+ if (!geteuid() && (
1904
os_init_job_environment(ap_server_conf, unixd_config.user_name,
1905
- one_process) != 0 ||
1906
+ one_process) != 0 ||
1908
setuid(senv->uid) == -1)) {
1909
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
1910
- "setuid: unable to change to uid: %ld",
1911
- (long) senv->uid);
1912
+ "setuid: unable to change to uid: %ld", (long) senv->uid);
1919
static int check_signal(int signum)
1921
_DBG("signum=%d", signum);
1933
@@ -1725,38 +1768,45 @@
1934
* In other words, don't change this one without checking table_do in alloc.c.
1935
* It returns true unless there was a write error of some kind.
1937
-static int peruser_header_field(peruser_header *h,
1938
- const char *fieldname, const char *fieldval)
1939
+static int peruser_header_field(peruser_header *h, const char *fieldname,
1940
+ const char *fieldval)
1942
apr_pstrcat(h->p, h->headers, fieldname, ": ", fieldval, CRLF, NULL);
1947
-static inline ap_listen_rec* listen_add(apr_pool_t* pool, apr_socket_t *sock, void* accept_func)
1948
+static inline ap_listen_rec* listen_add(apr_pool_t* pool, apr_socket_t *sock,
1949
+ void* accept_func)
1951
ap_listen_rec *lr_walk, *lr_new;
1953
_DBG("function entered", 0);
1955
/* -- create an new listener for this child -- */
1956
lr_new = apr_palloc(pool, sizeof(*lr_new));
1957
- lr_new->sd = sock;
1958
- lr_new->active = 1;
1959
+ lr_new->sd = sock;
1960
+ lr_new->active = 1;
1961
lr_new->accept_func = accept_func;
1962
- lr_new->next = NULL;
1963
+ lr_new->next = NULL;
1965
/* -- add the new listener_rec into the list -- */
1966
/* FIXME: should we somehow lock this list ? */
1967
lr_walk = ap_listeners;
1970
- while (lr_walk->next) lr_walk = lr_walk->next;
1973
+ while (lr_walk->next) {
1974
+ lr_walk = lr_walk->next;
1977
lr_walk->next = lr_new;
1982
ap_listeners = lr_walk = lr_new;
1990
@@ -1767,13 +1817,13 @@
1991
_DBG("function entered", 0);
1993
/* FIXME: should we somehow lock this list ? */
1994
- while (ap_listeners)
1996
+ while (ap_listeners) {
1997
lr_walk = ap_listeners->next;
1998
apr_socket_close(ap_listeners->sd);
1999
ap_listeners = lr_walk;
2001
- num_listensocks=0;
2003
+ num_listensocks = 0;
2006
apr_status_t cleanup_child_info(void *d)
2007
@@ -1820,17 +1870,18 @@
2008
apr_socket_t *sock = NULL;
2009
apr_socket_t *pod_sock = NULL;
2011
- mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
2012
- * child initializes
2014
+ /* for benefit of any hooks that run as this
2015
+ * child initializes
2017
+ mpm_state = AP_MPMQ_STARTING;
2019
my_child_num = child_num_arg;
2020
ap_my_pid = getpid();
2021
requests_this_child = 0;
2023
_DBG("sock_fd_in=%d sock_fd_out=%d",
2024
- CHILD_INFO_TABLE[my_child_num].senv->input,
2025
- CHILD_INFO_TABLE[my_child_num].senv->output);
2026
+ CHILD_INFO_TABLE[my_child_num].senv->input,
2027
+ CHILD_INFO_TABLE[my_child_num].senv->output);
2029
/* Get a sub context for global allocations in this child, so that
2030
* we can have cleanups occur when the child exits.
2031
@@ -1853,35 +1904,44 @@
2032
clean_child_exit(APEXIT_CHILDFATAL);
2035
- switch(CHILD_INFO_TABLE[my_child_num].type)
2037
- case CHILD_TYPE_MULTIPLEXER:
2038
- _DBG("MULTIPLEXER %d", my_child_num);
2041
- case CHILD_TYPE_PROCESSOR:
2042
- case CHILD_TYPE_WORKER:
2043
- _DBG("%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type), my_child_num);
2045
- /* -- create new listener to receive from multiplexer -- */
2046
- apr_os_sock_put(&sock, &CHILD_INFO_TABLE[my_child_num].senv->input, pconf);
2048
- listen_add(pconf, sock, receive_from_multiplexer);
2051
+ switch (CHILD_INFO_TABLE[my_child_num].type) {
2052
+ case CHILD_TYPE_MULTIPLEXER:
2053
+ _DBG("MULTIPLEXER %d", my_child_num);
2055
+ /* -- create new listener to receive from workers -- */
2056
+ apr_os_sock_put(&sock, &CHILD_INFO_TABLE[my_child_num].senv->input,
2058
+ listen_add(pconf, sock, receive_connection);
2061
+ case CHILD_TYPE_PROCESSOR:
2062
+ case CHILD_TYPE_WORKER:
2063
+ _DBG("%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type),
2066
+ /* -- create new listener to receive from multiplexer -- */
2067
+ apr_os_sock_put(&sock, &CHILD_INFO_TABLE[my_child_num].senv->input,
2070
+ listen_add(pconf, sock, receive_connection);
2075
+ _DBG("unspecified child type for %d sleeping a while ...",
2079
- _DBG("unspecified child type for %d sleeping a while ...", my_child_num);
2086
apr_os_file_get(&fd, pipe_of_death_in);
2087
apr_os_sock_put(&pod_sock, &fd, pconf);
2088
listen_add(pconf, pod_sock, check_pipe_of_death);
2090
- if(peruser_setup_child(my_child_num, pchild) != 0)
2091
+ if (peruser_setup_child(my_child_num, pchild) != 0) {
2092
clean_child_exit(APEXIT_CHILDFATAL);
2095
ap_run_child_init(pchild, ap_server_conf);
2097
@@ -1889,8 +1949,8 @@
2098
(void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
2100
/* Set up the pollfd array */
2101
- listensocks = apr_pcalloc(pchild,
2102
- sizeof(*listensocks) * (num_listensocks));
2103
+ listensocks = apr_pcalloc(pchild, sizeof(*listensocks) * (num_listensocks));
2105
for (lr = ap_listeners, i = 0; i < num_listensocks; lr = lr->next, i++) {
2106
listensocks[i].accept_func = lr->accept_func;
2107
listensocks[i].sd = lr->sd;
2108
@@ -1909,29 +1969,30 @@
2109
bucket_alloc = apr_bucket_alloc_create(pchild);
2113
- * (Re)initialize this child to a pre-connection state.
2116
+ * (Re)initialize this child to a pre-connection state.
2119
- current_conn = NULL;
2120
+ current_conn = NULL;
2122
- apr_pool_clear(ptrans);
2123
+ apr_pool_clear(ptrans);
2125
- if (CHILD_INFO_TABLE[my_child_num].type != CHILD_TYPE_MULTIPLEXER
2126
- && ap_max_requests_per_child > 0
2127
- && requests_this_child++ >= ap_max_requests_per_child) {
2128
+ if (CHILD_INFO_TABLE[my_child_num].type != CHILD_TYPE_MULTIPLEXER
2129
+ && ap_max_requests_per_child > 0
2130
+ && requests_this_child++ >= ap_max_requests_per_child) {
2131
_DBG("max requests reached, dying now", 0);
2132
- clean_child_exit(0);
2134
+ clean_child_exit(0);
2137
(void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
2139
CHILD_INFO_TABLE[my_child_num].status = CHILD_STATUS_READY;
2140
- _DBG("Child %d (%s) is now ready", my_child_num, child_type_string(CHILD_INFO_TABLE[my_child_num].type));
2141
+ _DBG("Child %d (%s) is now ready", my_child_num,
2142
+ child_type_string(CHILD_INFO_TABLE[my_child_num].type));
2145
- * Wait for an acceptable connection to arrive.
2148
+ * Wait for an acceptable connection to arrive.
2151
/* Lock around "accept", if necessary */
2152
if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) {
2153
@@ -1943,54 +2004,63 @@
2156
/* multiple listening sockets - need to poll */
2162
ret = apr_poll(pollset, num_listensocks, &n, -1);
2164
if (ret != APR_SUCCESS) {
2165
if (APR_STATUS_IS_EINTR(ret)) {
2168
- /* Single Unix documents select as returning errnos
2169
- * EBADF, EINTR, and EINVAL... and in none of those
2170
- * cases does it make sense to continue. In fact
2171
- * on Linux 2.0.x we seem to end up with EFAULT
2172
- * occasionally, and we'd loop forever due to it.
2174
- ap_log_error(APLOG_MARK, APLOG_ERR, ret, ap_server_conf,
2175
- "apr_poll: (listen)");
2176
- clean_child_exit(1);
2178
+ /* Single Unix documents select as returning errnos
2179
+ * EBADF, EINTR, and EINVAL... and in none of those
2180
+ * cases does it make sense to continue. In fact
2181
+ * on Linux 2.0.x we seem to end up with EFAULT
2182
+ * occasionally, and we'd loop forever due to it.
2184
+ ap_log_error(APLOG_MARK, APLOG_ERR, ret, ap_server_conf,
2185
+ "apr_poll: (listen)");
2186
+ clean_child_exit(1);
2189
/* find a listener */
2190
curr_pollfd = last_pollfd;
2194
if (curr_pollfd >= num_listensocks) {
2198
/* XXX: Should we check for POLLERR? */
2199
if (pollset[curr_pollfd].rtnevents & APR_POLLIN) {
2200
last_pollfd = curr_pollfd;
2201
offset = curr_pollfd;
2204
- } while (curr_pollfd != last_pollfd);
2206
+ while (curr_pollfd != last_pollfd);
2215
_DBG("input available ... resetting socket.",0);
2216
- sock = NULL; /* important! */
2217
+ sock = NULL; /* important! */
2219
/* if we accept() something we don't want to die, so we have to
2222
- status = listensocks[offset].accept_func((void *)&sock, &listensocks[offset], ptrans);
2223
+ status = listensocks[offset].accept_func((void *) &sock,
2224
+ &listensocks[offset], ptrans);
2226
if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) {
2227
- SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
2228
+ SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
2231
if (status == APR_EGENERAL) {
2232
@@ -2003,45 +2073,48 @@
2234
if (CHILD_INFO_TABLE[my_child_num].status == CHILD_STATUS_READY) {
2235
CHILD_INFO_TABLE[my_child_num].status = CHILD_STATUS_ACTIVE;
2236
- _DBG("Child %d (%s) is now active", my_child_num, child_type_string(CHILD_INFO_TABLE[my_child_num].type));
2237
+ _DBG("Child %d (%s) is now active", my_child_num,
2238
+ child_type_string(CHILD_INFO_TABLE[my_child_num].type));
2241
- if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_PROCESSOR ||
2242
- CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_WORKER ||
2243
- CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER)
2245
- _DBG("CHECKING IF WE SHOULD CLONE A CHILD...");
2246
+ if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_PROCESSOR
2247
+ || CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_WORKER
2248
+ || CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) {
2250
+ _DBG("CHECKING IF WE SHOULD CLONE A CHILD...");
2252
- _DBG("total_processors = %d, max_processors = %d",
2253
- total_processors(my_child_num),
2254
- CHILD_INFO_TABLE[my_child_num].senv->max_processors);
2256
- _DBG("idle_processors = %d, min_free_processors = %d",
2257
- idle_processors(my_child_num),
2258
- CHILD_INFO_TABLE[my_child_num].senv->min_free_processors);
2260
- if(total_processors(my_child_num) <
2261
- CHILD_INFO_TABLE[my_child_num].senv->max_processors &&
2262
- (idle_processors(my_child_num) <=
2263
- CHILD_INFO_TABLE[my_child_num].senv->min_free_processors ||
2264
- total_processors(my_child_num) <
2265
- CHILD_INFO_TABLE[my_child_num].senv->min_processors
2268
- _DBG("CLONING CHILD");
2271
+ _DBG("total_processors = %d, max_processors = %d",
2272
+ total_processors(my_child_num),
2273
+ CHILD_INFO_TABLE[my_child_num].senv->max_processors);
2275
+ _DBG("idle_processors = %d, min_free_processors = %d",
2276
+ idle_processors(my_child_num),
2277
+ CHILD_INFO_TABLE[my_child_num].senv->min_free_processors);
2279
+ if (total_processors(my_child_num)
2280
+ < CHILD_INFO_TABLE[my_child_num].senv->max_processors
2281
+ && (idle_processors(my_child_num)
2282
+ <= CHILD_INFO_TABLE[my_child_num].senv->min_free_processors
2283
+ || total_processors(my_child_num)
2284
+ < CHILD_INFO_TABLE[my_child_num].senv->min_processors)) {
2286
+ _DBG("CLONING CHILD");
2291
- if (!setjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer))
2293
+ if (!setjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer)) {
2294
_DBG("marked jmpbuffer",0);
2296
+ CHILD_INFO_TABLE[my_child_num].senv->stats_connections++;
2298
_TRACE_CALL("process_socket()",0);
2300
process_socket(ptrans, sock, my_child_num, bucket_alloc, pchild);
2302
_TRACE_RET("process_socket()",0);
2307
_DBG("landed from longjmp",0);
2308
CHILD_INFO_TABLE[my_child_num].sock_fd = AP_PERUSER_THISCHILD;
2310
@@ -2055,17 +2128,17 @@
2311
_DBG("ap_mpm_pod_check(pod) = APR_SUCCESS; dying now", 0);
2314
- else if (ap_my_generation !=
2315
- ap_scoreboard_image->global->running_generation) { /* restart? */
2316
+ else if (ap_my_generation
2317
+ != ap_scoreboard_image->global->running_generation) {
2318
/* yeah, this could be non-graceful restart, in which case the
2319
* parent will kill us soon enough, but why bother checking?
2321
- _DBG("ap_my_generation != ap_scoreboard_image->global->running_generation; dying now", 0);
2322
+ _DBG("ap_my_generation !="
2323
+ " ap_scoreboard_image->global->running_generation; dying now");
2327
- if(CHILD_INFO_TABLE[my_child_num].status == CHILD_STATUS_RESTART)
2329
+ if (CHILD_INFO_TABLE[my_child_num].status == CHILD_STATUS_RESTART) {
2330
_DBG("restarting", 0);
2333
@@ -2075,40 +2148,43 @@
2334
clean_child_exit(0);
2337
-static server_env_t* find_senv_by_name(const char *name) {
2338
+static server_env_t* find_senv_by_name(const char *name)
2342
- if (name == NULL) return NULL;
2343
+ if (name == NULL) {
2347
_DBG("name=%s", name);
2349
- for(i = 0; i < NUM_SENV; i++)
2351
- if(SENV[i].name != NULL && !strcmp(SENV[i].name, name)) {
2355
+ for (i = 0; i < NUM_SENV; i++) {
2356
+ if (SENV[i].name != NULL && !strcmp(SENV[i].name, name)) {
2364
-static server_env_t* find_matching_senv(server_env_t* senv) {
2365
+static server_env_t* find_matching_senv(server_env_t* senv)
2369
- _DBG("name=%s uid=%d gid=%d chroot=%s", senv->name, senv->uid, senv->gid, senv->chroot);
2370
+ _DBG("name=%s uid=%d gid=%d chroot=%s", senv->name, senv->uid, senv->gid,
2373
- for(i = 0; i < NUM_SENV; i++)
2375
- if((senv->name != NULL && SENV[i].name != NULL && !strcmp(SENV[i].name, senv->name)) ||
2376
- (senv->name == NULL && SENV[i].uid == senv->uid && SENV[i].gid == senv->gid &&
2378
- (SENV[i].chroot == NULL && senv->chroot == NULL) ||
2379
- ((SENV[i].chroot != NULL || senv->chroot != NULL) && !strcmp(SENV[i].chroot, senv->chroot)))
2385
+ for (i = 0; i < NUM_SENV; i++) {
2386
+ if ((senv->name != NULL && SENV[i].name != NULL
2387
+ && !strcmp(SENV[i].name, senv->name))
2388
+ || (senv->name == NULL && SENV[i].uid == senv->uid
2389
+ && SENV[i].gid == senv->gid
2390
+ && ((SENV[i].chroot == NULL && senv->chroot == NULL)
2391
+ || ((SENV[i].chroot != NULL || senv->chroot != NULL)
2392
+ && !strcmp(SENV[i].chroot, senv->chroot))))) {
2399
@@ -2124,15 +2200,16 @@
2402
_DBG("Found existing senv");
2409
- if(NUM_SENV >= server_limit)
2411
- _DBG("server_limit reached!");
2414
+ if (NUM_SENV >= server_limit) {
2415
+ _DBG("server_limit reached!");
2419
_DBG("Creating new senv");
2421
@@ -2141,32 +2218,31 @@
2422
SENV[NUM_SENV].availability = 100;
2424
socketpair(PF_UNIX, SOCK_STREAM, 0, socks);
2425
- SENV[NUM_SENV].input = socks[0];
2426
+ SENV[NUM_SENV].input = socks[0];
2427
SENV[NUM_SENV].output = socks[1];
2429
senv = &SENV[NUM_SENV];
2430
return &SENV[server_env_image->control->num++];
2434
static const char* child_clone()
2440
- for(i = 0; i < NUM_CHILDS; i++)
2442
- if(CHILD_INFO_TABLE[i].pid == 0 &&
2443
- CHILD_INFO_TABLE[i].type == CHILD_TYPE_UNKNOWN) break;
2444
+ for (i = 0; i < NUM_CHILDS; i++) {
2445
+ if (CHILD_INFO_TABLE[i].pid == 0
2446
+ && CHILD_INFO_TABLE[i].type == CHILD_TYPE_UNKNOWN) {
2451
- if(i == NUM_CHILDS && NUM_CHILDS >= server_limit)
2454
+ if (i == NUM_CHILDS && NUM_CHILDS >= server_limit) {
2455
_DBG("Trying to use more child ID's than ServerLimit. "
2456
- "Increase ServerLimit in your config file.");
2457
+ "Increase ServerLimit in your config file.");
2462
_DBG("cloning child #%d from #%d", i, my_child_num);
2464
@@ -2185,49 +2261,67 @@
2465
new->sock_fd = this->sock_fd;
2466
new->status = CHILD_STATUS_STARTING;
2468
- if(i == NUM_CHILDS) child_info_image->control->num++;
2469
+ if (i == NUM_CHILDS) {
2470
+ child_info_image->control->num++;
2476
-static const char* child_add(int type, int status,
2477
- apr_pool_t *pool, server_env_t *senv)
2478
+static const char* child_add(int type, int status, apr_pool_t *pool,
2479
+ server_env_t *senv)
2481
- _DBG("adding child #%d", NUM_CHILDS);
2484
- if(NUM_CHILDS >= server_limit)
2486
+ for (i = 0; i < NUM_CHILDS; i++) {
2487
+ if (CHILD_INFO_TABLE[i].pid == 0
2488
+ && CHILD_INFO_TABLE[i].type == CHILD_TYPE_UNKNOWN) {
2493
+ _DBG("adding child #%d", i);
2495
+ if (i >= server_limit) {
2496
return "Trying to use more child ID's than ServerLimit. "
2497
- "Increase ServerLimit in your config file.";
2498
+ "Increase ServerLimit in your config file.";
2501
- if (senv->chroot && !ap_is_directory(pool, senv->chroot))
2502
- return apr_psprintf(pool, "Error: chroot directory [%s] does not exist", senv->chroot);
2503
+ if (senv->chroot && !ap_is_directory(pool, senv->chroot)) {
2504
+ return apr_psprintf(pool,
2505
+ "Error: chroot directory [%s] does not exist",
2509
- CHILD_INFO_TABLE[NUM_CHILDS].senv = senv_add(senv);
2510
+ CHILD_INFO_TABLE[i].senv = senv_add(senv);
2512
- if(CHILD_INFO_TABLE[NUM_CHILDS].senv == NULL)
2514
+ if (CHILD_INFO_TABLE[i].senv == NULL) {
2515
return "Trying to use more server environments than ServerLimit. "
2516
- "Increase ServerLimit in your config file.";
2517
+ "Increase ServerLimit in your config file.";
2520
+ if (type == CHILD_TYPE_MULTIPLEXER) {
2521
+ multiplexer_senv = CHILD_INFO_TABLE[i].senv;
2524
- if(type != CHILD_TYPE_WORKER)
2525
- CHILD_INFO_TABLE[NUM_CHILDS].senv->processor_id = NUM_CHILDS;
2526
+ if (type != CHILD_TYPE_WORKER) {
2527
+ CHILD_INFO_TABLE[i].senv->processor_id = i;
2530
- CHILD_INFO_TABLE[NUM_CHILDS].type = type;
2531
- CHILD_INFO_TABLE[NUM_CHILDS].sock_fd = AP_PERUSER_THISCHILD;
2532
- CHILD_INFO_TABLE[NUM_CHILDS].status = status;
2533
+ CHILD_INFO_TABLE[i].type = type;
2534
+ CHILD_INFO_TABLE[i].sock_fd = AP_PERUSER_THISCHILD;
2535
+ CHILD_INFO_TABLE[i].status = status;
2537
- _DBG("[%d] uid=%d gid=%d type=%d chroot=%s",
2538
- NUM_CHILDS, senv->uid, senv->gid, type,
2540
+ _DBG("[%d] uid=%d gid=%d type=%d chroot=%s", i, senv->uid,
2541
+ senv->gid, type, senv->chroot);
2543
- if (senv->uid == 0 || senv->gid == 0)
2545
+ if (senv->uid == 0 || senv->gid == 0) {
2546
_DBG("Assigning root user/group to a child.", 0);
2549
- child_info_image->control->num++;
2550
+ if (i >= NUM_CHILDS) {
2551
+ child_info_image->control->num = i + 1;
2556
@@ -2239,31 +2333,29 @@
2557
_DBG("function entered", 0);
2558
dump_server_env_image();
2560
- switch (CHILD_INFO_TABLE[slot].type)
2562
- case CHILD_TYPE_MULTIPLEXER: break;
2563
- case CHILD_TYPE_PROCESSOR: break;
2564
- case CHILD_TYPE_WORKER: break;
2567
- _DBG("no valid client in slot %d", slot);
2572
- if (slot + 1 > ap_max_daemons_limit) {
2573
- ap_max_daemons_limit = slot + 1;
2574
+ switch (CHILD_INFO_TABLE[slot].type) {
2575
+ case CHILD_TYPE_MULTIPLEXER:
2577
+ case CHILD_TYPE_PROCESSOR:
2579
+ case CHILD_TYPE_WORKER:
2583
+ _DBG("no valid client in slot %d", slot);
2589
- apr_signal(SIGHUP, just_die);
2590
+ apr_signal(SIGHUP, just_die);
2591
/* Don't catch AP_SIG_GRACEFUL in ONE_PROCESS mode :) */
2592
- apr_signal(SIGINT, just_die);
2593
+ apr_signal(SIGINT, just_die);
2595
- apr_signal(SIGQUIT, SIG_DFL);
2596
+ apr_signal(SIGQUIT, SIG_DFL);
2598
- apr_signal(SIGTERM, just_die);
2600
+ apr_signal(SIGTERM, just_die);
2604
(void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING,
2605
@@ -2271,29 +2363,29 @@
2607
CHILD_INFO_TABLE[slot].status = CHILD_STATUS_READY;
2611
/* BS2000 requires a "special" version of fork() before a setuid() call */
2612
if ((pid = os_fork(unixd_config.user_name)) == -1) {
2614
- if ((pid = os_fork(s, slot)) == -1) {
2615
+ if ((pid = os_fork(s, slot)) == -1) {
2617
if ((pid = fork()) == -1) {
2619
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "fork: Unable to fork new process");
2620
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, s,
2621
+ "fork: Unable to fork new process");
2623
- /* fork didn't succeed. Fix the scoreboard or else
2624
- * it will say SERVER_STARTING forever and ever
2626
- (void) ap_update_child_status_from_indexes(slot, 0, SERVER_DEAD,
2627
+ /* fork didn't succeed. Fix the scoreboard or else
2628
+ * it will say SERVER_STARTING forever and ever
2630
+ (void) ap_update_child_status_from_indexes(slot, 0, SERVER_DEAD,
2631
(request_rec *) NULL);
2633
- /* In case system resources are maxxed out, we don't want
2634
- Apache running away with the CPU trying to fork over and
2635
- over and over again. */
2637
+ /* In case system resources are maxxed out, we don't want
2638
+ Apache running away with the CPU trying to fork over and
2639
+ over and over again. */
2647
@@ -2301,38 +2393,33 @@
2648
/* by default AIX binds to a single processor
2649
* this bit unbinds children which will then bind to another cpu
2651
- int status = bindprocessor(BINDPROCESS, (int)getpid(),
2652
- PROCESSOR_CLASS_ANY);
2653
- if (status != OK) {
2654
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
2655
- ap_server_conf, "processor unbind failed %d", status);
2657
+ int status = bindprocessor(BINDPROCESS, (int)getpid(),
2658
+ PROCESSOR_CLASS_ANY);
2659
+ if (status != OK) {
2660
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
2661
+ ap_server_conf, "processor unbind failed %d", status);
2664
- RAISE_SIGSTOP(MAKE_CHILD);
2666
+ RAISE_SIGSTOP(MAKE_CHILD); AP_MONCONTROL(1);
2667
/* Disable the parent's signal handlers and set up proper handling in
2670
- apr_signal(SIGHUP, just_die);
2671
- apr_signal(SIGTERM, just_die);
2673
+ apr_signal(SIGHUP, just_die);
2674
+ apr_signal(SIGTERM, just_die);
2675
/* The child process doesn't do anything for AP_SIG_GRACEFUL.
2676
* Instead, the pod is used for signalling graceful restart.
2678
/* apr_signal(AP_SIG_GRACEFUL, restart); */
2681
clean_child_exit(0);
2684
ap_scoreboard_image->parent[slot].pid = pid;
2685
- CHILD_INFO_TABLE[slot].pid = pid;
2687
- ap_child_table[slot].pid = pid;
2688
- ap_child_table[slot].status = SERVER_ALIVE;
2689
+ CHILD_INFO_TABLE[slot].pid = pid;
2696
* idle_spawn_rate is the number of children that will be spawned on the
2697
* next maintenance cycle if there aren't enough idle servers. It is
2698
@@ -2346,119 +2433,109 @@
2699
static int total_processes(int child_num)
2702
- for(i = 0, total = 0; i < NUM_CHILDS; ++i)
2704
- if(CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv &&
2705
- (!(CHILD_INFO_TABLE[i].type == CHILD_TYPE_PROCESSOR &&
2706
- CHILD_INFO_TABLE[i].status == CHILD_STATUS_STANDBY)))
2710
+ for (i = 0, total = 0; i < NUM_CHILDS; ++i) {
2711
+ if (CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv
2712
+ && CHILD_INFO_TABLE[i].status != CHILD_STATUS_STANDBY) {
2720
+static int determine_child_fate(int childnum, child_info_t *child,
2721
+ worker_score *child_sb, apr_time_t now)
2723
+ time_t idle_time = apr_time_sec(now - child_sb->last_used);
2725
+ if (total_processes(childnum) <= child->senv->min_processors) {
2726
+ /* We will not kill a child, if the senv needs live workers */
2730
+ if (child->type == CHILD_TYPE_PROCESSOR ||
2731
+ child->type == CHILD_TYPE_WORKER) {
2733
+ if (idle_processors(childnum) <= child->senv->min_free_processors ||
2734
+ child->senv->min_free_processors == 0) {
2735
+ /* We will not kill a child, if the senv needs idle workers */
2739
+ if (expire_timeout > 0 && idle_time > expire_timeout) {
2740
+ /* Child has not handled a request for some time now, stop it */
2741
+ _DBG("Expire timeout reached for child #%d", childnum);
2745
+ if (idle_timeout > 0 && child_sb->status == SERVER_READY
2746
+ && idle_time > idle_timeout) {
2747
+ /* Child has been idle for too long, stop it */
2748
+ _DBG("Idle timeout reached for child #%d", childnum);
2752
+ if (child->senv->max_free_processors > 0
2753
+ && idle_processors(childnum) >= child->senv->max_free_processors) {
2754
+ /* Too many spare workers available */
2755
+ _DBG("Too many spare workers for processor %s, stopping child #%d",
2756
+ child->senv->name, childnum);
2759
+ } else if (child->type == CHILD_TYPE_MULTIPLEXER) {
2760
+ if (multiplexer_idle_timeout > 0 && child_sb->status == SERVER_READY
2761
+ && idle_time > multiplexer_idle_timeout) {
2762
+ /* Multiplexer has been idle for too long, stop it */
2763
+ _DBG("Stopping idle multiplexer #%d", childnum);
2771
static void perform_idle_server_maintenance(apr_pool_t *p)
2774
+ int i, stop_child;
2776
+ child_info_t *child;
2777
+ worker_score *child_sb;
2780
- /* _DBG("function entered", 0); */
2782
now = apr_time_now();
2784
- for (i = 0; i < NUM_CHILDS; ++i)
2786
- if(CHILD_INFO_TABLE[i].pid == 0)
2788
- if(CHILD_INFO_TABLE[i].status == CHILD_STATUS_STARTING)
2789
- make_child(ap_server_conf, i);
2792
- (((CHILD_INFO_TABLE[i].type == CHILD_TYPE_PROCESSOR ||
2793
- CHILD_INFO_TABLE[i].type == CHILD_TYPE_WORKER) &&
2794
- ap_scoreboard_image->parent[i].pid > 1) &&
2795
- (idle_processors (i) > CHILD_INFO_TABLE[i].senv->min_free_processors || CHILD_INFO_TABLE[i].senv->min_free_processors == 0) &&
2796
- total_processes (i) > CHILD_INFO_TABLE[i].senv->min_processors &&
2798
- (expire_timeout > 0 && ap_scoreboard_image->servers[i][0].status != SERVER_DEAD &&
2799
- apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > expire_timeout) ||
2800
- (idle_timeout > 0 && ap_scoreboard_image->servers[i][0].status == SERVER_READY &&
2801
- apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > idle_timeout) ||
2802
- (CHILD_INFO_TABLE[i].senv->max_free_processors > 0 && CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY &&
2803
- idle_processors(i) > CHILD_INFO_TABLE[i].senv->max_free_processors))
2805
- || (CHILD_INFO_TABLE[i].type == CHILD_TYPE_MULTIPLEXER &&
2806
- (multiplexer_idle_timeout > 0 && ap_scoreboard_image->servers[i][0].status == SERVER_READY &&
2807
- apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > multiplexer_idle_timeout) &&
2808
- total_processors(i) > CHILD_INFO_TABLE[i].senv->min_processors
2812
- CHILD_INFO_TABLE[i].pid = 0;
2813
- CHILD_INFO_TABLE[i].status = CHILD_STATUS_STANDBY;
2814
+ for (i = 0; i < NUM_CHILDS; ++i) {
2815
+ child = &CHILD_INFO_TABLE[i];
2816
+ child_sb = &ap_scoreboard_image->servers[i][0];
2818
- if(CHILD_INFO_TABLE[i].type == CHILD_TYPE_WORKER || CHILD_INFO_TABLE[i].type == CHILD_TYPE_MULTIPLEXER)
2820
- /* completely free up this slot */
2821
+ if (child->status == CHILD_STATUS_STANDBY) {
2825
+ if (child->pid == 0) {
2826
+ if (child->status == CHILD_STATUS_STARTING) {
2827
+ make_child(ap_server_conf, i);
2830
- CHILD_INFO_TABLE[i].senv = (server_env_t*)NULL;
2831
- CHILD_INFO_TABLE[i].type = CHILD_TYPE_UNKNOWN;
2832
- CHILD_INFO_TABLE[i].sock_fd = -3; /* -1 and -2 are taken */
2835
- if(kill(ap_scoreboard_image->parent[i].pid, SIGTERM) == -1)
2837
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
2838
- ap_server_conf, "kill SIGTERM");
2840
+ if (ap_scoreboard_image->parent[i].pid == 0) {
2845
- ap_update_child_status_from_indexes(i, 0, SERVER_DEAD, NULL);
2849
- for(i=0;i<grace_children;i++) {
2850
- if (child_grace_info_table[i].pid > 0 && expire_timeout > 0 &&
2851
- apr_time_sec(now - child_grace_info_table[i].last_used) > expire_timeout) {
2853
- _DBG("Killing a child from last graceful (pid=%d,childno=%d,last_used=%d)",
2854
- child_grace_info_table[i].pid, child_grace_info_table[i].id,
2855
- child_grace_info_table[i].last_used);
2857
- if(kill(child_grace_info_table[i].pid, SIGTERM) == -1)
2859
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
2860
- ap_server_conf, "kill SIGTERM");
2861
+ if (determine_child_fate(i, child, child_sb, now) == 1) {
2862
+ child->status = CHILD_STATUS_STANDBY;
2864
+ if (kill(ap_scoreboard_image->parent[i].pid, SIGTERM) == -1) {
2865
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
2869
- /* We don't need to do remove_grace_child() here,
2870
- * because it will be automatically done once
2871
- * the child dies by ap_mpm_run() */
2877
-int remove_grace_child(int slot) {
2878
- if (slot < grace_children) {
2879
- child_grace_info_table[slot].id = 0;
2880
- child_grace_info_table[slot].pid = 0;
2881
- child_grace_info_table[slot].status = CHILD_STATUS_STANDBY;
2882
- child_grace_info_table[slot].type = CHILD_TYPE_UNKNOWN;
2883
- child_grace_info_table[slot].last_used = 0;
2884
- grace_children_alive--;
2886
- if (grace_children_alive <= 0) { /* All children have returned from graceful */
2887
- _DBG("Every child has returned from graceful restart - freeing child_grace_info_table");
2888
- grace_children_alive = 0;
2890
- grace_children = 0;
2891
- free(child_grace_info_table);
2898
/*****************************************************************
2899
* Executive routines.
2901
@@ -2466,10 +2543,11 @@
2902
int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
2909
-/* apr_socket_t *sock = NULL; */
2910
+ unsigned char status;
2911
+ /* apr_socket_t *sock = NULL; */
2913
ap_log_pid(pconf, ap_pid_fname);
2915
@@ -2488,7 +2566,7 @@
2916
ap_server_root_relative(_pconf, ap_lock_fname),
2919
- rv = apr_proc_mutex_create(&accept_mutex, ap_lock_fname,
2920
+ rv = apr_proc_mutex_create(&accept_mutex, ap_lock_fname,
2921
ap_accept_lock_mech, _pconf);
2922
if (rv != APR_SUCCESS) {
2923
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
2924
@@ -2498,8 +2576,8 @@
2927
#if APR_USE_SYSVSEM_SERIALIZE
2928
- if (ap_accept_lock_mech == APR_LOCK_DEFAULT ||
2929
- ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
2930
+ if (ap_accept_lock_mech == APR_LOCK_DEFAULT ||
2931
+ ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
2933
if (ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
2935
@@ -2507,7 +2585,7 @@
2936
if (rv != APR_SUCCESS) {
2937
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
2938
"Couldn't set permissions on cross-process lock; "
2939
- "check User and Group directives");
2940
+ "check User and Group directives");
2941
mpm_state = AP_MPMQ_STOPPING;
2944
@@ -2524,15 +2602,6 @@
2945
ap_scoreboard_image->global->running_generation = ap_my_generation;
2948
- /* Initialize the child table */
2951
- for (i = 0; i < server_limit; i++)
2953
- ap_child_table[i].pid = 0;
2957
/* We need to put the new listeners at the end of the ap_listeners
2958
* list. If we don't, then the pool will be cleared before the
2959
* open_logs phase is called for the second time, and ap_listeners
2960
@@ -2541,12 +2610,12 @@
2965
- apr_os_file_get(&fd, pipe_of_death_in);
2966
- apr_os_sock_put(&sock, &fd, pconf);
2968
+ apr_os_file_get(&fd, pipe_of_death_in);
2969
+ apr_os_sock_put(&sock, &fd, pconf);
2971
- listen_add(pconf, sock, check_pipe_of_death);
2973
+ listen_add(pconf, sock, check_pipe_of_death);
2978
@@ -2554,15 +2623,15 @@
2981
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
2982
- "%s configured -- resuming normal operations",
2983
- ap_get_server_version());
2984
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
2985
- "Server built: %s", ap_get_server_built());
2986
+ "%s configured -- resuming normal operations",
2987
+ ap_get_server_version());
2988
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, "Server built: %s",
2989
+ ap_get_server_built());
2990
#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
2991
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
2992
- "AcceptMutex: %s (default: %s)",
2993
- apr_proc_mutex_name(accept_mutex),
2994
- apr_proc_mutex_defname());
2995
+ "AcceptMutex: %s (default: %s)",
2996
+ apr_proc_mutex_name(accept_mutex),
2997
+ apr_proc_mutex_defname());
2999
restart_pending = shutdown_pending = 0;
3001
@@ -2571,105 +2640,113 @@
3002
_DBG("sizeof(child_info_t) = %d", sizeof(child_info_t));
3004
while (!restart_pending && !shutdown_pending) {
3006
+ int child_slot = -1;
3007
apr_exit_why_e exitwhy;
3008
- int status, processed_status;
3009
+ int status, processed_status;
3010
/* this is a memory leak, but I'll fix it later. */
3014
ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
3016
- /* XXX: if it takes longer than 1 second for all our children
3017
- * to start up and get into IDLE state then we may spawn an
3020
- if (pid.pid != -1) {
3021
+ /* XXX: if it takes longer than 1 second for all our children
3022
+ * to start up and get into IDLE state then we may spawn an
3025
+ if (pid.pid != -1) {
3026
processed_status = ap_process_child_status(&pid, exitwhy, status);
3027
if (processed_status == APEXIT_CHILDFATAL) {
3028
mpm_state = AP_MPMQ_STOPPING;
3032
- if (grace_children > 0) {
3033
- for(i=0;i<grace_children;i++) {
3034
- if (child_grace_info_table[i].pid == pid.pid) {
3038
- if (i != grace_children) {
3039
- _DBG("Child returned from graceful (%d)", i);
3040
- remove_grace_child(i);
3045
/* non-fatal death... note that it's gone in the scoreboard. */
3046
- child_slot = find_child_by_pid(&pid);
3047
- _DBG("child #%d has died ...", child_slot);
3049
- for (i = 0; i < ap_max_daemons_limit; ++i)
3051
- if (ap_child_table[i].pid == pid.pid)
3053
+ for (i = 0; i < NUM_CHILDS; ++i) {
3054
+ if (CHILD_INFO_TABLE[i].pid == pid.pid) {
3060
- if (child_slot >= 0) {
3061
- ap_child_table[child_slot].pid = 0;
3062
+ _DBG("child #%d (pid=%d) has died", child_slot, pid.pid);
3064
+ if (child_slot >= 0) {
3065
+ CHILD_INFO_TABLE[child_slot].pid = 0;
3067
+ status = ap_scoreboard_image->servers[child_slot][0].status;
3069
_TRACE_CALL("ap_update_child_status_from_indexes", 0);
3070
- (void) ap_update_child_status_from_indexes(child_slot, 0, SERVER_DEAD,
3071
- (request_rec *) NULL);
3073
+ (void)ap_update_child_status_from_indexes(child_slot, 0,
3075
+ (request_rec *)NULL);
3077
_TRACE_RET("ap_update_child_status_from_indexes", 0);
3079
if (processed_status == APEXIT_CHILDSICK) {
3080
- /* child detected a resource shortage (E[NM]FILE, ENOBUFS, etc)
3081
+ /* child detected a resource shortage (E[NM]FILE, ENOBUFS,
3083
* cut the fork rate to the minimum
3085
_DBG("processed_status = APEXIT_CHILDSICK", 0);
3086
- idle_spawn_rate = 1;
3087
+ idle_spawn_rate = 1;
3089
- else if (CHILD_INFO_TABLE[child_slot].status == CHILD_STATUS_STANDBY) {
3090
+ else if (status == SERVER_GRACEFUL) {
3091
+ _DBG("cleaning child from last generation");
3092
+ memset(&CHILD_INFO_TABLE[child_slot], 0, sizeof(child_info_t));
3093
+ CHILD_INFO_TABLE[child_slot].id = child_slot;
3095
+ else if (CHILD_INFO_TABLE[child_slot].status
3096
+ == CHILD_STATUS_STANDBY)
3098
_DBG("leaving child in standby state", 0);
3100
+ if (CHILD_INFO_TABLE[child_slot].type == CHILD_TYPE_WORKER
3101
+ || CHILD_INFO_TABLE[child_slot].type == CHILD_TYPE_MULTIPLEXER) {
3102
+ /* completely free up this slot */
3103
+ CHILD_INFO_TABLE[child_slot].senv = (server_env_t*) NULL;
3104
+ CHILD_INFO_TABLE[child_slot].type = CHILD_TYPE_UNKNOWN;
3105
+ CHILD_INFO_TABLE[child_slot].sock_fd = -3; /* -1 and -2 are taken */
3108
- else if (child_slot < ap_daemons_limit &&
3109
- CHILD_INFO_TABLE[child_slot].type !=
3110
- CHILD_TYPE_UNKNOWN) {
3111
- /* we're still doing a 1-for-1 replacement of dead
3112
- * children with new children
3114
+ else if (child_slot < ap_daemons_limit
3115
+ && CHILD_INFO_TABLE[child_slot].type
3116
+ != CHILD_TYPE_UNKNOWN)
3118
+ /* we're still doing a 1-for-1 replacement of dead
3119
+ * children with new children
3121
_DBG("replacing by new child ...", 0);
3122
- make_child(ap_server_conf, child_slot);
3124
+ make_child(ap_server_conf, child_slot);
3126
#if APR_HAS_OTHER_CHILD
3128
- else if (apr_proc_other_child_alert(&pid, APR_OC_REASON_DEATH, status) == APR_SUCCESS) {
3130
+ else if (apr_proc_other_child_alert(&pid, APR_OC_REASON_DEATH,
3131
+ status) == APR_SUCCESS) {
3132
_DBG("Already handled", 0);
3137
- else if (is_graceful) {
3138
- /* Great, we've probably just lost a slot in the
3139
- * scoreboard. Somehow we don't know about this
3143
+ else if (is_graceful) {
3144
+ /* Great, we've probably just lost a slot in the
3145
+ * scoreboard. Somehow we don't know about this
3148
_DBG("long lost child came home, whatever that means", 0);
3150
- ap_log_error(APLOG_MARK, APLOG_WARNING,
3151
- 0, ap_server_conf,
3152
- "long lost child came home! (pid %ld)", (long)pid.pid);
3154
- /* Don't perform idle maintenance when a child dies,
3155
- * only do it when there's a timeout. Remember only a
3156
- * finite number of children can die, and it's pretty
3157
- * pathological for a lot to die suddenly.
3161
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf,
3162
+ "long lost child came home! (pid %ld)",
3165
+ /* Don't perform idle maintenance when a child dies,
3166
+ * only do it when there's a timeout. Remember only a
3167
+ * finite number of children can die, and it's pretty
3168
+ * pathological for a lot to die suddenly.
3173
+ perform_idle_server_maintenance(pconf);
3175
- perform_idle_server_maintenance(pconf);
3178
shutdown_pending = os_check_server(tpf_server_name);
3180
@@ -2680,35 +2757,35 @@
3181
mpm_state = AP_MPMQ_STOPPING;
3183
if (shutdown_pending) {
3184
- /* Time to gracefully shut down:
3185
- * Kill child processes, tell them to call child_exit, etc...
3187
- if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
3188
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
3190
- ap_reclaim_child_processes(1); /* Start with SIGTERM */
3192
- /* cleanup pid file on normal shutdown */
3194
- const char *pidfile = NULL;
3195
- pidfile = ap_server_root_relative (pconf, ap_pid_fname);
3196
- if ( pidfile != NULL && unlink(pidfile) == 0)
3197
- ap_log_error(APLOG_MARK, APLOG_INFO,
3198
- 0, ap_server_conf,
3199
- "removed PID file %s (pid=%ld)",
3200
- pidfile, (long)getpid());
3203
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3204
- "caught SIGTERM, shutting down");
3206
+ /* Time to gracefully shut down:
3207
+ * Kill child processes, tell them to call child_exit, etc...
3209
+ if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
3210
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
3211
+ "killpg SIGTERM");
3213
+ ap_reclaim_child_processes(1); /* Start with SIGTERM */
3215
+ /* cleanup pid file on normal shutdown */
3217
+ const char *pidfile = NULL;
3218
+ pidfile = ap_server_root_relative(pconf, ap_pid_fname);
3219
+ if (pidfile != NULL && unlink(pidfile) == 0)
3220
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
3221
+ "removed PID file %s (pid=%ld)", pidfile,
3225
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3226
+ "caught SIGTERM, shutting down");
3230
/* we've been told to restart */
3231
apr_signal(SIGHUP, SIG_IGN);
3233
- /* not worth thinking about */
3235
+ /* not worth thinking about */
3239
/* advance to the next generation */
3240
@@ -2717,7 +2794,7 @@
3243
ap_scoreboard_image->global->running_generation = ap_my_generation;
3246
/* cleanup sockets */
3247
for (i = 0; i < NUM_SENV; i++) {
3248
close(SENV[i].input);
3249
@@ -2727,100 +2804,45 @@
3251
char char_of_death = AP_PERUSER_CHAR_OF_DEATH;
3253
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3254
- "Graceful restart requested, doing restart");
3257
- /* kill off the idle ones */
3258
- ap_mpm_pod_killpg(pod, ap_max_daemons_limit);
3260
- /* This is mostly for debugging... so that we know what is still
3261
- * gracefully dealing with existing request. This will break
3262
- * in a very nasty way if we ever have the scoreboard totally
3263
- * file-based (no shared memory)
3265
- for (i = 0; i < ap_daemons_limit; ++i) {
3266
- if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
3267
- ap_scoreboard_image->servers[i][0].status = SERVER_GRACEFUL;
3272
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
3273
- ap_server_conf, AP_SIG_GRACEFUL_STRING " received. "
3274
- "Doing graceful restart");
3275
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3276
+ "Graceful restart requested, doing restart");
3278
/* This is mostly for debugging... so that we know what is still
3279
- * gracefully dealing with existing request.
3280
+ * gracefully dealing with existing request. This will break
3281
+ * in a very nasty way if we ever have the scoreboard totally
3282
+ * file-based (no shared memory)
3285
- int alivechildren = 0;
3286
- child_grace_info_t* old_grace_info;
3288
- for (i = 0; i < NUM_CHILDS; ++i)
3290
- ((ap_child_table[i].pid) && (ap_child_table[i].status = SERVER_DYING));
3292
- if (CHILD_INFO_TABLE[i].pid) {
3297
- _DBG("Initializing child_grace_info_table", 0);
3299
- if (alivechildren > 0) {
3300
- if (grace_children > 0) {
3301
- old_grace_info = child_grace_info_table;
3302
- _DBG("%d children still living from last graceful "
3303
- "- adding to new child_grace_info_table",
3307
- child_grace_info_table = (child_grace_info_t*)calloc(alivechildren+grace_children,
3308
- sizeof(child_grace_info_t));
3310
- if (grace_children > 0) {
3311
- for(i=0;i<grace_children;i++) {
3312
- child_grace_info_table[i] = old_grace_info[i];
3314
- grace_children = i;
3315
- free(old_grace_info);
3317
- else grace_children = 0;
3319
+ for (i = 0; i < ap_daemons_limit; ++i) {
3320
+ if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
3321
+ ap_scoreboard_image->servers[i][0].status = SERVER_GRACEFUL;
3325
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3326
+ AP_SIG_GRACEFUL_STRING " received. "
3327
+ "Doing graceful restart");
3329
/* give the children the signal to die */
3330
- for (i = 0; i < NUM_CHILDS;)
3332
- if ((rv = apr_file_write(pipe_of_death_out, &char_of_death, &one)) != APR_SUCCESS)
3334
- if (APR_STATUS_IS_EINTR(rv)) continue;
3335
+ for (i = 0; i < NUM_CHILDS;i++) {
3336
+ if ((rv = apr_file_write(pipe_of_death_out, &char_of_death, &one))
3338
+ if (APR_STATUS_IS_EINTR(rv)) {
3341
ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
3342
"write pipe_of_death");
3344
- if (CHILD_INFO_TABLE[i].pid) {
3345
- child_grace_info_table[grace_children].id = CHILD_INFO_TABLE[i].id;
3346
- child_grace_info_table[grace_children].pid = CHILD_INFO_TABLE[i].pid;
3347
- child_grace_info_table[grace_children].status = CHILD_INFO_TABLE[i].status;
3348
- child_grace_info_table[grace_children].type = CHILD_INFO_TABLE[i].type;
3349
- child_grace_info_table[grace_children].last_used= ap_scoreboard_image->servers[i][0].last_used;
3351
- grace_children_alive++;
3355
- _DBG("Total children of %d leaving behind for graceful restart (%d living)",
3356
- grace_children, grace_children_alive);
3359
- /* Kill 'em off */
3360
- if (unixd_killpg(getpgrp(), SIGHUP) < 0) {
3361
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
3363
- ap_reclaim_child_processes(0); /* Not when just starting up */
3364
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3365
- "SIGHUP received. Attempting to restart");
3366
+ /* Kill 'em off */
3367
+ if (unixd_killpg(getpgrp(), SIGHUP) < 0) {
3368
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
3371
+ ap_reclaim_child_processes(0); /* Not when just starting up */
3372
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
3373
+ "SIGHUP received. Attempting to restart");
3377
@@ -2829,8 +2851,8 @@
3378
/* == allocate an private server config structure == */
3379
static void *peruser_create_config(apr_pool_t *p, server_rec *s)
3381
- peruser_server_conf *c = (peruser_server_conf *)
3382
- apr_pcalloc(p, sizeof(peruser_server_conf));
3383
+ peruser_server_conf *c =
3384
+ (peruser_server_conf *) apr_pcalloc(p, sizeof(peruser_server_conf));
3387
c->missing_senv_reported = 0;
3388
@@ -2841,7 +2863,8 @@
3389
/* This really should be a post_config hook, but the error log is already
3390
* redirected by that point, so we need to do this in the open_logs phase.
3392
-static int peruser_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
3393
+static int peruser_open_logs(apr_pool_t *p, apr_pool_t *plog,
3394
+ apr_pool_t *ptemp, server_rec *s)
3398
@@ -2849,26 +2872,28 @@
3401
if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) {
3402
- ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0,
3403
- NULL, "no listening sockets available, shutting down");
3405
+ ap_log_error(APLOG_MARK, APLOG_ALERT | APLOG_STARTUP, 0, NULL,
3406
+ "no listening sockets available, shutting down");
3410
ap_log_pid(pconf, ap_pid_fname);
3412
if ((rv = ap_mpm_pod_open(pconf, &pod))) {
3413
- ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL,
3414
- "Could not open pipe-of-death.");
3415
+ ap_log_error(APLOG_MARK, APLOG_CRIT | APLOG_STARTUP, rv, NULL,
3416
+ "Could not open pipe-of-death.");
3420
- if ((rv = apr_file_pipe_create(&pipe_of_death_in, &pipe_of_death_out,
3421
- pconf)) != APR_SUCCESS) {
3422
+ if ((rv = apr_file_pipe_create(&pipe_of_death_in,
3423
+ &pipe_of_death_out, pconf))
3425
ap_log_error(APLOG_MARK, APLOG_ERR, rv,
3426
(const server_rec*) ap_server_conf,
3427
"apr_file_pipe_create (pipe_of_death)");
3431
if ((rv = apr_file_pipe_timeout_set(pipe_of_death_in, 0)) != APR_SUCCESS) {
3432
ap_log_error(APLOG_MARK, APLOG_ERR, rv,
3433
(const server_rec*) ap_server_conf,
3434
@@ -2880,7 +2905,8 @@
3437
static int restart_num = 0;
3438
-static int peruser_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
3439
+static int peruser_pre_config(apr_pool_t *p, apr_pool_t *plog,
3440
+ apr_pool_t *ptemp)
3442
int no_detach, debug, foreground, i;
3443
int tmp_server_limit = DEFAULT_SERVER_LIMIT;
3444
@@ -2897,8 +2923,7 @@
3445
foreground = one_process = 1;
3451
no_detach = ap_exists_config_define("NO_DETACH");
3452
one_process = ap_exists_config_define("ONE_PROCESS");
3453
foreground = ap_exists_config_define("FOREGROUND");
3454
@@ -2908,7 +2933,8 @@
3455
if (restart_num++ == 1) {
3456
if (!one_process && !foreground) {
3457
rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND
3458
- : APR_PROC_DETACH_DAEMONIZE);
3459
+ : APR_PROC_DETACH_DAEMONIZE);
3461
if (rv != APR_SUCCESS) {
3462
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
3463
"apr_proc_detach failed");
3464
@@ -2933,7 +2959,7 @@
3465
ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
3466
ap_extended_status = 1;
3467
#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
3468
- ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
3469
+ ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
3472
expire_timeout = DEFAULT_EXPIRE_TIMEOUT;
3473
@@ -2942,21 +2968,16 @@
3474
processor_wait_timeout = DEFAULT_PROCESSOR_WAIT_TIMEOUT;
3475
processor_wait_steps = DEFAULT_PROCESSOR_WAIT_STEPS;
3478
apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
3480
/* we need to know ServerLimit and ThreadLimit before we start processing
3481
* the tree because we need to already have allocated child_info_table
3483
- for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next)
3485
- if (!strcasecmp(pdir->directive, "ServerLimit"))
3487
- if (atoi(pdir->args) > tmp_server_limit)
3489
+ for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
3490
+ if (!strcasecmp(pdir->directive, "ServerLimit")) {
3491
+ if (atoi(pdir->args) > tmp_server_limit) {
3492
tmp_server_limit = atoi(pdir->args);
3493
- if (tmp_server_limit > MAX_SERVER_LIMIT)
3495
+ if (tmp_server_limit > MAX_SERVER_LIMIT) {
3496
tmp_server_limit = MAX_SERVER_LIMIT;
3499
@@ -2975,9 +2996,11 @@
3501
if (!child_info_image) {
3502
_DBG("Initializing child_info_table", 0);
3503
- child_info_size = tmp_server_limit * sizeof(child_info_t) + sizeof(apr_size_t);
3504
+ child_info_size = tmp_server_limit * sizeof(child_info_t)
3505
+ + sizeof(apr_size_t);
3507
- rv = apr_shm_create(&child_info_shm, child_info_size, NULL, global_pool);
3508
+ rv = apr_shm_create(&child_info_shm, child_info_size, NULL,
3511
/* if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) { */
3512
if (rv != APR_SUCCESS) {
3513
@@ -2997,38 +3020,42 @@
3514
return HTTP_INTERNAL_SERVER_ERROR;
3517
- memset(shmem, 0, child_info_size);
3518
- child_info_image = (child_info*)apr_palloc(global_pool, sizeof(child_info));
3519
- child_info_image->control = (child_info_control*)shmem;
3520
+ child_info_image = (child_info*) apr_palloc(global_pool,
3521
+ sizeof(child_info));
3522
+ child_info_image->control = (child_info_control*) shmem;
3523
shmem += sizeof(child_info_control);
3524
- child_info_image->table = (child_info_t*)shmem;
3527
- _DBG("Clearing child_info_table");
3528
- child_info_image->control->num = 0;
3529
+ child_info_image->table = (child_info_t*) shmem;
3531
- for (i = 0; i < tmp_server_limit; i++) {
3532
- CHILD_INFO_TABLE[i].pid = 0;
3533
- CHILD_INFO_TABLE[i].senv = (server_env_t*)NULL;
3534
- CHILD_INFO_TABLE[i].type = CHILD_TYPE_UNKNOWN;
3535
- CHILD_INFO_TABLE[i].status = CHILD_STATUS_STANDBY;
3536
- CHILD_INFO_TABLE[i].sock_fd = -3; /* -1 and -2 are taken */
3537
- CHILD_INFO_TABLE[i].id = i;
3538
+ for (i = 0; i < tmp_server_limit; i++) {
3539
+ memset(&CHILD_INFO_TABLE[i], 0, sizeof(child_info_t));
3540
+ CHILD_INFO_TABLE[i].id = i;
3544
+ for (i = 0; i < NUM_CHILDS; i++) {
3545
+ if (!is_graceful || (CHILD_INFO_TABLE[i].pid == 0
3546
+ && CHILD_INFO_TABLE[i].status == CHILD_STATUS_STANDBY)) {
3547
+ memset(&CHILD_INFO_TABLE[i], 0, sizeof(child_info_t));
3548
+ CHILD_INFO_TABLE[i].id = i;
3553
- if (!server_env_image)
3555
- _DBG("Initializing server_environments_table", 0);
3556
- server_env_size = tmp_server_limit * sizeof(server_env_t) + sizeof(apr_size_t);
3557
+ if (!server_env_image) {
3558
+ _DBG("Initializing server_environments_table", 0);
3560
- rv = apr_shm_create(&server_env_shm, server_env_size, NULL, global_pool);
3561
+ server_env_size = tmp_server_limit * sizeof(server_env_t)
3562
+ + sizeof(apr_size_t);
3564
- if (rv != APR_SUCCESS) {
3565
- _DBG("shared memory creation failed", 0);
3566
+ rv = apr_shm_create(&server_env_shm, server_env_size, NULL,
3569
- ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
3570
- "Unable to create shared memory segment "
3571
- "(anonymous shared memory failure)");
3572
+ if (rv != APR_SUCCESS) {
3573
+ _DBG("shared memory creation failed", 0);
3575
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
3576
+ "Unable to create shared memory segment "
3577
+ "(anonymous shared memory failure)");
3579
else if (rv == APR_ENOTIMPL) {
3580
_DBG("anonymous shared memory not available", 0);
3581
@@ -3041,38 +3068,39 @@
3584
memset(shmem, 0, server_env_size);
3585
- server_env_image = (server_env*)apr_palloc(global_pool, sizeof(server_env));
3586
- server_env_image->control = (server_env_control*)shmem;
3587
+ server_env_image = (server_env*) apr_palloc(global_pool,
3588
+ sizeof(server_env));
3589
+ server_env_image->control = (server_env_control*) shmem;
3590
shmem += sizeof(server_env_control);
3591
- server_env_image->table = (server_env_t*)shmem;
3592
+ server_env_image->table = (server_env_t*) shmem;
3596
_DBG("Clearing server environment table");
3597
- server_env_image->control->num = 0;
3598
+ server_env_image->control->num = 0;
3600
for (i = 0; i < tmp_server_limit; i++) {
3601
SENV[i].processor_id = -1;
3604
- SENV[i].chroot = NULL;
3605
- SENV[i].input = -1;
3606
- SENV[i].output = -1;
3609
+ SENV[i].chroot = NULL;
3610
+ SENV[i].input = -1;
3611
+ SENV[i].output = -1;
3612
SENV[i].error_cgroup = 0;
3613
- SENV[i].error_pass = 0;
3614
+ SENV[i].error_pass = 0;
3620
-static int peruser_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *server_list)
3621
+static int peruser_post_config(apr_pool_t *p, apr_pool_t *plog,
3622
+ apr_pool_t *ptemp, server_rec *server_list)
3624
- server_env_t senv;
3627
- ap_child_table = (ap_ctable *)apr_pcalloc(p, server_limit * sizeof(ap_ctable));
3628
+ server_env_t senv;
3630
/* Retrieve the function from mod_ssl for detecting SSL virtualhosts */
3631
- ssl_server_is_https = (ssl_server_is_https_t) apr_dynamic_fn_retrieve("ssl_server_is_https");
3632
+ ssl_server_is_https = (ssl_server_is_https_t) apr_dynamic_fn_retrieve(
3633
+ "ssl_server_is_https");
3635
/* Create the server environment for multiplexers */
3636
senv.uid = unixd_config.user_id;
3637
@@ -3081,17 +3109,20 @@
3640
senv.name = "Multiplexer";
3641
+ senv.stats_connections = 0;
3642
+ senv.stats_requests = 0;
3643
+ senv.stats_dropped = 0;
3645
+ senv.min_processors = ap_min_multiplexers;
3646
+ senv.min_free_processors = ap_min_free_processors;
3647
+ senv.max_free_processors = ap_max_free_processors;
3648
+ senv.max_processors = ap_max_multiplexers;
3650
- senv.min_processors = ap_min_multiplexers;
3651
- senv.min_free_processors = ap_min_free_processors;
3652
- senv.max_free_processors = ap_max_free_processors;
3653
- senv.max_processors = ap_max_multiplexers;
3655
- r = child_add(CHILD_TYPE_MULTIPLEXER, CHILD_STATUS_STARTING,
3657
+ r = child_add(CHILD_TYPE_MULTIPLEXER, CHILD_STATUS_STARTING, p,
3661
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, p, r);
3662
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, r);
3666
@@ -3106,33 +3137,34 @@
3667
child_info_t *processor;
3669
if (sconf->senv == NULL) {
3670
- _DBG("Server environment not set on virtualhost %s", r->server->server_hostname);
3671
+ _DBG("Server environment not set on virtualhost %s",
3672
+ r->server->server_hostname);
3674
if (sconf->missing_senv_reported == 0) {
3675
ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
3676
"Virtualhost %s has no server environment set, "
3677
- "request will not be honoured.", r->server->server_hostname);
3678
+ "request will not be honoured.",
3679
+ r->server->server_hostname);
3683
sconf->missing_senv_reported = 1;
3685
return HTTP_INTERNAL_SERVER_ERROR;
3688
- if(CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER)
3689
+ if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) {
3690
processor = &CHILD_INFO_TABLE[sconf->senv->processor_id];
3694
processor = &CHILD_INFO_TABLE[r->connection->id];
3698
- if (!strlen(r->the_request))
3700
+ if (!strlen(r->the_request)) {
3701
_DBG("corrupt request. aborting",0);
3705
- if (processor->sock_fd != AP_PERUSER_THISCHILD)
3707
+ if (processor->sock_fd != AP_PERUSER_THISCHILD) {
3708
apr_socket_t *sock = NULL;
3710
apr_os_sock_put(&sock, &processor->sock_fd, r->connection->pool);
3711
@@ -3142,201 +3174,239 @@
3715
- switch (CHILD_INFO_TABLE[my_child_num].type)
3716
+ switch (CHILD_INFO_TABLE[my_child_num].type) {
3717
+ case CHILD_TYPE_MULTIPLEXER:
3719
- case CHILD_TYPE_MULTIPLEXER:
3721
- _DBG("MULTIPLEXER => Determining if request should be passed. "
3722
- "Child Num: %d, dest-child: %d, hostname from server: %s r->hostname=%s r->the_request=\"%s\"",
3723
- my_child_num, processor->id, r->server->server_hostname, r->hostname, r->the_request);
3724
+ _DBG("MULTIPLEXER => Determining if request should be passed. "
3725
+ "Child Num: %d, dest-child: %d, hostname from server: %s "
3726
+ "r->hostname=%s r->the_request=\"%s\"",
3727
+ my_child_num, processor->id, r->server->server_hostname,
3728
+ r->hostname, r->the_request);
3730
+ if (processor->id != my_child_num) {
3731
+ if (processor->status == CHILD_STATUS_STANDBY) {
3732
+ _DBG("Activating child #%d", processor->id);
3733
+ processor->status = CHILD_STATUS_STARTING;
3736
- if (processor->id != my_child_num)
3738
- if (processor->status == CHILD_STATUS_STANDBY)
3740
- _DBG("Activating child #%d", processor->id);
3741
- processor->status = CHILD_STATUS_STARTING;
3742
+ _DBG("Passing request.",0);
3743
+ if (pass_request(r, processor) == -1) {
3744
+ if (processor->senv->error_pass == 0) {
3745
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
3746
+ "Could not pass request to processor %s "
3747
+ "(virtualhost %s), "
3748
+ "request will not be honoured.",
3749
+ processor->senv->name, r->hostname);
3752
- _DBG("Passing request.",0);
3753
- if (pass_request(r, processor) == -1)
3755
- if (processor->senv->error_pass == 0) {
3756
- ap_log_error(APLOG_MARK, APLOG_ERR, 0,
3757
- ap_server_conf, "Could not pass request to processor %s (virtualhost %s), request will not be honoured.",
3758
- processor->senv->name, r->hostname);
3760
+ processor->senv->error_pass = 1;
3761
+ processor->senv->stats_dropped++;
3763
- processor->senv->error_pass = 1;
3764
+ return HTTP_SERVICE_UNAVAILABLE;
3767
+ processor->senv->error_pass = 0;
3770
- return HTTP_SERVICE_UNAVAILABLE;
3773
- processor->senv->error_pass = 0;
3774
+ _DBG("doing longjmp",0);
3776
+ longjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer, 1);
3778
+ _DBG("request declined at our site",0);
3783
+ _DBG("The server is assigned to the multiplexer! Dropping request");
3787
+ case CHILD_TYPE_PROCESSOR:
3788
+ case CHILD_TYPE_WORKER:
3790
+ if (sconf->senv != CHILD_INFO_TABLE[my_child_num].senv) {
3791
+ _DBG("request not for this worker - passing it back to the "
3794
+ child_info_t *multiplexer = &CHILD_INFO_TABLE[multiplexer_senv->
3797
+ if (pass_request(r, multiplexer) == -1) {
3798
+ if (multiplexer->senv->error_pass == 0) {
3799
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
3800
+ "Could not pass request to multiplexer, "
3801
+ "request will not be honoured (%s).",
3805
- _DBG("doing longjmp",0);
3806
- longjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer, 1);
3807
- _DBG("request declined at our site",0);
3809
+ multiplexer->senv->error_pass = 1;
3810
+ multiplexer->senv->stats_dropped++;
3812
+ return HTTP_SERVICE_UNAVAILABLE;
3815
+ multiplexer->senv->error_pass = 0;
3817
- _DBG("WTF: the server is assigned to the multiplexer! ... dropping request",0);
3818
+ _DBG("doing longjmp",0);
3820
+ longjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer, 1);
3824
- case CHILD_TYPE_PROCESSOR:
3825
- case CHILD_TYPE_WORKER:
3827
- if (sconf->senv != CHILD_INFO_TABLE[my_child_num].senv) {
3828
- ap_log_error(APLOG_MARK, APLOG_WARNING,
3829
- 0, ap_server_conf,
3830
- "invalid virtualhost for this child! (%s)", r->hostname);
3831
- ap_lingering_close(r->connection);
3832
- return HTTP_REQUEST_TIME_OUT;
3835
- _DBG("%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type), my_child_num);
3836
- _DBG("request for %s / (server %s) seems to be for us", r->hostname, r->server->server_hostname);
3838
- if (server_env_cleanup)
3841
- int input = sconf->senv->input;
3842
- int output = sconf->senv->output;
3843
+ _DBG("%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type),
3846
- _DBG("performing handle cleanup");
3847
- for (i = 0; i < NUM_SENV; i++)
3849
- if (SENV[i].input > 0 && SENV[i].input != input) {
3850
- int retval = close(SENV[i].input);
3852
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
3853
- "close(%d) failed", SENV[i].input);
3855
+ _DBG("request for %s / (server %s) seems to be for us", r->hostname,
3856
+ r->server->server_hostname);
3858
+ if (server_env_cleanup) {
3860
+ int input = sconf->senv->input;
3861
+ int output = sconf->senv->output;
3863
+ _DBG("performing handle cleanup");
3864
+ for (i = 0; i < NUM_SENV; i++) {
3865
+ if (&SENV[i] == multiplexer_senv) {
3869
+ if (SENV[i].input > 0 && SENV[i].input != input) {
3870
+ int retval = close(SENV[i].input);
3872
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
3873
+ ap_server_conf, "close(%d) failed",
3876
- if (SENV[i].output > 0 && SENV[i].output != output) {
3877
- int retval = close(SENV[i].output);
3879
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
3880
- "close(%d) failed", SENV[i].output);
3884
+ if (SENV[i].output > 0 && SENV[i].output != output) {
3885
+ int retval = close(SENV[i].output);
3887
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
3888
+ ap_server_conf, "close(%d) failed",
3892
- server_env_cleanup = 0;
3899
- _DBG("unspecified child type %d in %d, dropping request",
3900
- CHILD_INFO_TABLE[my_child_num].type, my_child_num);
3902
+ server_env_cleanup = 0;
3905
+ CHILD_INFO_TABLE[my_child_num].senv->stats_requests++;
3911
+ _DBG("unspecified child type %d in %d, dropping request",
3912
+ CHILD_INFO_TABLE[my_child_num].type, my_child_num);
3917
_DBG("THIS POINT SHOULD NOT BE REACHED!",0);
3922
+int senv_active_cmp(const void *a, const void *b)
3924
+ _DBG("CMP %d %d", *(int *) a,*(int *) b);
3926
-int senv_active_cmp(const void *a, const void *b) {
3927
- _DBG("CMP %d %d", *(int *) a,*(int *) b);
3928
- return active_env_processors(*(int *)a)<active_env_processors(*(int *)b);
3929
+ return active_env_processors(*(int *) a)
3930
+ < active_env_processors(*(int *) b);
3933
static int peruser_status_hook(request_rec *r, int flags)
3936
+ child_info_t *child;
3939
- if (flags & AP_STATUS_SHORT)
3941
+ if (flags & AP_STATUS_SHORT) {
3945
+ if (flags & AP_STATUS_PERUSER_STATS) {
3948
+ sorted_senv = (int *) apr_palloc(r->pool, NUM_SENV * sizeof(int));
3950
- if (flags & AP_STATUS_STATS) {
3954
- sorted_senv=(int *) apr_palloc(r->pool, NUM_SENV*sizeof(int));
3956
- if(!sorted_senv) {
3957
- ap_rputs("peruser_status_hook(): Out of memory",r);
3960
- /* Initial senv table */
3961
- for(i=0; i < NUM_SENV; i++)
3964
- /* sort env by number of processors */
3965
- qsort(sorted_senv, NUM_SENV, sizeof(int), senv_active_cmp);
3967
- ap_rputs("<h3>Processors statistics:</h3><table border=\"0\"><tr><th>Environment</th><th>Pss</th><th>Avail</th></tr>", r);
3968
- /* just a mockup to se what data will be usefull here will put code layter, yes I know we need to iterate ON ENV[] NUM_ENV times */
3969
- for (x = 0; x < NUM_SENV; x++)
3971
- senv = &SENV[sorted_senv[x]];
3974
- ap_rprintf(r, "<tr><td nowrap>%s</td><td nowrap>%d/%d/%d</td>"
3975
- "<td>%d%%</td></tr>",
3976
- senv == NULL ? NULL : ( senv->name == NULL ? "" : senv->name ),
3977
- active_env_processors(sorted_senv[x]), idle_env_processors(sorted_senv[x]), senv == NULL ? 0 : senv->max_processors,
3978
- senv == NULL ? 0 : senv->availability );
3980
- ap_rputs("</table><tr/>", r);
3982
- ap_rputs("<hr/><table>"
3983
- "<tr><th>Pss</th><td>Number of processors active/idle/max</td></tr>"
3984
- "</table><hr/>",r);
3986
- ap_rputs("<hr>\n", r);
3987
- ap_rputs("<h3>peruser status</h3>\n", r);
3988
- ap_rputs("<table border=\"0\">\n", r);
3989
- ap_rputs("<tr><th>ID</th><th>PID</th><th>STATUS</th><th>SB STATUS</th><th>Type</th><th>Processor</th>"
3993
- for (x = 0; x < NUM_CHILDS; x++)
3995
- senv = CHILD_INFO_TABLE[x].senv;
3996
- ap_rprintf(r, "<tr><td>%3d</td><td>%5d</td><td>%8s</td><td>%8s</td><td>%12s</td><td nowrap>%48s</td>"
3997
- "<td>%d/%d/%d</td>"
3998
+ if (!sorted_senv) {
3999
+ ap_rputs("peruser_status_hook(): Out of memory", r);
4003
+ /* Initial senv table */
4004
+ for (i = 0; i < NUM_SENV; i++) {
4005
+ sorted_senv[i] = i;
4008
+ /* sort env by number of processors */
4009
+ qsort(sorted_senv, NUM_SENV, sizeof(int), senv_active_cmp);
4011
+ ap_rputs("<h3>Processors statistics:</h3>"
4012
+ "<table width=700 border=\"0\"><tr><th>Environment</th><th>Pss</th>"
4013
+ "<th>Connections</th><th>Requests</th><th>Dropped (503)</th>"
4014
+ "<th>Avail</th></tr>", r);
4016
+ /* just a mockup to see what data will be useful here will put code
4017
+ * later, yes I know we need to iterate ON ENV[] NUM_ENV times */
4018
+ for (x = 0; x < NUM_SENV; x++) {
4019
+ senv = &SENV[sorted_senv[x]];
4020
+ if (senv == NULL) {
4024
+ ap_rprintf(r, "<tr><td nowrap>%s</td><td nowrap>%d/%d/%d</td>"
4025
+ "<td>%d</td><td>%d</td><td>%d</td><td>%d%%</td></tr>",
4026
+ senv->name == NULL ? "" : senv->name,
4027
+ active_env_processors(sorted_senv[x]),
4028
+ idle_env_processors(sorted_senv[x]),
4029
+ senv->max_processors, senv->stats_connections,
4030
+ senv->stats_requests, senv->stats_dropped,
4031
+ senv->availability);
4033
+ ap_rputs("</table><tr/>", r);
4035
+ ap_rputs("<hr/><table>"
4036
+ "<tr><th>Pss</th><td>Number of processors active/idle/max</td></tr>"
4037
+ "</table><hr/>", r);
4040
+ ap_rputs("<hr>\n", r);
4041
+ ap_rputs("<h3>peruser status</h3>\n", r);
4042
+ ap_rputs("<table border=\"0\">\n", r);
4043
+ ap_rputs("<tr><th>ID</th><th>PID</th><th>STATUS</th><th>SB STATUS</th>"
4044
+ "<th>Type</th><th>Processor</th><th>Pss</th><th>AVAIL</th>"
4047
+ for (x = 0; x < NUM_CHILDS; x++) {
4048
+ child = &CHILD_INFO_TABLE[x];
4049
+ senv = child->senv;
4051
+ "<tr><td>%3d</td><td>%5d</td><td>%8s</td><td>%8s</td>"
4052
+ "<td>%12s</td><td nowrap>%48s</td><td>%d/%d/%d</td>"
4053
"<td>%3d%%</td></tr>\n",
4054
- CHILD_INFO_TABLE[x].id,
4055
- CHILD_INFO_TABLE[x].pid,
4056
- child_status_string(CHILD_INFO_TABLE[x].status),
4057
+ child->id, child->pid,
4058
+ child_status_string(child->status),
4059
scoreboard_status_string(SCOREBOARD_STATUS(x)),
4060
- child_type_string(CHILD_INFO_TABLE[x].type),
4061
- senv == NULL ? NULL : ( senv->name == NULL ? "" : senv->name ),
4062
+ child_type_string(child->type),
4063
+ senv == NULL ? NULL : (senv->name == NULL ? "" :
4065
active_processors(x),
4067
- senv == NULL ? 0 : CHILD_INFO_TABLE[x].senv->max_processors,
4068
- senv == NULL ? 0 : CHILD_INFO_TABLE[x].senv->availability
4071
- ap_rputs("</table>\n", r);
4073
- ap_rputs("<hr/><table>"
4074
- "<tr><th>STATUS</th><td>Processor status</td></tr>"
4075
- "<tr><th>Pss</th><td>Number of processors active/idle/max</td></tr>"
4076
- "</table><hr/>",r);
4079
- if (grace_children > 0) {
4080
- ap_rputs("<h2>peruser graceful children status</h2>\n", r);
4081
- ap_rprintf(r, "%d of total %d still living<br />\n", grace_children_alive, grace_children);
4082
- ap_rputs("<table border=\"0\">\n", r);
4083
- ap_rputs("<tr><td>ID</td><td>PID</td><td>STATUS</td><td>TYPE</td></tr>\n", r);
4084
- for (x = 0; x < grace_children; x++) {
4085
- ap_rprintf(r, "<tr><td>%3d</td><td>%5d</td><td>%8s</td><td>%12s</td></tr>\n",
4086
- child_grace_info_table[x].id,
4087
- child_grace_info_table[x].pid,
4088
- child_status_string(child_grace_info_table[x].status),
4089
- child_type_string(child_grace_info_table[x].type)
4091
+ senv == NULL ? 0 : senv->max_processors,
4092
+ senv == NULL ? 0 : senv->availability);
4094
ap_rputs("</table>\n", r);
4096
+ ap_rputs("<hr/><table>"
4097
+ "<tr><th>STATUS</th><td>Processor status</td></tr>"
4098
+ "<tr><th>Pss</th><td>Number of processors active/idle/max</td></tr>"
4099
+ "</table><hr/>", r);
4105
@@ -3346,7 +3416,7 @@
4106
* will be redirected to a file, and the messages won't print to the
4109
- static const char *const aszSucc[] = {"core.c", NULL};
4110
+ static const char * const aszSucc[] = { "core.c", NULL };
4114
@@ -3368,17 +3438,24 @@
4115
ap_hook_process_connection(peruser_process_connection, NULL, NULL,
4116
APR_HOOK_REALLY_FIRST);
4118
- APR_OPTIONAL_HOOK(ap, status_hook, peruser_status_hook, NULL, NULL, APR_HOOK_MIDDLE);
4119
+ APR_OPTIONAL_HOOK(ap, status_hook, peruser_status_hook, NULL, NULL,
4123
-void senv_init(server_env_t * senv) {
4124
- senv->nice_lvl = 0;
4125
- senv->chroot = NULL;
4126
- senv->cgroup = NULL;
4127
- senv->min_processors = ap_min_processors;
4128
- senv->min_free_processors = ap_min_free_processors;
4129
- senv->max_free_processors = ap_max_free_processors;
4130
- senv->max_processors = ap_max_processors;
4131
+void senv_init(server_env_t * senv)
4133
+ senv->nice_lvl = 0;
4134
+ senv->chroot = NULL;
4135
+ senv->cgroup = NULL;
4136
+ senv->min_processors = ap_min_processors;
4137
+ senv->min_free_processors = ap_min_free_processors;
4138
+ senv->max_free_processors = ap_max_free_processors;
4139
+ senv->max_processors = ap_max_processors;
4140
+ senv->error_cgroup = 0;
4141
+ senv->error_pass = 0;
4142
+ senv->stats_connections = 0;
4143
+ senv->stats_requests = 0;
4144
+ senv->stats_dropped = 0;
4147
static const char *cf_Processor(cmd_parms *cmd, void *dummy, const char *arg)
4148
@@ -3390,15 +3467,17 @@
4149
const char *endp = ap_strrchr_c(arg, '>');
4152
- return apr_psprintf(cmd->temp_pool,
4153
- "Error: Directive %s> missing closing '>'", cmd->cmd->name);
4154
+ return apr_psprintf(cmd->temp_pool,
4155
+ "Error: Directive %s> missing closing '>'",
4159
arg = apr_pstrndup(cmd->pool, arg, endp - arg);
4162
- return apr_psprintf(cmd->temp_pool,
4163
- "Error: %s> must specify a processor name", cmd->cmd->name);
4164
+ return apr_psprintf(cmd->temp_pool,
4165
+ "Error: %s> must specify a processor name",
4169
senv.name = ap_getword_conf(cmd->pool, &arg);
4170
@@ -3406,7 +3485,8 @@
4172
if (strlen(senv.name) == 0) {
4173
return apr_psprintf(cmd->temp_pool,
4174
- "Error: Directive %s> takes one argument", cmd->cmd->name);
4175
+ "Error: Directive %s> takes one argument",
4179
server_env_t *old_senv = find_senv_by_name(senv.name);
4180
@@ -3421,27 +3501,28 @@
4181
current = cmd->directive->first_child;
4184
- for(; current != NULL; current = current->next) {
4185
+ for (; current != NULL; current = current->next) {
4186
directive = current->directive;
4189
if (!strcasecmp(directive, "user")) {
4190
user_name = current->args;
4192
else if (!strcasecmp(directive, "group")) {
4193
- group_name = current->args;
4194
+ group_name = current->args;
4196
else if (!strcasecmp(directive, "chroot")) {
4197
senv.chroot = ap_getword_conf(cmd->pool, ¤t->args);
4199
else if (!strcasecmp(directive, "nicelevel")) {
4200
- senv.nice_lvl = atoi(current->args);
4201
+ senv.nice_lvl = atoi(current->args);
4203
else if (!strcasecmp(directive, "maxprocessors")) {
4204
proc_temp = atoi(current->args);
4206
if (proc_temp < 1) {
4207
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4208
- "WARNING: Require MaxProcessors > 0, setting to 1");
4209
+ "WARNING: Require MaxProcessors > 0,"
4214
@@ -3452,7 +3533,8 @@
4216
if (proc_temp < 0) {
4217
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4218
- "WARNING: Require MinProcessors >= 0, setting to 0");
4219
+ "WARNING: Require MinProcessors >= 0,"
4224
@@ -3463,7 +3545,8 @@
4226
if (proc_temp < 0) {
4227
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4228
- "WARNING: Require MinSpareProcessors >= 0, setting to 0");
4229
+ "WARNING: Require MinSpareProcessors >= 0,"
4234
@@ -3471,10 +3554,11 @@
4236
else if (!strcasecmp(directive, "maxspareprocessors")) {
4237
proc_temp = atoi(current->args);
4240
if (proc_temp < 0) {
4241
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4242
- "WARNING: Require MaxSpareProcessors >= 0, setting to 0");
4243
+ "WARNING: Require MaxSpareProcessors >= 0,"
4248
@@ -3485,53 +3569,64 @@
4251
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4252
- "Unknown directive %s in %s>", directive, cmd->cmd->name);
4253
+ "Unknown directive %s in %s>", directive,
4258
if (user_name == NULL || group_name == NULL) {
4259
return apr_psprintf(cmd->temp_pool,
4260
- "Error: User or Group must be set in %s>", cmd->cmd->name);
4261
+ "Error: User or Group must be set in %s>",
4265
senv.uid = ap_uname2id(user_name);
4266
senv.gid = ap_gname2id(group_name);
4268
_DBG("name=%s user=%s:%d group=%s:%d chroot=%s nice_lvl=%d",
4269
- senv.name, user_name, senv.uid, group_name, senv.gid, senv.chroot, senv.nice_lvl);
4270
+ senv.name, user_name, senv.uid, group_name, senv.gid, senv.chroot,
4273
- _DBG("min_processors=%d min_free_processors=%d max_spare_processors=%d max_processors=%d",
4274
- senv.min_processors, senv.min_free_processors, senv.max_free_processors, senv.max_processors);
4275
+ _DBG("min_processors=%d min_free_processors=%d max_spare_processors=%d "
4276
+ "max_processors=%d", senv.min_processors, senv.min_free_processors,
4277
+ senv.max_free_processors, senv.max_processors);
4279
- return child_add(CHILD_TYPE_PROCESSOR, CHILD_STATUS_STANDBY,
4280
- cmd->pool, &senv);
4281
+ return child_add(CHILD_TYPE_PROCESSOR, CHILD_STATUS_STANDBY, cmd->pool,
4285
static const char *cf_Processor_depr(cmd_parms *cmd, void *dummy,
4286
- const char *user_name, const char *group_name, const char *chroot)
4287
+ const char *user_name,
4288
+ const char *group_name, const char *chroot)
4293
/* we define an Multiplexer child w/ specific uid/gid */
4294
static const char *cf_Multiplexer(cmd_parms *cmd, void *dummy,
4295
- const char *user_name, const char *group_name, const char *chroot)
4296
+ const char *user_name, const char *group_name,
4297
+ const char *chroot)
4299
static short depr_warned = 0;
4302
if (depr_warned == 0) {
4303
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4304
- "WARNING: Multiplexer directive is deprecated. Multiplexer user and group is set by User and Group directives.");
4306
+ "WARNING: Multiplexer directive is deprecated."
4307
+ "Multiplexer user and group is set by User and Group"
4310
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4311
- "To set multiplexer chroot, please use MultiplexerChroot.");
4312
+ "To set multiplexer chroot, "
4313
+ "please use MultiplexerChroot.");
4319
- if (!ap_is_directory(cmd->pool, chroot))
4320
- return apr_psprintf(cmd->pool, "Error: multiplexer chroot directory [%s] does not exist", chroot);
4321
+ if (!ap_is_directory(cmd->pool, chroot)) {
4322
+ return apr_psprintf(cmd->pool, "Error:multiplexer chroot directory"
4323
+ "[%s] does not exist", chroot);
4326
multiplexer_chroot = chroot;
4327
_DBG("Setting multiplexer chroot to %s", chroot);
4328
@@ -3541,12 +3636,13 @@
4331
static const char* cf_MultiplexerChroot(cmd_parms *cmd, void *dummy,
4335
multiplexer_chroot = path;
4337
if (path && !ap_is_directory(cmd->pool, path))
4338
- return apr_psprintf(cmd->pool, "Error: multiplexer chroot directory [%s] does not exist", path);
4339
+ return apr_psprintf(cmd->pool, "Error: multiplexer chroot directory"
4340
+ "[%s] does not exist", path);
4342
_DBG("setting multiplexer chroot to %s", path);
4344
@@ -3554,108 +3650,117 @@
4347
static const char* cf_ServerEnvironment(cmd_parms *cmd, void *dummy,
4348
- const char *name, const char * group_name, const char * chroot)
4349
+ const char *name, const char * group_name, const char * chroot)
4351
peruser_server_conf *sconf = PERUSER_SERVER_CONF(cmd->server->module_config);
4353
char * processor_name, *tmp;
4356
_DBG("function entered", 0);
4359
/* name of processor env */
4360
processor_name = name;
4362
- if(group_name != NULL || chroot != NULL) {
4364
+ if (group_name != NULL || chroot != NULL) {
4365
/* deprecated ServerEnvironment user group chroot syntax
4366
* we create simple server env based on user/group/chroot only
4368
- processor_name = apr_pstrcat(cmd->pool, name, "_",group_name, "_", chroot, NULL);
4370
+ processor_name = apr_pstrcat(cmd->pool, name, "_", group_name, "_",
4373
/* search for previous default server env */
4374
sconf->senv = find_senv_by_name(processor_name);
4376
- if(!sconf->senv) {
4378
+ if (!sconf->senv) {
4380
senv.uid = ap_uname2id(name);
4381
senv.gid = ap_gname2id(group_name);
4382
senv.chroot = chroot;
4383
senv.name = processor_name;
4385
- tmp = child_add(CHILD_TYPE_PROCESSOR, CHILD_STATUS_STANDBY, cmd->pool, &senv);
4387
+ tmp = child_add(CHILD_TYPE_PROCESSOR, CHILD_STATUS_STANDBY,
4388
+ cmd->pool, &senv);
4389
/* error handling in case this child can't be created */
4398
/* use predefined processor environment or default named "user_group_chroot" */
4399
- if(sconf->senv == NULL)
4400
+ if (sconf->senv == NULL) {
4401
sconf->senv = find_senv_by_name(processor_name);
4405
if (sconf->senv == NULL) {
4406
- return apr_psprintf(cmd->pool,
4407
- "Error: Processor %s not defined", name);
4408
+ return apr_psprintf(cmd->pool, "Error: Processor %s not defined", name);
4411
_DBG("user=%d group=%d chroot=%s numchilds=%d",
4412
- sconf->senv->uid, sconf->senv->gid, sconf->senv->chroot, NUM_CHILDS);
4413
+ sconf->senv->uid, sconf->senv->gid, sconf->senv->chroot, NUM_CHILDS);
4418
-static const char *set_min_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
4419
+static const char *set_min_free_servers(cmd_parms *cmd, void *dummy,
4422
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4428
ap_min_free_processors = atoi(arg);
4429
if (ap_min_free_processors <= 0) {
4430
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4431
- "WARNING: detected MinSpareServers set to non-positive.");
4432
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4433
- "Resetting to 1 to avoid almost certain Apache failure.");
4434
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4435
- "Please read the documentation.");
4436
- ap_min_free_processors = 1;
4437
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4438
+ "WARNING: detected MinSpareServers set to non-positive.");
4439
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4440
+ "Resetting to 1 to avoid almost certain Apache failure.");
4441
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4442
+ "Please read the documentation.");
4443
+ ap_min_free_processors = 1;
4450
-static const char *set_max_clients (cmd_parms *cmd, void *dummy, const char *arg)
4451
+static const char *set_max_clients(cmd_parms *cmd, void *dummy, const char *arg)
4453
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4459
ap_daemons_limit = atoi(arg);
4461
if (ap_daemons_limit > server_limit) {
4462
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4463
- "WARNING: MaxClients of %d exceeds ServerLimit value "
4464
- "of %d servers,", ap_daemons_limit, server_limit);
4465
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4466
- " lowering MaxClients to %d. To increase, please "
4467
- "see the ServerLimit", server_limit);
4468
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4470
- ap_daemons_limit = server_limit;
4472
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4473
+ "WARNING: MaxClients of %d exceeds ServerLimit value "
4474
+ "of %d servers,", ap_daemons_limit, server_limit);
4475
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4476
+ " lowering MaxClients to %d. To increase, please "
4477
+ "see the ServerLimit", server_limit);
4478
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, " directive.");
4479
+ ap_daemons_limit = server_limit;
4481
else if (ap_daemons_limit < 1) {
4482
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4483
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4484
"WARNING: Require MaxClients > 0, setting to 1");
4485
- ap_daemons_limit = 1;
4486
+ ap_daemons_limit = 1;
4492
-static const char *set_min_processors (cmd_parms *cmd, void *dummy, const char *arg)
4493
+static const char *set_min_processors(cmd_parms *cmd, void *dummy,
4496
peruser_server_conf *sconf;
4498
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
4499
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE
4504
@@ -3671,24 +3776,28 @@
4506
if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) {
4507
sconf = PERUSER_SERVER_CONF(cmd->server->module_config);
4508
- if(sconf->senv != NULL)
4509
- sconf->senv->min_processors = min_procs;
4511
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4512
- "WARNING: MinProcessors must be set after ServerEnvironment to take effect");
4516
+ if (sconf->senv != NULL) {
4517
+ sconf->senv->min_processors = min_procs;
4519
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4520
+ "WARNING: MinProcessors must be set"
4521
+ "after ServerEnvironment to take effect");
4524
ap_min_processors = min_procs;
4530
-static const char *set_min_free_processors (cmd_parms *cmd, void *dummy, const char *arg)
4531
+static const char *set_min_free_processors(cmd_parms *cmd, void *dummy,
4534
peruser_server_conf *sconf;
4536
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
4537
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE
4542
@@ -3704,57 +3813,64 @@
4544
if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) {
4545
sconf = PERUSER_SERVER_CONF(cmd->server->module_config);
4546
- if(sconf->senv != NULL)
4547
- sconf->senv->min_free_processors = min_free_procs;
4549
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4550
- "WARNING: MinSpareProcessors must be set after ServerEnvironment to take effect");
4553
+ if (sconf->senv != NULL) {
4554
+ sconf->senv->min_free_processors = min_free_procs;
4556
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4557
+ "WARNING: MinSpareProcessors must be set"
4558
+ "after ServerEnvironment to take effect");
4561
ap_min_free_processors = min_free_procs;
4567
-static const char *set_max_free_processors (cmd_parms *cmd, void *dummy, const char *arg)
4568
+static const char *set_max_free_processors(cmd_parms *cmd, void *dummy,
4571
- peruser_server_conf *sconf;
4572
- int max_free_procs;
4573
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
4575
- if (err != NULL) {
4579
- max_free_procs = atoi(arg);
4581
- if (max_free_procs < 0) {
4582
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4583
- "WARNING: Require MaxSpareProcessors >= 0, setting to 0");
4584
- max_free_procs = 0;
4587
- if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) {
4588
- sconf = PERUSER_SERVER_CONF(cmd->server->module_config);
4590
- sconf->senv->max_free_processors = max_free_procs;
4592
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4593
- "WARNING: MaxSpareProcessors must be set after ServerEnvironment to take effect");
4596
- ap_max_free_processors = max_free_procs;
4598
+ peruser_server_conf *sconf;
4599
+ int max_free_procs;
4600
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE
4603
+ if (err != NULL) {
4607
+ max_free_procs = atoi(arg);
4609
+ if (max_free_procs < 0) {
4610
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4611
+ "WARNING: Require MaxSpareProcessors >= 0, setting to 0");
4612
+ max_free_procs = 0;
4615
+ if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) {
4616
+ sconf = PERUSER_SERVER_CONF(cmd->server->module_config);
4618
+ if (sconf != NULL) {
4619
+ sconf->senv->max_free_processors = max_free_procs;
4621
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4622
+ "WARNING: MaxSpareProcessors must be set"
4623
+ "after ServerEnvironment to take effect");
4626
+ ap_max_free_processors = max_free_procs;
4633
-static const char *set_max_processors (cmd_parms *cmd, void *dummy, const char *arg)
4634
+static const char *set_max_processors(cmd_parms *cmd, void *dummy,
4637
peruser_server_conf *sconf;
4639
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
4640
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE
4645
@@ -3770,23 +3886,26 @@
4647
if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) {
4648
sconf = PERUSER_SERVER_CONF(cmd->server->module_config);
4649
- if(sconf->senv != NULL)
4650
- sconf->senv->max_processors = max_procs;
4652
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4653
- "WARNING: MaxProcessors must be set after ServerEnvironment to take effect");
4656
+ if (sconf->senv != NULL) {
4657
+ sconf->senv->max_processors = max_procs;
4659
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4660
+ "WARNING: MaxProcessors must be set"
4661
+ "after ServerEnvironment to take effect");
4664
ap_max_processors = max_procs;
4670
-static const char *set_min_multiplexers (cmd_parms *cmd, void *dummy, const char *arg)
4671
+static const char *set_min_multiplexers(cmd_parms *cmd, void *dummy,
4674
int min_multiplexers;
4675
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
4676
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE
4681
@@ -3805,10 +3924,12 @@
4685
-static const char *set_max_multiplexers (cmd_parms *cmd, void *dummy, const char *arg)
4686
+static const char *set_max_multiplexers(cmd_parms *cmd, void *dummy,
4689
int max_multiplexers;
4690
- const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
4691
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE
4696
@@ -3827,21 +3948,22 @@
4700
-static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
4701
+static const char *set_server_limit(cmd_parms *cmd, void *dummy,
4704
int tmp_server_limit;
4707
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4712
tmp_server_limit = atoi(arg);
4714
/* you cannot change ServerLimit across a restart; ignore
4717
- if (first_server_limit &&
4718
- tmp_server_limit != server_limit) {
4719
+ if (first_server_limit && tmp_server_limit != server_limit) {
4720
/* how do we log a message? the error log is a bit bucket at this
4721
* point; we'll just have to set a flag so that ap_mpm_run()
4722
* logs a warning later
4723
@@ -3849,25 +3971,28 @@
4724
changed_limit_at_restart = 1;
4728
server_limit = tmp_server_limit;
4731
if (server_limit > MAX_SERVER_LIMIT) {
4732
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4733
- "WARNING: ServerLimit of %d exceeds compile time limit "
4734
- "of %d servers,", server_limit, MAX_SERVER_LIMIT);
4735
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4736
- " lowering ServerLimit to %d.", MAX_SERVER_LIMIT);
4737
- server_limit = MAX_SERVER_LIMIT;
4739
- else if (server_limit < 1) {
4740
- ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4741
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4742
+ "WARNING: ServerLimit of %d exceeds compile time limit "
4743
+ "of %d servers,", server_limit, MAX_SERVER_LIMIT);
4744
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4745
+ " lowering ServerLimit to %d.", MAX_SERVER_LIMIT);
4746
+ server_limit = MAX_SERVER_LIMIT;
4747
+ } else if (server_limit < 1) {
4748
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4749
"WARNING: Require ServerLimit > 0, setting to 1");
4757
-static const char *set_expire_timeout (cmd_parms *cmd, void *dummy, const char *arg) {
4758
+static const char *set_expire_timeout(cmd_parms *cmd, void *dummy,
4761
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4764
@@ -3878,7 +4003,9 @@
4768
-static const char *set_idle_timeout (cmd_parms *cmd, void *dummy, const char *arg) {
4769
+static const char *set_idle_timeout(cmd_parms *cmd, void *dummy,
4772
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4775
@@ -3889,7 +4016,9 @@
4779
-static const char *set_multiplexer_idle_timeout (cmd_parms *cmd, void *dummy, const char *arg) {
4780
+static const char *set_multiplexer_idle_timeout(cmd_parms *cmd, void *dummy,
4783
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4786
@@ -3901,9 +4030,12 @@
4790
-static const char *set_processor_wait_timeout (cmd_parms *cmd, void *dummy, const char *timeout, const char *steps) {
4791
+static const char *set_processor_wait_timeout(cmd_parms *cmd, void *dummy,
4792
+ const char *timeout,
4793
+ const char *steps)
4795
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
4801
@@ -3915,7 +4047,8 @@
4803
if (steps_tmp < 1) {
4804
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
4805
- "WARNING: Require ProcessorWaitTimeout steps > 0, setting to 1");
4806
+ "WARNING: Require ProcessorWaitTimeout steps > 0,"
4811
@@ -3925,8 +4058,7 @@
4815
-static const command_rec peruser_cmds[] = {
4816
-UNIX_DAEMON_COMMANDS,
4817
+static const command_rec peruser_cmds[] = { UNIX_DAEMON_COMMANDS,
4819
AP_INIT_TAKE1("MinSpareProcessors", set_min_free_processors, NULL, RSRC_CONF,
4820
"Minimum number of idle children, to handle request spikes"),
4821
@@ -3940,8 +4072,9 @@
4822
"Minimum number of processors per vhost"),
4823
AP_INIT_TAKE1("MaxProcessors", set_max_processors, NULL, RSRC_CONF,
4824
"Maximum number of processors per vhost"),
4826
AP_INIT_TAKE1("MinMultiplexers", set_min_multiplexers, NULL, RSRC_CONF,
4827
- "Minimum number of multiplexers the server can have"),
4828
+ "Minimum number of multiplexers the server can have") ,
4829
AP_INIT_TAKE1("MaxMultiplexers", set_max_multiplexers, NULL, RSRC_CONF,
4830
"Maximum number of multiplexers the server can have"),
4831
AP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF,
4832
@@ -3949,11 +4082,14 @@
4833
AP_INIT_TAKE1("ExpireTimeout", set_expire_timeout, NULL, RSRC_CONF,
4834
"Maximum time a child can live, 0 to disable"),
4835
AP_INIT_TAKE1("IdleTimeout", set_idle_timeout, NULL, RSRC_CONF,
4836
- "Maximum time before a child is killed after being idle, 0 to disable"),
4837
-AP_INIT_TAKE1("MultiplexerIdleTimeout", set_multiplexer_idle_timeout, NULL, RSRC_CONF,
4838
- "Maximum time before a multiplexer is killed after being idle, 0 to disable"),
4839
-AP_INIT_TAKE12("ProcessorWaitTimeout", set_processor_wait_timeout, NULL, RSRC_CONF,
4840
- "Maximum time a multiplexer waits for the processor if it is busy"),
4841
+ "Maximum time before a child is killed after being idle,"
4843
+AP_INIT_TAKE1("MultiplexerIdleTimeout", set_multiplexer_idle_timeout, NULL,
4844
+ RSRC_CONF, "Maximum time before a multiplexer is killed after"
4845
+ " being idle, 0 to disable"),
4846
+AP_INIT_TAKE12("ProcessorWaitTimeout", set_processor_wait_timeout, NULL,
4847
+ RSRC_CONF, "Maximum time a multiplexer waits for the processor"
4848
+ " if it is busy"),
4849
AP_INIT_TAKE23("Multiplexer", cf_Multiplexer, NULL, RSRC_CONF,
4850
"Specify an Multiplexer Child configuration."),
4851
AP_INIT_RAW_ARGS("<Processor", cf_Processor, NULL, RSRC_CONF,
4852
@@ -3969,11 +4105,11 @@
4854
module AP_MODULE_DECLARE_DATA mpm_peruser_module = {
4856
- ap_mpm_rewrite_args, /* hook to run before apache parses args */
4857
- NULL, /* create per-directory config structure */
4858
- NULL, /* merge per-directory config structures */
4859
- peruser_create_config, /* create per-server config structure */
4860
- NULL, /* merge per-server config structures */
4861
- peruser_cmds, /* command apr_table_t */
4862
- peruser_hooks, /* register hooks */
4863
+ ap_mpm_rewrite_args, /* hook to run before apache parses args */
4864
+ NULL, /* create per-directory config structure */
4865
+ NULL, /* merge per-directory config structures */
4866
+ peruser_create_config, /* create per-server config structure */
4867
+ NULL, /* merge per-server config structures */
4868
+ peruser_cmds, /* command apr_table_t */
4869
+ peruser_hooks, /* register hooks */