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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "apr_strings.h"
19 #include "apr_getopt.h"
20 #include "apr_general.h"
24 #include "apr_version.h"
25 #include "apu_version.h"
27 #define APR_WANT_STDIO
28 #define APR_WANT_STRFUNC
31 #include "ap_config.h"
33 #include "http_main.h"
35 #include "http_config.h"
36 #include "http_core.h"
38 #include "http_request.h"
39 #include "http_vhost.h"
41 #include "util_ebcdic.h"
47 /* Not sure what absence of unistd would signify for tty. Treating it as a
48 * big NO is safe, as we then won't try to write to stderr that's not a tty.
53 /* we know core's module_index is 0 */
54 #undef APLOG_MODULE_INDEX
55 #define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
57 /* WARNING: Win32 binds http_main.c dynamically to the server. Please place
58 * extern functions and global data in another appropriate module.
60 * Most significant main() global data can be found in http_config.c
63 static void show_mpm_settings(void)
68 printf("Server MPM: %s\n", ap_show_mpm());
70 retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
72 if (retval == APR_SUCCESS) {
73 printf(" threaded: ");
75 if (mpm_query_info == AP_MPMQ_DYNAMIC) {
76 printf("yes (variable thread count)\n");
78 else if (mpm_query_info == AP_MPMQ_STATIC) {
79 printf("yes (fixed thread count)\n");
86 retval = ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_query_info);
88 if (retval == APR_SUCCESS) {
91 if (mpm_query_info == AP_MPMQ_DYNAMIC) {
92 printf("yes (variable process count)\n");
94 else if (mpm_query_info == AP_MPMQ_STATIC) {
95 printf("yes (fixed process count)\n");
103 static void show_compile_settings(void)
105 printf("Server version: %s\n", ap_get_server_description());
106 printf("Server built: %s\n", ap_get_server_built());
107 printf("Server's Module Magic Number: %u:%u\n",
108 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
109 #if APR_MAJOR_VERSION >= 2
110 printf("Server loaded: APR %s, PCRE %s\n",
111 apr_version_string(), ap_pcre_version_string(AP_REG_PCRE_LOADED));
112 printf("Compiled using: APR %s, PCRE %s\n",
113 APR_VERSION_STRING, ap_pcre_version_string(AP_REG_PCRE_COMPILED));
115 printf("Server loaded: APR %s, APR-UTIL %s, PCRE %s\n",
116 apr_version_string(), apu_version_string(),
117 ap_pcre_version_string(AP_REG_PCRE_LOADED));
118 printf("Compiled using: APR %s, APR-UTIL %s, PCRE %s\n",
119 APR_VERSION_STRING, APU_VERSION_STRING,
120 ap_pcre_version_string(AP_REG_PCRE_COMPILED));
122 /* sizeof(foo) is long on some platforms so we might as well
123 * make it long everywhere to keep the printf format
126 printf("Architecture: %ld-bit\n", 8 * (long)sizeof(void *));
130 printf("Server compiled with....\n");
131 #ifdef BIG_SECURITY_HOLE
132 printf(" -D BIG_SECURITY_HOLE\n");
135 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
136 printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
140 printf(" -D OS=\"" OS "\"\n");
144 printf(" -D HAVE_SHMGET\n");
147 #if APR_FILE_BASED_SHM
148 printf(" -D APR_FILE_BASED_SHM\n");
152 printf(" -D APR_HAS_SENDFILE\n");
156 printf(" -D APR_HAS_MMAP\n");
160 printf(" -D NO_WRITEV\n");
164 printf(" -D NO_LINGCLOSE\n");
168 printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
169 #ifdef AP_ENABLE_V4_MAPPED
170 printf("enabled)\n");
172 printf("disabled)\n");
176 #if APR_USE_FLOCK_SERIALIZE
177 printf(" -D APR_USE_FLOCK_SERIALIZE\n");
180 #if APR_USE_SYSVSEM_SERIALIZE
181 printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
184 #if APR_USE_POSIXSEM_SERIALIZE
185 printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
188 #if APR_USE_FCNTL_SERIALIZE
189 printf(" -D APR_USE_FCNTL_SERIALIZE\n");
192 #if APR_USE_PROC_PTHREAD_SERIALIZE
193 printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
196 #if APR_USE_PTHREAD_SERIALIZE
197 printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
200 #if APR_PROCESS_LOCK_IS_GLOBAL
201 printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
204 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
205 printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
208 #if APR_HAS_OTHER_CHILD
209 printf(" -D APR_HAS_OTHER_CHILD\n");
212 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
213 printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
217 printf(" -D BUFFERED_LOGS\n");
219 printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
223 printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
225 #if APR_CHARSET_EBCDIC
226 printf(" -D APR_CHARSET_EBCDIC\n");
229 #ifdef NEED_HASHBANG_EMUL
230 printf(" -D NEED_HASHBANG_EMUL\n");
233 /* This list displays the compiled in default paths: */
235 printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
239 printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
242 #ifdef DEFAULT_PIDLOG
243 printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
246 #ifdef DEFAULT_SCOREBOARD
247 printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
250 #ifdef DEFAULT_ERRORLOG
251 printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
254 #ifdef AP_TYPES_CONFIG_FILE
255 printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
258 #ifdef SERVER_CONFIG_FILE
259 printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
263 #define TASK_SWITCH_SLEEP 10000
265 static void destroy_and_exit_process(process_rec *process,
266 int process_exit_value)
269 * Sleep for TASK_SWITCH_SLEEP micro seconds to cause a task switch on
270 * OS layer and thus give possibly started piped loggers a chance to
271 * process their input. Otherwise it is possible that they get killed
272 * by us before they can do so. In this case maybe valueable log messages
276 /* If we are to print an error, we need the name before we destroy pool.
277 * short_name is a pointer into argv, so remains valid.
279 const char *name = process->short_name ? process->short_name : "httpd";
281 apr_sleep(TASK_SWITCH_SLEEP);
282 ap_main_state = AP_SQ_MS_EXITING;
283 apr_pool_destroy(process->pool); /* and destroy all descendent pools */
285 if ((process_exit_value != 0) && isatty(fileno(stderr))) {
286 fprintf(stderr, "%s: abnormal exit %d\n", name, process_exit_value);
288 exit(process_exit_value);
291 /* APR callback invoked if allocation fails. */
292 static int abort_on_oom(int retcode)
295 return retcode; /* unreachable, hopefully. */
298 static process_rec *init_process(int *argc, const char * const * *argv)
300 process_rec *process;
303 const char *failed = "apr_app_initialize()";
305 stat = apr_app_initialize(argc, argv, NULL);
306 if (stat == APR_SUCCESS) {
307 failed = "apr_pool_create()";
308 stat = apr_pool_create(&cntx, NULL);
311 if (stat != APR_SUCCESS) {
312 /* For all intents and purposes, this is impossibly unlikely,
313 * but APR doesn't exist yet, we can't use it for reporting
314 * these earliest two failures;
316 * XXX: Note the apr_ctime() and apr_time_now() calls. These
317 * work, today, against an uninitialized APR, but in the future
318 * (if they relied on global pools or mutexes, for example) then
319 * the datestamp logic will need to be replaced.
321 char ctimebuff[APR_CTIME_LEN];
322 apr_ctime(ctimebuff, apr_time_now());
323 fprintf(stderr, "[%s] [crit] (%d) %s: %s failed "
324 "to initial context, exiting\n",
325 ctimebuff, stat, (*argv)[0], failed);
330 apr_pool_abort_set(abort_on_oom, cntx);
331 apr_pool_tag(cntx, "process");
332 ap_open_stderr_log(cntx);
334 /* Now we have initialized apr and our logger, no more
335 * exceptional error reporting required for the lifetime
336 * of this server process.
339 process = apr_palloc(cntx, sizeof(process_rec));
340 process->pool = cntx;
342 apr_pool_create(&process->pconf, process->pool);
343 apr_pool_tag(process->pconf, "pconf");
344 process->argc = *argc;
345 process->argv = *argv;
346 process->short_name = apr_filepath_name_get((*argv)[0]);
350 static void usage(process_rec *process)
352 const char *bin = process->argv[0];
353 int pad_len = strlen(bin);
355 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
356 "Usage: %s [-D name] [-d directory] [-f file]", bin);
358 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
359 " %*s [-C \"directive\"] [-c \"directive\"]", pad_len, " ");
362 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
363 " %*s [-w] [-k start|restart|stop|shutdown] [-n service_name]",
365 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
366 " %*s [-k install|config|uninstall] [-n service_name]",
369 /* XXX not all MPMs support signalling the server in general or graceful-stop
372 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
373 " %*s [-k start|restart|graceful|graceful-stop|stop]",
376 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
377 " %*s [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]",
379 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
382 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
383 " -D name : define a name for use in "
384 "<IfDefine name> directives");
385 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
386 " -d directory : specify an alternate initial "
388 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
389 " -f file : specify an alternate ServerConfigFile");
390 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
391 " -C \"directive\" : process directive before reading "
393 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
394 " -c \"directive\" : process directive after reading "
398 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
399 " -n name : set screen name");
402 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
403 " -n name : set service name and use its "
404 "ServerConfigFile and ServerRoot");
405 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
406 " -k start : tell Apache to start");
407 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
408 " -k restart : tell running Apache to do a graceful "
410 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
411 " -k stop|shutdown : tell running Apache to shutdown");
412 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
413 " -k install : install an Apache service");
414 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
415 " -k config : change startup Options of an Apache "
417 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
418 " -k uninstall : uninstall an Apache service");
419 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
420 " -w : hold open the console window on error");
423 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
424 " -e level : show startup errors of level "
426 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
427 " -E file : log startup errors to file");
428 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
429 " -v : show version number");
430 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
431 " -V : show compile settings");
432 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
433 " -h : list available command line options "
435 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
436 " -l : list compiled in modules");
437 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
438 " -L : list available configuration "
440 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
441 " -t -D DUMP_VHOSTS : show parsed vhost settings");
442 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
443 " -t -D DUMP_RUN_CFG : show parsed run settings");
444 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
445 " -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG");
446 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
447 " -t -D DUMP_MODULES : show all loaded modules ");
448 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
449 " -M : a synonym for -t -D DUMP_MODULES");
450 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
451 " -t : run syntax check for config files");
452 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
453 " -T : start without DocumentRoot(s) check");
454 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
455 " -X : debug mode (only one worker, do not detach)");
457 destroy_and_exit_process(process, 1);
460 int main(int argc, const char * const argv[])
463 int showcompile = 0, showdirectives = 0;
464 const char *confname = SERVER_CONFIG_FILE;
465 const char *def_server_root = HTTPD_ROOT;
466 const char *temp_error_log = NULL;
468 process_rec *process;
470 apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
471 apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
472 apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
477 APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
479 AP_MONCONTROL(0); /* turn off profiling of startup */
481 process = init_process(&argc, &argv);
482 ap_pglobal = process->pool;
483 pconf = process->pconf;
484 ap_server_argv0 = process->short_name;
485 ap_init_rng(ap_pglobal);
487 /* Set up the OOM callback in the global pool, so all pools should
488 * by default inherit it. */
489 apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
491 #if APR_CHARSET_EBCDIC
492 if (ap_init_ebcdic(ap_pglobal) != APR_SUCCESS) {
493 destroy_and_exit_process(process, 1);
497 apr_pool_create(&pcommands, ap_pglobal);
498 apr_pool_tag(pcommands, "pcommands");
499 ap_server_pre_read_config = apr_array_make(pcommands, 1, sizeof(char *));
500 ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
501 ap_server_config_defines = apr_array_make(pcommands, 1, sizeof(char *));
503 error = ap_setup_prelinked_modules(process);
505 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, APLOGNO(00012)
506 "%s: %s", ap_server_argv0, error);
507 destroy_and_exit_process(process, 1);
510 ap_run_rewrite_args(process);
512 /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
513 * to safely pass on our args from its rewrite_args() handler.
515 apr_getopt_init(&opt, pcommands, process->argc, process->argv);
517 while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &opt_arg))
523 new = (char **)apr_array_push(ap_server_post_read_config);
524 *new = apr_pstrdup(pcommands, opt_arg);
528 new = (char **)apr_array_push(ap_server_pre_read_config);
529 *new = apr_pstrdup(pcommands, opt_arg);
533 def_server_root = opt_arg;
537 new = (char **)apr_array_push(ap_server_config_defines);
538 *new = apr_pstrdup(pcommands, opt_arg);
539 /* Setting -D DUMP_VHOSTS should work like setting -S */
540 if (strcmp(opt_arg, "DUMP_VHOSTS") == 0)
541 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
542 /* Setting -D DUMP_RUN_CFG should work like setting -S */
543 else if (strcmp(opt_arg, "DUMP_RUN_CFG") == 0)
544 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
545 /* Setting -D DUMP_MODULES is equivalent to setting -M */
546 else if (strcmp(opt_arg, "DUMP_MODULES") == 0)
547 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
551 if (ap_parse_log_level(opt_arg, &ap_default_loglevel) != NULL)
556 temp_error_log = apr_pstrdup(process->pool, opt_arg);
560 new = (char **)apr_array_push(ap_server_config_defines);
569 printf("Server version: %s\n", ap_get_server_description());
570 printf("Server built: %s\n", ap_get_server_built());
571 destroy_and_exit_process(process, 0);
575 destroy_and_exit_process(process, 0);
578 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
583 if (ap_run_mode == AP_SQ_RM_UNKNOWN)
584 ap_run_mode = AP_SQ_RM_CONFIG_TEST;
588 ap_document_root_check = 0;
592 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
593 new = (char **)apr_array_push(ap_server_config_defines);
594 *new = "DUMP_VHOSTS";
595 new = (char **)apr_array_push(ap_server_config_defines);
596 *new = "DUMP_RUN_CFG";
600 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
601 new = (char **)apr_array_push(ap_server_config_defines);
602 *new = "DUMP_MODULES";
606 if (strcmp(ap_show_mpm(), "")) { /* MPM built-in? */
607 show_compile_settings();
608 destroy_and_exit_process(process, 0);
612 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
622 if (ap_run_mode == AP_SQ_RM_UNKNOWN)
623 ap_run_mode = AP_SQ_RM_NORMAL;
625 /* bad cmdline option? then we die */
626 if (rv != APR_EOF || opt->ind < opt->argc) {
630 ap_main_state = AP_SQ_MS_CREATE_PRE_CONFIG;
631 apr_pool_create(&plog, ap_pglobal);
632 apr_pool_tag(plog, "plog");
633 apr_pool_create(&ptemp, pconf);
634 apr_pool_tag(ptemp, "ptemp");
636 /* Note that we preflight the config file once
637 * before reading it _again_ in the main loop.
638 * This allows things, log files configuration
639 * for example, to settle down.
642 ap_server_root = def_server_root;
643 if (temp_error_log) {
644 ap_replace_stderr_log(process->pool, temp_error_log);
646 ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
647 if (!ap_server_conf) {
648 destroy_and_exit_process(process, 1);
650 apr_pool_cleanup_register(pconf, &ap_server_conf, ap_pool_cleanup_set_null,
651 apr_pool_cleanup_null);
652 /* sort hooks here to make sure pre_config hooks are sorted properly */
655 if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
656 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
657 NULL, APLOGNO(00013) "Pre-configuration failed");
658 destroy_and_exit_process(process, 1);
661 rv = ap_process_config_tree(ap_server_conf, ap_conftree,
662 process->pconf, ptemp);
664 ap_fixup_virtual_hosts(pconf, ap_server_conf);
665 ap_fini_vhost_config(pconf, ap_server_conf);
667 * Sort hooks again because ap_process_config_tree may have add modules
668 * and hence hooks. This happens with mod_perl and modules written in
673 if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
674 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
675 NULL, APLOGNO(00014) "Configuration check failed");
676 destroy_and_exit_process(process, 1);
679 if (ap_run_mode != AP_SQ_RM_NORMAL) {
680 if (showcompile) { /* deferred due to dynamically loaded MPM */
681 show_compile_settings();
683 else if (showdirectives) { /* deferred in case of DSOs */
684 ap_show_directives();
685 destroy_and_exit_process(process, 0);
688 ap_run_test_config(pconf, ap_server_conf);
689 if (ap_run_mode == AP_SQ_RM_CONFIG_TEST)
690 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
692 destroy_and_exit_process(process, 0);
696 /* If our config failed, deal with that here. */
698 destroy_and_exit_process(process, 1);
701 signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
705 if (signal_server(&exit_status, pconf) != 0) {
706 destroy_and_exit_process(process, exit_status);
710 apr_pool_clear(plog);
712 if ( ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
713 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
714 0, NULL, APLOGNO(00015) "Unable to open logs");
715 destroy_and_exit_process(process, 1);
718 if ( ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
719 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
720 NULL, APLOGNO(00016) "Configuration Failed");
721 destroy_and_exit_process(process, 1);
724 apr_pool_destroy(ptemp);
727 ap_main_state = AP_SQ_MS_DESTROY_CONFIG;
728 apr_hook_deregister_all();
729 apr_pool_clear(pconf);
730 ap_clear_auth_internal();
732 ap_main_state = AP_SQ_MS_CREATE_CONFIG;
733 ap_config_generation++;
734 for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
735 ap_register_hooks(*mod, pconf);
738 /* This is a hack until we finish the code so that it only reads
739 * the config file once and just operates on the tree already in
743 apr_pool_create(&ptemp, pconf);
744 apr_pool_tag(ptemp, "ptemp");
745 ap_server_root = def_server_root;
746 ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
747 if (!ap_server_conf) {
748 destroy_and_exit_process(process, 1);
750 apr_pool_cleanup_register(pconf, &ap_server_conf,
751 ap_pool_cleanup_set_null, apr_pool_cleanup_null);
752 /* sort hooks here to make sure pre_config hooks are sorted properly */
755 if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
756 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
757 APLOGNO(00017) "Pre-configuration failed, exiting");
758 destroy_and_exit_process(process, 1);
761 if (ap_process_config_tree(ap_server_conf, ap_conftree, process->pconf,
763 destroy_and_exit_process(process, 1);
765 ap_fixup_virtual_hosts(pconf, ap_server_conf);
766 ap_fini_vhost_config(pconf, ap_server_conf);
768 * Sort hooks again because ap_process_config_tree may have add modules
769 * and hence hooks. This happens with mod_perl and modules written in
774 if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
775 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
776 APLOGNO(00018) "Configuration check failed, exiting");
777 destroy_and_exit_process(process, 1);
780 apr_pool_clear(plog);
781 if (ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
782 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
783 APLOGNO(00019) "Unable to open logs, exiting");
784 destroy_and_exit_process(process, 1);
787 if (ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
788 ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
789 APLOGNO(00020) "Configuration Failed, exiting");
790 destroy_and_exit_process(process, 1);
793 apr_pool_destroy(ptemp);
794 apr_pool_lock(pconf, 1);
796 ap_run_optional_fn_retrieve();
798 ap_main_state = AP_SQ_MS_RUN_MPM;
799 if (ap_run_mpm(pconf, plog, ap_server_conf) != OK)
802 apr_pool_lock(pconf, 0);
805 apr_pool_lock(pconf, 0);
806 destroy_and_exit_process(process, 0);
808 return 0; /* Termination 'ok' */
811 #ifdef AP_USING_AUTOCONF
812 /* This ugly little hack pulls any function referenced in exports.c into
813 * the web server. exports.c is generated during the build, and it
814 * has all of the APR functions specified by the apr/apr.exports and
815 * apr-util/aprutil.exports files.
817 const void *ap_suck_in_APR(void);
818 const void *ap_suck_in_APR(void)
820 extern const void *ap_ugly_hack;