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