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