/[Apache-SVN]/httpd/httpd/branches/2.4.x/server/main.c
ViewVC logotype

Contents of /httpd/httpd/branches/2.4.x/server/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1835175 - (show annotations) (download)
Thu Jul 5 19:26:56 2018 UTC (15 months, 2 weeks ago) by ylavic
File MIME type: text/plain
File size: 28388 byte(s)
Merge r1835094 from trunk (follow up to 2.4.x's r1834321):

global ap_server_conf must be reset when process->pconf is cleared

Submitted by: covener
Reviewed by: covener, rpluem, ylavic

1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "apr.h"
18 #include "apr_strings.h"
19 #include "apr_getopt.h"
20 #include "apr_general.h"
21 #include "apr_lib.h"
22 #include "apr_md5.h"
23 #include "apr_time.h"
24 #include "apr_version.h"
25 #include "apu_version.h"
26
27 #define APR_WANT_STDIO
28 #define APR_WANT_STRFUNC
29 #include "apr_want.h"
30
31 #include "ap_config.h"
32 #include "httpd.h"
33 #include "http_main.h"
34 #include "http_log.h"
35 #include "http_config.h"
36 #include "http_core.h"
37 #include "mod_core.h"
38 #include "http_request.h"
39 #include "http_vhost.h"
40 #include "apr_uri.h"
41 #include "util_ebcdic.h"
42 #include "ap_mpm.h"
43
44 #if APR_HAVE_UNISTD_H
45 #include <unistd.h>
46 #endif
47
48 /* WARNING: Win32 binds http_main.c dynamically to the server. Please place
49 * extern functions and global data in another appropriate module.
50 *
51 * Most significant main() global data can be found in http_config.c
52 */
53
54 static void show_mpm_settings(void)
55 {
56 int mpm_query_info;
57 apr_status_t retval;
58
59 printf("Server MPM: %s\n", ap_show_mpm());
60
61 retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
62
63 if (retval == APR_SUCCESS) {
64 printf(" threaded: ");
65
66 if (mpm_query_info == AP_MPMQ_DYNAMIC) {
67 printf("yes (variable thread count)\n");
68 }
69 else if (mpm_query_info == AP_MPMQ_STATIC) {
70 printf("yes (fixed thread count)\n");
71 }
72 else {
73 printf("no\n");
74 }
75 }
76
77 retval = ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_query_info);
78
79 if (retval == APR_SUCCESS) {
80 printf(" forked: ");
81
82 if (mpm_query_info == AP_MPMQ_DYNAMIC) {
83 printf("yes (variable process count)\n");
84 }
85 else if (mpm_query_info == AP_MPMQ_STATIC) {
86 printf("yes (fixed process count)\n");
87 }
88 else {
89 printf("no\n");
90 }
91 }
92 }
93
94 static void show_compile_settings(void)
95 {
96 printf("Server version: %s\n", ap_get_server_description());
97 printf("Server built: %s\n", ap_get_server_built());
98 printf("Server's Module Magic Number: %u:%u\n",
99 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
100 #if APR_MAJOR_VERSION >= 2
101 printf("Server loaded: APR %s\n", apr_version_string());
102 printf("Compiled using: APR %s\n", APR_VERSION_STRING);
103 #else
104 printf("Server loaded: APR %s, APR-UTIL %s\n",
105 apr_version_string(), apu_version_string());
106 printf("Compiled using: APR %s, APR-UTIL %s\n",
107 APR_VERSION_STRING, APU_VERSION_STRING);
108 #endif
109 /* sizeof(foo) is long on some platforms so we might as well
110 * make it long everywhere to keep the printf format
111 * consistent
112 */
113 printf("Architecture: %ld-bit\n", 8 * (long)sizeof(void *));
114
115 show_mpm_settings();
116
117 printf("Server compiled with....\n");
118 #ifdef BIG_SECURITY_HOLE
119 printf(" -D BIG_SECURITY_HOLE\n");
120 #endif
121
122 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
123 printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
124 #endif
125
126 #ifdef OS
127 printf(" -D OS=\"" OS "\"\n");
128 #endif
129
130 #ifdef HAVE_SHMGET
131 printf(" -D HAVE_SHMGET\n");
132 #endif
133
134 #if APR_FILE_BASED_SHM
135 printf(" -D APR_FILE_BASED_SHM\n");
136 #endif
137
138 #if APR_HAS_SENDFILE
139 printf(" -D APR_HAS_SENDFILE\n");
140 #endif
141
142 #if APR_HAS_MMAP
143 printf(" -D APR_HAS_MMAP\n");
144 #endif
145
146 #ifdef NO_WRITEV
147 printf(" -D NO_WRITEV\n");
148 #endif
149
150 #ifdef NO_LINGCLOSE
151 printf(" -D NO_LINGCLOSE\n");
152 #endif
153
154 #if APR_HAVE_IPV6
155 printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
156 #ifdef AP_ENABLE_V4_MAPPED
157 printf("enabled)\n");
158 #else
159 printf("disabled)\n");
160 #endif
161 #endif
162
163 #if APR_USE_FLOCK_SERIALIZE
164 printf(" -D APR_USE_FLOCK_SERIALIZE\n");
165 #endif
166
167 #if APR_USE_SYSVSEM_SERIALIZE
168 printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
169 #endif
170
171 #if APR_USE_POSIXSEM_SERIALIZE
172 printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
173 #endif
174
175 #if APR_USE_FCNTL_SERIALIZE
176 printf(" -D APR_USE_FCNTL_SERIALIZE\n");
177 #endif
178
179 #if APR_USE_PROC_PTHREAD_SERIALIZE
180 printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
181 #endif
182
183 #if APR_USE_PTHREAD_SERIALIZE
184 printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
185 #endif
186
187 #if APR_PROCESS_LOCK_IS_GLOBAL
188 printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
189 #endif
190
191 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
192 printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
193 #endif
194
195 #if APR_HAS_OTHER_CHILD
196 printf(" -D APR_HAS_OTHER_CHILD\n");
197 #endif
198
199 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
200 printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
201 #endif
202
203 #ifdef BUFFERED_LOGS
204 printf(" -D BUFFERED_LOGS\n");
205 #ifdef PIPE_BUF
206 printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
207 #endif
208 #endif
209
210 printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
211
212 #if APR_CHARSET_EBCDIC
213 printf(" -D APR_CHARSET_EBCDIC\n");
214 #endif
215
216 #ifdef NEED_HASHBANG_EMUL
217 printf(" -D NEED_HASHBANG_EMUL\n");
218 #endif
219
220 /* This list displays the compiled in default paths: */
221 #ifdef HTTPD_ROOT
222 printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
223 #endif
224
225 #ifdef SUEXEC_BIN
226 printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
227 #endif
228
229 #ifdef DEFAULT_PIDLOG
230 printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
231 #endif
232
233 #ifdef DEFAULT_SCOREBOARD
234 printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
235 #endif
236
237 #ifdef DEFAULT_ERRORLOG
238 printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
239 #endif
240
241 #ifdef AP_TYPES_CONFIG_FILE
242 printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
243 #endif
244
245 #ifdef SERVER_CONFIG_FILE
246 printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
247 #endif
248 }
249
250 #define TASK_SWITCH_SLEEP 10000
251
252 static void destroy_and_exit_process(process_rec *process,
253 int process_exit_value)
254 {
255 /*
256 * Sleep for TASK_SWITCH_SLEEP micro seconds to cause a task switch on
257 * OS layer and thus give possibly started piped loggers a chance to
258 * process their input. Otherwise it is possible that they get killed
259 * by us before they can do so. In this case maybe valueable log messages
260 * might get lost.
261 */
262 apr_sleep(TASK_SWITCH_SLEEP);
263 ap_main_state = AP_SQ_MS_EXITING;
264 apr_pool_destroy(process->pool); /* and destroy all descendent pools */
265 apr_terminate();
266 exit(process_exit_value);
267 }
268
269 /* APR callback invoked if allocation fails. */
270 static int abort_on_oom(int retcode)
271 {
272 ap_abort_on_oom();
273 return retcode; /* unreachable, hopefully. */
274 }
275
276 /* Deregister all hooks when clearing pconf (pre_cleanup).
277 * TODO: have a hook to deregister and run them from here?
278 * ap_clear_auth_internal() is already a candidate.
279 */
280 static apr_status_t deregister_all_hooks(void *unused)
281 {
282 (void)unused;
283 ap_clear_auth_internal();
284 apr_hook_deregister_all();
285 return APR_SUCCESS;
286 }
287
288 static void reset_process_pconf(process_rec *process)
289 {
290 if (process->pconf) {
291 apr_pool_clear(process->pconf);
292 ap_server_conf = NULL;
293 }
294 else {
295 apr_pool_create(&process->pconf, process->pool);
296 apr_pool_tag(process->pconf, "pconf");
297 }
298 apr_pool_pre_cleanup_register(process->pconf, NULL, deregister_all_hooks);
299 }
300
301 static process_rec *init_process(int *argc, const char * const * *argv)
302 {
303 process_rec *process;
304 apr_pool_t *cntx;
305 apr_status_t stat;
306 const char *failed = "apr_app_initialize()";
307
308 stat = apr_app_initialize(argc, argv, NULL);
309 if (stat == APR_SUCCESS) {
310 failed = "apr_pool_create()";
311 stat = apr_pool_create(&cntx, NULL);
312 }
313
314 if (stat != APR_SUCCESS) {
315 /* For all intents and purposes, this is impossibly unlikely,
316 * but APR doesn't exist yet, we can't use it for reporting
317 * these earliest two failures;
318 *
319 * XXX: Note the apr_ctime() and apr_time_now() calls. These
320 * work, today, against an uninitialized APR, but in the future
321 * (if they relied on global pools or mutexes, for example) then
322 * the datestamp logic will need to be replaced.
323 */
324 char ctimebuff[APR_CTIME_LEN];
325 apr_ctime(ctimebuff, apr_time_now());
326 fprintf(stderr, "[%s] [crit] (%d) %s: %s failed "
327 "to initial context, exiting\n",
328 ctimebuff, stat, (*argv)[0], failed);
329 apr_terminate();
330 exit(1);
331 }
332
333 apr_pool_abort_set(abort_on_oom, cntx);
334 apr_pool_tag(cntx, "process");
335 ap_open_stderr_log(cntx);
336
337 /* Now we have initialized apr and our logger, no more
338 * exceptional error reporting required for the lifetime
339 * of this server process.
340 */
341
342 process = apr_palloc(cntx, sizeof(process_rec));
343 process->pool = cntx;
344
345 process->pconf = NULL;
346 reset_process_pconf(process);
347
348 process->argc = *argc;
349 process->argv = *argv;
350 process->short_name = apr_filepath_name_get((*argv)[0]);
351 return process;
352 }
353
354 static void usage(process_rec *process)
355 {
356 const char *bin = process->argv[0];
357 int pad_len = strlen(bin);
358
359 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
360 "Usage: %s [-D name] [-d directory] [-f file]", bin);
361
362 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
363 " %*s [-C \"directive\"] [-c \"directive\"]", pad_len, " ");
364
365 #ifdef WIN32
366 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
367 " %*s [-w] [-k start|restart|stop|shutdown] [-n service_name]",
368 pad_len, " ");
369 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
370 " %*s [-k install|config|uninstall] [-n service_name]",
371 pad_len, " ");
372 #else
373 /* XXX not all MPMs support signalling the server in general or graceful-stop
374 * in particular
375 */
376 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
377 " %*s [-k start|restart|graceful|graceful-stop|stop]",
378 pad_len, " ");
379 #endif
380 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
381 " %*s [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]",
382 pad_len, " ");
383 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
384 "Options:");
385
386 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
387 " -D name : define a name for use in "
388 "<IfDefine name> directives");
389 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
390 " -d directory : specify an alternate initial "
391 "ServerRoot");
392 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
393 " -f file : specify an alternate ServerConfigFile");
394 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
395 " -C \"directive\" : process directive before reading "
396 "config files");
397 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
398 " -c \"directive\" : process directive after reading "
399 "config files");
400
401 #ifdef NETWARE
402 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
403 " -n name : set screen name");
404 #endif
405 #ifdef WIN32
406 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
407 " -n name : set service name and use its "
408 "ServerConfigFile and ServerRoot");
409 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
410 " -k start : tell Apache to start");
411 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
412 " -k restart : tell running Apache to do a graceful "
413 "restart");
414 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
415 " -k stop|shutdown : tell running Apache to shutdown");
416 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
417 " -k install : install an Apache service");
418 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
419 " -k config : change startup Options of an Apache "
420 "service");
421 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
422 " -k uninstall : uninstall an Apache service");
423 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
424 " -w : hold open the console window on error");
425 #endif
426
427 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
428 " -e level : show startup errors of level "
429 "(see LogLevel)");
430 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
431 " -E file : log startup errors to file");
432 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
433 " -v : show version number");
434 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
435 " -V : show compile settings");
436 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
437 " -h : list available command line options "
438 "(this page)");
439 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
440 " -l : list compiled in modules");
441 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
442 " -L : list available configuration "
443 "directives");
444 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
445 " -t -D DUMP_VHOSTS : show parsed vhost settings");
446 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
447 " -t -D DUMP_RUN_CFG : show parsed run settings");
448 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
449 " -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG");
450 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
451 " -t -D DUMP_MODULES : show all loaded modules ");
452 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
453 " -M : a synonym for -t -D DUMP_MODULES");
454 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
455 " -t -D DUMP_INCLUDES: show all included configuration files");
456 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
457 " -t : run syntax check for config files");
458 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
459 " -T : start without DocumentRoot(s) check");
460 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
461 " -X : debug mode (only one worker, do not detach)");
462
463 destroy_and_exit_process(process, 1);
464 }
465
466 int main(int argc, const char * const argv[])
467 {
468 char c;
469 int showcompile = 0, showdirectives = 0;
470 const char *confname = SERVER_CONFIG_FILE;
471 const char *def_server_root = HTTPD_ROOT;
472 const char *temp_error_log = NULL;
473 const char *error;
474 process_rec *process;
475 apr_pool_t *pconf;
476 apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
477 apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
478 apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
479 apr_getopt_t *opt;
480 apr_status_t rv;
481 module **mod;
482 const char *opt_arg;
483 APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
484 int rc = OK;
485
486 AP_MONCONTROL(0); /* turn off profiling of startup */
487
488 process = init_process(&argc, &argv);
489 ap_pglobal = process->pool;
490 pconf = process->pconf;
491 ap_server_argv0 = process->short_name;
492 ap_init_rng(ap_pglobal);
493
494 /* Set up the OOM callback in the global pool, so all pools should
495 * by default inherit it. */
496 apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
497
498 #if APR_CHARSET_EBCDIC
499 if (ap_init_ebcdic(ap_pglobal) != APR_SUCCESS) {
500 destroy_and_exit_process(process, 1);
501 }
502 #endif
503
504 apr_pool_create(&pcommands, ap_pglobal);
505 apr_pool_tag(pcommands, "pcommands");
506 ap_server_pre_read_config = apr_array_make(pcommands, 1,
507 sizeof(const char *));
508 ap_server_post_read_config = apr_array_make(pcommands, 1,
509 sizeof(const char *));
510 ap_server_config_defines = apr_array_make(pcommands, 1,
511 sizeof(const char *));
512
513 error = ap_setup_prelinked_modules(process);
514 if (error) {
515 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, APLOGNO(00012)
516 "%s: %s", ap_server_argv0, error);
517 destroy_and_exit_process(process, 1);
518 }
519
520 ap_run_rewrite_args(process);
521
522 /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
523 * to safely pass on our args from its rewrite_args() handler.
524 */
525 apr_getopt_init(&opt, pcommands, process->argc, process->argv);
526
527 while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &opt_arg))
528 == APR_SUCCESS) {
529 const char **new;
530
531 switch (c) {
532 case 'c':
533 new = (const char **)apr_array_push(ap_server_post_read_config);
534 *new = apr_pstrdup(pcommands, opt_arg);
535 break;
536
537 case 'C':
538 new = (const char **)apr_array_push(ap_server_pre_read_config);
539 *new = apr_pstrdup(pcommands, opt_arg);
540 break;
541
542 case 'd':
543 def_server_root = opt_arg;
544 break;
545
546 case 'D':
547 new = (const char **)apr_array_push(ap_server_config_defines);
548 *new = apr_pstrdup(pcommands, opt_arg);
549 /* Setting -D DUMP_VHOSTS should work like setting -S */
550 if (strcmp(opt_arg, "DUMP_VHOSTS") == 0)
551 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
552 /* Setting -D DUMP_RUN_CFG should work like setting -S */
553 else if (strcmp(opt_arg, "DUMP_RUN_CFG") == 0)
554 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
555 /* Setting -D DUMP_MODULES is equivalent to setting -M */
556 else if (strcmp(opt_arg, "DUMP_MODULES") == 0)
557 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
558 /* Setting -D DUMP_INCLUDES is a type of configuration dump */
559 else if (strcmp(opt_arg, "DUMP_INCLUDES") == 0)
560 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
561 break;
562
563 case 'e':
564 if (ap_parse_log_level(opt_arg, &ap_default_loglevel) != NULL)
565 usage(process);
566 break;
567
568 case 'E':
569 temp_error_log = apr_pstrdup(process->pool, opt_arg);
570 break;
571
572 case 'X':
573 new = (const char **)apr_array_push(ap_server_config_defines);
574 *new = "DEBUG";
575 break;
576
577 case 'f':
578 confname = opt_arg;
579 break;
580
581 case 'v':
582 printf("Server version: %s\n", ap_get_server_description());
583 printf("Server built: %s\n", ap_get_server_built());
584 destroy_and_exit_process(process, 0);
585
586 case 'l':
587 ap_show_modules();
588 destroy_and_exit_process(process, 0);
589
590 case 'L':
591 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
592 showdirectives = 1;
593 break;
594
595 case 't':
596 if (ap_run_mode == AP_SQ_RM_UNKNOWN)
597 ap_run_mode = AP_SQ_RM_CONFIG_TEST;
598 break;
599
600 case 'T':
601 ap_document_root_check = 0;
602 break;
603
604 case 'S':
605 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
606 new = (const char **)apr_array_push(ap_server_config_defines);
607 *new = "DUMP_VHOSTS";
608 new = (const char **)apr_array_push(ap_server_config_defines);
609 *new = "DUMP_RUN_CFG";
610 break;
611
612 case 'M':
613 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
614 new = (const char **)apr_array_push(ap_server_config_defines);
615 *new = "DUMP_MODULES";
616 break;
617
618 case 'V':
619 if (strcmp(ap_show_mpm(), "")) { /* MPM built-in? */
620 show_compile_settings();
621 destroy_and_exit_process(process, 0);
622 }
623 else {
624 showcompile = 1;
625 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
626 }
627 break;
628
629 case 'h':
630 case '?':
631 usage(process);
632 }
633 }
634
635 if (ap_run_mode == AP_SQ_RM_UNKNOWN)
636 ap_run_mode = AP_SQ_RM_NORMAL;
637
638 /* bad cmdline option? then we die */
639 if (rv != APR_EOF || opt->ind < opt->argc) {
640 usage(process);
641 }
642
643 ap_main_state = AP_SQ_MS_CREATE_PRE_CONFIG;
644 apr_pool_create(&plog, ap_pglobal);
645 apr_pool_tag(plog, "plog");
646 apr_pool_create(&ptemp, pconf);
647 apr_pool_tag(ptemp, "ptemp");
648
649 /* Note that we preflight the config file once
650 * before reading it _again_ in the main loop.
651 * This allows things, log files configuration
652 * for example, to settle down.
653 */
654
655 ap_server_root = def_server_root;
656 if (temp_error_log) {
657 ap_replace_stderr_log(process->pool, temp_error_log);
658 }
659 ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
660 if (!ap_server_conf) {
661 if (showcompile) {
662 /* Well, we tried. Show as much as we can, but exit nonzero to
663 * indicate that something's not right. The cause should have
664 * already been logged. */
665 show_compile_settings();
666 }
667 destroy_and_exit_process(process, 1);
668 }
669 apr_pool_cleanup_register(pconf, &ap_server_conf, ap_pool_cleanup_set_null,
670 apr_pool_cleanup_null);
671
672 if (showcompile) { /* deferred due to dynamically loaded MPM */
673 show_compile_settings();
674 destroy_and_exit_process(process, 0);
675 }
676
677 /* sort hooks here to make sure pre_config hooks are sorted properly */
678 apr_hook_sort_all();
679
680 if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
681 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
682 NULL, APLOGNO(00013) "Pre-configuration failed");
683 destroy_and_exit_process(process, 1);
684 }
685
686 rv = ap_process_config_tree(ap_server_conf, ap_conftree,
687 process->pconf, ptemp);
688 if (rv == OK) {
689 ap_fixup_virtual_hosts(pconf, ap_server_conf);
690 ap_fini_vhost_config(pconf, ap_server_conf);
691 /*
692 * Sort hooks again because ap_process_config_tree may have add modules
693 * and hence hooks. This happens with mod_perl and modules written in
694 * perl.
695 */
696 apr_hook_sort_all();
697
698 if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
699 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
700 NULL, APLOGNO(00014) "Configuration check failed");
701 destroy_and_exit_process(process, 1);
702 }
703
704 if (ap_run_mode != AP_SQ_RM_NORMAL) {
705 if (showdirectives) { /* deferred in case of DSOs */
706 ap_show_directives();
707 destroy_and_exit_process(process, 0);
708 }
709 else {
710 ap_run_test_config(pconf, ap_server_conf);
711 if (ap_run_mode == AP_SQ_RM_CONFIG_TEST)
712 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
713 }
714 destroy_and_exit_process(process, 0);
715 }
716 }
717
718 /* If our config failed, deal with that here. */
719 if (rv != OK) {
720 destroy_and_exit_process(process, 1);
721 }
722
723 signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
724 if (signal_server) {
725 int exit_status;
726
727 if (signal_server(&exit_status, pconf) != 0) {
728 destroy_and_exit_process(process, exit_status);
729 }
730 }
731
732 apr_pool_clear(plog);
733
734 if ( ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
735 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
736 0, NULL, APLOGNO(00015) "Unable to open logs");
737 destroy_and_exit_process(process, 1);
738 }
739
740 if ( ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
741 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
742 NULL, APLOGNO(00016) "Configuration Failed");
743 destroy_and_exit_process(process, 1);
744 }
745
746 apr_pool_destroy(ptemp);
747
748 do {
749 ap_main_state = AP_SQ_MS_DESTROY_CONFIG;
750 reset_process_pconf(process);
751
752 ap_main_state = AP_SQ_MS_CREATE_CONFIG;
753 ap_config_generation++;
754 for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
755 ap_register_hooks(*mod, pconf);
756 }
757
758 /* This is a hack until we finish the code so that it only reads
759 * the config file once and just operates on the tree already in
760 * memory. rbb
761 */
762 ap_conftree = NULL;
763 apr_pool_create(&ptemp, pconf);
764 apr_pool_tag(ptemp, "ptemp");
765 ap_server_root = def_server_root;
766 ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
767 if (!ap_server_conf) {
768 destroy_and_exit_process(process, 1);
769 }
770 apr_pool_cleanup_register(pconf, &ap_server_conf,
771 ap_pool_cleanup_set_null, apr_pool_cleanup_null);
772 /* sort hooks here to make sure pre_config hooks are sorted properly */
773 apr_hook_sort_all();
774
775 if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
776 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
777 APLOGNO(00017) "Pre-configuration failed, exiting");
778 destroy_and_exit_process(process, 1);
779 }
780
781 if (ap_process_config_tree(ap_server_conf, ap_conftree, process->pconf,
782 ptemp) != OK) {
783 destroy_and_exit_process(process, 1);
784 }
785 ap_fixup_virtual_hosts(pconf, ap_server_conf);
786 ap_fini_vhost_config(pconf, ap_server_conf);
787 /*
788 * Sort hooks again because ap_process_config_tree may have add modules
789 * and hence hooks. This happens with mod_perl and modules written in
790 * perl.
791 */
792 apr_hook_sort_all();
793
794 if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
795 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
796 APLOGNO(00018) "Configuration check failed, exiting");
797 destroy_and_exit_process(process, 1);
798 }
799
800 apr_pool_clear(plog);
801 if (ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
802 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
803 APLOGNO(00019) "Unable to open logs, exiting");
804 destroy_and_exit_process(process, 1);
805 }
806
807 if (ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
808 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
809 APLOGNO(00020) "Configuration Failed, exiting");
810 destroy_and_exit_process(process, 1);
811 }
812
813 apr_pool_destroy(ptemp);
814 apr_pool_lock(pconf, 1);
815
816 ap_run_optional_fn_retrieve();
817
818 ap_main_state = AP_SQ_MS_RUN_MPM;
819 rc = ap_run_mpm(pconf, plog, ap_server_conf);
820
821 apr_pool_lock(pconf, 0);
822
823 } while (rc == OK);
824
825 if (rc == DONE) {
826 rc = OK;
827 }
828 else if (rc != OK) {
829 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL, APLOGNO(02818)
830 "MPM run failed, exiting");
831 }
832 destroy_and_exit_process(process, rc);
833
834 /* NOTREACHED */
835 return !OK;
836 }
837
838 #ifdef AP_USING_AUTOCONF
839 /* This ugly little hack pulls any function referenced in exports.c into
840 * the web server. exports.c is generated during the build, and it
841 * has all of the APR functions specified by the apr/apr.exports and
842 * apr-util/aprutil.exports files.
843 */
844 const void *ap_suck_in_APR(void);
845 const void *ap_suck_in_APR(void)
846 {
847 extern const void *ap_ugly_hack;
848
849 return ap_ugly_hack;
850 }
851 #endif

Properties

Name Value
svn:eol-style native

infrastructure at apache.org
ViewVC Help
Powered by ViewVC 1.1.26