]> granicus.if.org Git - apache/blob - server/main.c
Wildcard name-based vhosts printed twice in apachectl -S
[apache] / server / main.c
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 static process_rec *init_process(int *argc, const char * const * *argv)
277 {
278     process_rec *process;
279     apr_pool_t *cntx;
280     apr_status_t stat;
281     const char *failed = "apr_app_initialize()";
282
283     stat = apr_app_initialize(argc, argv, NULL);
284     if (stat == APR_SUCCESS) {
285         failed = "apr_pool_create()";
286         stat = apr_pool_create(&cntx, NULL);
287     }
288
289     if (stat != APR_SUCCESS) {
290         /* For all intents and purposes, this is impossibly unlikely,
291          * but APR doesn't exist yet, we can't use it for reporting
292          * these earliest two failures;
293          *
294          * XXX: Note the apr_ctime() and apr_time_now() calls.  These
295          * work, today, against an uninitialized APR, but in the future
296          * (if they relied on global pools or mutexes, for example) then
297          * the datestamp logic will need to be replaced.
298          */
299         char ctimebuff[APR_CTIME_LEN];
300         apr_ctime(ctimebuff, apr_time_now());
301         fprintf(stderr, "[%s] [crit] (%d) %s: %s failed "
302                         "to initial context, exiting\n",
303                         ctimebuff, stat, (*argv)[0], failed);
304         apr_terminate();
305         exit(1);
306     }
307
308     apr_pool_abort_set(abort_on_oom, cntx);
309     apr_pool_tag(cntx, "process");
310     ap_open_stderr_log(cntx);
311
312     /* Now we have initialized apr and our logger, no more
313      * exceptional error reporting required for the lifetime
314      * of this server process.
315      */
316
317     process = apr_palloc(cntx, sizeof(process_rec));
318     process->pool = cntx;
319
320     apr_pool_create(&process->pconf, process->pool);
321     apr_pool_tag(process->pconf, "pconf");
322     process->argc = *argc;
323     process->argv = *argv;
324     process->short_name = apr_filepath_name_get((*argv)[0]);
325     return process;
326 }
327
328 static void usage(process_rec *process)
329 {
330     const char *bin = process->argv[0];
331     int pad_len = strlen(bin);
332
333     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
334                  "Usage: %s [-D name] [-d directory] [-f file]", bin);
335
336     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
337                  "       %*s [-C \"directive\"] [-c \"directive\"]", pad_len, " ");
338
339 #ifdef WIN32
340     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
341                  "       %*s [-w] [-k start|restart|stop|shutdown] [-n service_name]",
342                  pad_len, " ");
343     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
344                  "       %*s [-k install|config|uninstall] [-n service_name]",
345                  pad_len, " ");
346 #else
347 /* XXX not all MPMs support signalling the server in general or graceful-stop
348  * in particular
349  */
350     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
351                  "       %*s [-k start|restart|graceful|graceful-stop|stop]",
352                  pad_len, " ");
353 #endif
354     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
355                  "       %*s [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]",
356                  pad_len, " ");
357     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
358                  "Options:");
359
360     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
361                  "  -D name            : define a name for use in "
362                  "<IfDefine name> directives");
363     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
364                  "  -d directory       : specify an alternate initial "
365                  "ServerRoot");
366     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
367                  "  -f file            : specify an alternate ServerConfigFile");
368     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
369                  "  -C \"directive\"     : process directive before reading "
370                  "config files");
371     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
372                  "  -c \"directive\"     : process directive after reading "
373                  "config files");
374
375 #ifdef NETWARE
376     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
377                  "  -n name            : set screen name");
378 #endif
379 #ifdef WIN32
380     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
381                  "  -n name            : set service name and use its "
382                  "ServerConfigFile and ServerRoot");
383     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
384                  "  -k start           : tell Apache to start");
385     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
386                  "  -k restart         : tell running Apache to do a graceful "
387                  "restart");
388     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
389                  "  -k stop|shutdown   : tell running Apache to shutdown");
390     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
391                  "  -k install         : install an Apache service");
392     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
393                  "  -k config          : change startup Options of an Apache "
394                  "service");
395     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
396                  "  -k uninstall       : uninstall an Apache service");
397     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
398                  "  -w                 : hold open the console window on error");
399 #endif
400
401     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
402                  "  -e level           : show startup errors of level "
403                  "(see LogLevel)");
404     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
405                  "  -E file            : log startup errors to file");
406     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
407                  "  -v                 : show version number");
408     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
409                  "  -V                 : show compile settings");
410     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
411                  "  -h                 : list available command line options "
412                  "(this page)");
413     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
414                  "  -l                 : list compiled in modules");
415     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
416                  "  -L                 : list available configuration "
417                  "directives");
418     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
419                  "  -t -D DUMP_VHOSTS  : show parsed vhost settings");
420     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
421                  "  -t -D DUMP_RUN_CFG : show parsed run settings");
422     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
423                  "  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG");
424     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
425                  "  -t -D DUMP_MODULES : show all loaded modules ");
426     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
427                  "  -M                 : a synonym for -t -D DUMP_MODULES");
428     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
429                  "  -t                 : run syntax check for config files");
430     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
431                  "  -T                 : start without DocumentRoot(s) check");
432     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
433                  "  -X                 : debug mode (only one worker, do not detach)");
434
435     destroy_and_exit_process(process, 1);
436 }
437
438 int main(int argc, const char * const argv[])
439 {
440     char c;
441     int showcompile = 0, showdirectives = 0;
442     const char *confname = SERVER_CONFIG_FILE;
443     const char *def_server_root = HTTPD_ROOT;
444     const char *temp_error_log = NULL;
445     const char *error;
446     process_rec *process;
447     apr_pool_t *pconf;
448     apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
449     apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
450     apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
451     apr_getopt_t *opt;
452     apr_status_t rv;
453     module **mod;
454     const char *opt_arg;
455     APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
456
457     AP_MONCONTROL(0); /* turn off profiling of startup */
458
459     process = init_process(&argc, &argv);
460     ap_pglobal = process->pool;
461     pconf = process->pconf;
462     ap_server_argv0 = process->short_name;
463     ap_init_rng(ap_pglobal);
464
465     /* Set up the OOM callback in the global pool, so all pools should
466      * by default inherit it. */
467     apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
468
469 #if APR_CHARSET_EBCDIC
470     if (ap_init_ebcdic(ap_pglobal) != APR_SUCCESS) {
471         destroy_and_exit_process(process, 1);
472     }
473 #endif
474
475     apr_pool_create(&pcommands, ap_pglobal);
476     apr_pool_tag(pcommands, "pcommands");
477     ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
478     ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
479     ap_server_config_defines   = apr_array_make(pcommands, 1, sizeof(char *));
480
481     error = ap_setup_prelinked_modules(process);
482     if (error) {
483         ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, APLOGNO(00012)
484                      "%s: %s", ap_server_argv0, error);
485         destroy_and_exit_process(process, 1);
486     }
487
488     ap_run_rewrite_args(process);
489
490     /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
491      * to safely pass on our args from its rewrite_args() handler.
492      */
493     apr_getopt_init(&opt, pcommands, process->argc, process->argv);
494
495     while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &opt_arg))
496             == APR_SUCCESS) {
497         char **new;
498
499         switch (c) {
500         case 'c':
501             new = (char **)apr_array_push(ap_server_post_read_config);
502             *new = apr_pstrdup(pcommands, opt_arg);
503             break;
504
505         case 'C':
506             new = (char **)apr_array_push(ap_server_pre_read_config);
507             *new = apr_pstrdup(pcommands, opt_arg);
508             break;
509
510         case 'd':
511             def_server_root = opt_arg;
512             break;
513
514         case 'D':
515             new = (char **)apr_array_push(ap_server_config_defines);
516             *new = apr_pstrdup(pcommands, opt_arg);
517             /* Setting -D DUMP_VHOSTS should work like setting -S */
518             if (strcmp(opt_arg, "DUMP_VHOSTS") == 0)
519                 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
520             /* Setting -D DUMP_RUN_CFG should work like setting -S */
521             else if (strcmp(opt_arg, "DUMP_RUN_CFG") == 0)
522                 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
523             /* Setting -D DUMP_MODULES is equivalent to setting -M */
524             else if (strcmp(opt_arg, "DUMP_MODULES") == 0)
525                 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
526             break;
527
528         case 'e':
529             if (ap_parse_log_level(opt_arg, &ap_default_loglevel) != NULL)
530                 usage(process);
531             break;
532
533         case 'E':
534             temp_error_log = apr_pstrdup(process->pool, opt_arg);
535             break;
536
537         case 'X':
538             new = (char **)apr_array_push(ap_server_config_defines);
539             *new = "DEBUG";
540             break;
541
542         case 'f':
543             confname = opt_arg;
544             break;
545
546         case 'v':
547             printf("Server version: %s\n", ap_get_server_description());
548             printf("Server built:   %s\n", ap_get_server_built());
549             destroy_and_exit_process(process, 0);
550
551         case 'l':
552             ap_show_modules();
553             destroy_and_exit_process(process, 0);
554
555         case 'L':
556             ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
557             showdirectives = 1;
558             break;
559
560         case 't':
561             if (ap_run_mode == AP_SQ_RM_UNKNOWN)
562                 ap_run_mode = AP_SQ_RM_CONFIG_TEST;
563             break;
564
565        case 'T':
566            ap_document_root_check = 0;
567            break;
568
569         case 'S':
570             ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
571             new = (char **)apr_array_push(ap_server_config_defines);
572             *new = "DUMP_VHOSTS";
573             new = (char **)apr_array_push(ap_server_config_defines);
574             *new = "DUMP_RUN_CFG";
575             break;
576
577         case 'M':
578             ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
579             new = (char **)apr_array_push(ap_server_config_defines);
580             *new = "DUMP_MODULES";
581             break;
582
583         case 'V':
584             if (strcmp(ap_show_mpm(), "")) { /* MPM built-in? */
585                 show_compile_settings();
586                 destroy_and_exit_process(process, 0);
587             }
588             else {
589                 showcompile = 1;
590                 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
591             }
592             break;
593
594         case 'h':
595         case '?':
596             usage(process);
597         }
598     }
599
600     if (ap_run_mode == AP_SQ_RM_UNKNOWN)
601         ap_run_mode = AP_SQ_RM_NORMAL;
602
603     /* bad cmdline option?  then we die */
604     if (rv != APR_EOF || opt->ind < opt->argc) {
605         usage(process);
606     }
607
608     ap_main_state = AP_SQ_MS_CREATE_PRE_CONFIG;
609     apr_pool_create(&plog, ap_pglobal);
610     apr_pool_tag(plog, "plog");
611     apr_pool_create(&ptemp, pconf);
612     apr_pool_tag(ptemp, "ptemp");
613
614     /* Note that we preflight the config file once
615      * before reading it _again_ in the main loop.
616      * This allows things, log files configuration
617      * for example, to settle down.
618      */
619
620     ap_server_root = def_server_root;
621     if (temp_error_log) {
622         ap_replace_stderr_log(process->pool, temp_error_log);
623     }
624     ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
625     if (!ap_server_conf) {
626         destroy_and_exit_process(process, 1);
627     }
628     apr_pool_cleanup_register(pconf, &ap_server_conf, ap_pool_cleanup_set_null,
629                               apr_pool_cleanup_null);
630     /* sort hooks here to make sure pre_config hooks are sorted properly */
631     apr_hook_sort_all();
632
633     if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
634         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
635                      NULL, APLOGNO(00013) "Pre-configuration failed");
636         destroy_and_exit_process(process, 1);
637     }
638
639     rv = ap_process_config_tree(ap_server_conf, ap_conftree,
640                                 process->pconf, ptemp);
641     if (rv == OK) {
642         ap_fixup_virtual_hosts(pconf, ap_server_conf);
643         ap_fini_vhost_config(pconf, ap_server_conf);
644         /*
645          * Sort hooks again because ap_process_config_tree may have add modules
646          * and hence hooks. This happens with mod_perl and modules written in
647          * perl.
648          */
649         apr_hook_sort_all();
650
651         if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
652             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
653                          NULL, APLOGNO(00014) "Configuration check failed");
654             destroy_and_exit_process(process, 1);
655         }
656
657         if (ap_run_mode != AP_SQ_RM_NORMAL) {
658             if (showcompile) { /* deferred due to dynamically loaded MPM */
659                 show_compile_settings();
660             }
661             else if (showdirectives) { /* deferred in case of DSOs */
662                 ap_show_directives();
663                 destroy_and_exit_process(process, 0);
664             }
665             else {
666                 ap_run_test_config(pconf, ap_server_conf);
667                 if (ap_run_mode == AP_SQ_RM_CONFIG_TEST)
668                     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
669             }
670             destroy_and_exit_process(process, 0);
671         }
672     }
673
674     /* If our config failed, deal with that here. */
675     if (rv != OK) {
676         destroy_and_exit_process(process, 1);
677     }
678
679     signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
680     if (signal_server) {
681         int exit_status;
682
683         if (signal_server(&exit_status, pconf) != 0) {
684             destroy_and_exit_process(process, exit_status);
685         }
686     }
687
688     apr_pool_clear(plog);
689
690     if ( ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
691         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
692                      0, NULL, APLOGNO(00015) "Unable to open logs");
693         destroy_and_exit_process(process, 1);
694     }
695
696     if ( ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
697         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
698                      NULL, APLOGNO(00016) "Configuration Failed");
699         destroy_and_exit_process(process, 1);
700     }
701
702     apr_pool_destroy(ptemp);
703
704     for (;;) {
705         ap_main_state = AP_SQ_MS_DESTROY_CONFIG;
706         apr_hook_deregister_all();
707         apr_pool_clear(pconf);
708         ap_clear_auth_internal();
709
710         ap_main_state = AP_SQ_MS_CREATE_CONFIG;
711         ap_config_generation++;
712         for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
713             ap_register_hooks(*mod, pconf);
714         }
715
716         /* This is a hack until we finish the code so that it only reads
717          * the config file once and just operates on the tree already in
718          * memory.  rbb
719          */
720         ap_conftree = NULL;
721         apr_pool_create(&ptemp, pconf);
722         apr_pool_tag(ptemp, "ptemp");
723         ap_server_root = def_server_root;
724         ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
725         if (!ap_server_conf) {
726             destroy_and_exit_process(process, 1);
727         }
728         apr_pool_cleanup_register(pconf, &ap_server_conf,
729                                   ap_pool_cleanup_set_null, apr_pool_cleanup_null);
730         /* sort hooks here to make sure pre_config hooks are sorted properly */
731         apr_hook_sort_all();
732
733         if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
734             ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
735                          APLOGNO(00017) "Pre-configuration failed, exiting");
736             destroy_and_exit_process(process, 1);
737         }
738
739         if (ap_process_config_tree(ap_server_conf, ap_conftree, process->pconf,
740                                    ptemp) != OK) {
741             destroy_and_exit_process(process, 1);
742         }
743         ap_fixup_virtual_hosts(pconf, ap_server_conf);
744         ap_fini_vhost_config(pconf, ap_server_conf);
745         /*
746          * Sort hooks again because ap_process_config_tree may have add modules
747          * and hence hooks. This happens with mod_perl and modules written in
748          * perl.
749          */
750         apr_hook_sort_all();
751
752         if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
753             ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
754                          APLOGNO(00018) "Configuration check failed, exiting");
755             destroy_and_exit_process(process, 1);
756         }
757
758         apr_pool_clear(plog);
759         if (ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
760             ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
761                          APLOGNO(00019) "Unable to open logs, exiting");
762             destroy_and_exit_process(process, 1);
763         }
764
765         if (ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
766             ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL,
767                          APLOGNO(00020) "Configuration Failed, exiting");
768             destroy_and_exit_process(process, 1);
769         }
770
771         apr_pool_destroy(ptemp);
772         apr_pool_lock(pconf, 1);
773
774         ap_run_optional_fn_retrieve();
775
776         ap_main_state = AP_SQ_MS_RUN_MPM;
777         if (ap_run_mpm(pconf, plog, ap_server_conf) != OK)
778             break;
779
780         apr_pool_lock(pconf, 0);
781     }
782
783     apr_pool_lock(pconf, 0);
784     destroy_and_exit_process(process, 0);
785
786     return 0; /* Termination 'ok' */
787 }
788
789 #ifdef AP_USING_AUTOCONF
790 /* This ugly little hack pulls any function referenced in exports.c into
791  * the web server.  exports.c is generated during the build, and it
792  * has all of the APR functions specified by the apr/apr.exports and
793  * apr-util/aprutil.exports files.
794  */
795 const void *ap_suck_in_APR(void);
796 const void *ap_suck_in_APR(void)
797 {
798     extern const void *ap_ugly_hack;
799
800     return ap_ugly_hack;
801 }
802 #endif