]> granicus.if.org Git - apache/blob - server/main.c
* server/main.c (abort_on_oom): New function.
[apache] / server / main.c
1 /* Copyright 1999-2006 The Apache Software Foundation or its licensors, as
2  * applicable.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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_version.h"
24 #include "apu_version.h"
25
26 #define APR_WANT_STDIO
27 #define APR_WANT_STRFUNC
28 #include "apr_want.h"
29
30 #define CORE_PRIVATE
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_vhost.h"
38 #include "apr_uri.h"
39 #include "util_ebcdic.h"
40 #include "ap_mpm.h"
41 #include "mpm_common.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_version());
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     printf("Server loaded:  APR %s, APR-UTIL %s\n",
100            apr_version_string(), apu_version_string());
101     printf("Compiled using: APR %s, APR-UTIL %s\n",
102            APR_VERSION_STRING, APU_VERSION_STRING);
103     /* sizeof(foo) is long on some platforms so we might as well
104      * make it long everywhere to keep the printf format
105      * consistent
106      */
107     printf("Architecture:   %ld-bit\n", 8 * (long)sizeof(void *));
108
109     show_mpm_settings();
110
111     printf("Server compiled with....\n");
112 #ifdef BIG_SECURITY_HOLE
113     printf(" -D BIG_SECURITY_HOLE\n");
114 #endif
115
116 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
117     printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
118 #endif
119
120 #ifdef OS
121     printf(" -D OS=\"" OS "\"\n");
122 #endif
123
124 #ifdef APACHE_MPM_DIR
125     printf(" -D APACHE_MPM_DIR=\"" APACHE_MPM_DIR "\"\n");
126 #endif
127
128 #ifdef HAVE_SHMGET
129     printf(" -D HAVE_SHMGET\n");
130 #endif
131
132 #if APR_FILE_BASED_SHM
133     printf(" -D APR_FILE_BASED_SHM\n");
134 #endif
135
136 #if APR_HAS_SENDFILE
137     printf(" -D APR_HAS_SENDFILE\n");
138 #endif
139
140 #if APR_HAS_MMAP
141     printf(" -D APR_HAS_MMAP\n");
142 #endif
143
144 #ifdef NO_WRITEV
145     printf(" -D NO_WRITEV\n");
146 #endif
147
148 #ifdef NO_LINGCLOSE
149     printf(" -D NO_LINGCLOSE\n");
150 #endif
151
152 #if APR_HAVE_IPV6
153     printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
154 #ifdef AP_ENABLE_V4_MAPPED
155     printf("enabled)\n");
156 #else
157     printf("disabled)\n");
158 #endif
159 #endif
160
161 #if APR_USE_FLOCK_SERIALIZE
162     printf(" -D APR_USE_FLOCK_SERIALIZE\n");
163 #endif
164
165 #if APR_USE_SYSVSEM_SERIALIZE
166     printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
167 #endif
168
169 #if APR_USE_POSIXSEM_SERIALIZE
170     printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
171 #endif
172
173 #if APR_USE_FCNTL_SERIALIZE
174     printf(" -D APR_USE_FCNTL_SERIALIZE\n");
175 #endif
176
177 #if APR_USE_PROC_PTHREAD_SERIALIZE
178     printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
179 #endif
180
181 #if APR_USE_PTHREAD_SERIALIZE
182     printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
183 #endif
184
185 #if APR_PROCESS_LOCK_IS_GLOBAL
186     printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
187 #endif
188
189 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
190     printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
191 #endif
192
193 #if APR_HAS_OTHER_CHILD
194     printf(" -D APR_HAS_OTHER_CHILD\n");
195 #endif
196
197 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
198     printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
199 #endif
200
201 #ifdef BUFFERED_LOGS
202     printf(" -D BUFFERED_LOGS\n");
203 #ifdef PIPE_BUF
204     printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
205 #endif
206 #endif
207
208     printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
209
210 #if APR_CHARSET_EBCDIC
211     printf(" -D APR_CHARSET_EBCDIC\n");
212 #endif
213
214 #ifdef NEED_HASHBANG_EMUL
215     printf(" -D NEED_HASHBANG_EMUL\n");
216 #endif
217
218 #ifdef SHARED_CORE
219     printf(" -D SHARED_CORE\n");
220 #endif
221
222 /* This list displays the compiled in default paths: */
223 #ifdef HTTPD_ROOT
224     printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
225 #endif
226
227 #ifdef SUEXEC_BIN
228     printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
229 #endif
230
231 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
232     printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
233 #endif
234
235 #ifdef DEFAULT_PIDLOG
236     printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
237 #endif
238
239 #ifdef DEFAULT_SCOREBOARD
240     printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
241 #endif
242
243 #ifdef DEFAULT_LOCKFILE
244     printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
245 #endif
246
247 #ifdef DEFAULT_ERRORLOG
248     printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
249 #endif
250
251 #ifdef AP_TYPES_CONFIG_FILE
252     printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
253 #endif
254
255 #ifdef SERVER_CONFIG_FILE
256     printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
257 #endif
258 }
259
260 static void destroy_and_exit_process(process_rec *process,
261                                      int process_exit_value)
262 {
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 *create_process(int argc, const char * const *argv)
280 {
281     process_rec *process;
282     apr_pool_t *cntx;
283     apr_status_t stat;
284
285     stat = apr_pool_create(&cntx, NULL);
286     if (stat != APR_SUCCESS) {
287         /* XXX From the time that we took away the NULL pool->malloc mapping
288          *     we have been unable to log here without segfaulting.
289          */
290         ap_log_error(APLOG_MARK, APLOG_ERR, stat, NULL,
291                      "apr_pool_create() failed to create "
292                      "initial context");
293         apr_terminate();
294         exit(1);
295     }
296
297     apr_pool_abort_set(abort_on_oom, cntx);
298     apr_pool_tag(cntx, "process");
299     ap_open_stderr_log(cntx);
300
301     process = apr_palloc(cntx, sizeof(process_rec));
302     process->pool = cntx;
303
304     apr_pool_create(&process->pconf, process->pool);
305     apr_pool_tag(process->pconf, "pconf");
306     process->argc = argc;
307     process->argv = argv;
308     process->short_name = apr_filepath_name_get(argv[0]);
309     return process;
310 }
311
312 static void usage(process_rec *process)
313 {
314     const char *bin = process->argv[0];
315     char pad[MAX_STRING_LEN];
316     unsigned i;
317
318     for (i = 0; i < strlen(bin); i++) {
319         pad[i] = ' ';
320     }
321
322     pad[i] = '\0';
323
324 #ifdef SHARED_CORE
325     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL ,
326                  "Usage: %s [-R directory] [-D name] [-d directory] [-f file]",
327                  bin);
328 #else
329     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
330                  "Usage: %s [-D name] [-d directory] [-f file]", bin);
331 #endif
332
333     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
334                  "       %s [-C \"directive\"] [-c \"directive\"]", pad);
335
336 #ifdef WIN32
337     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
338                  "       %s [-w] [-k start|restart|stop|shutdown]", pad);
339     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
340                  "       %s [-k install|config|uninstall] [-n service_name]",
341                  pad);
342 #endif
343 #ifdef AP_MPM_WANT_SIGNAL_SERVER
344 #ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN
345     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
346                  "       %s [-k start|restart|graceful|graceful-stop|stop]",
347                  pad);
348 #else
349     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
350                  "       %s [-k start|restart|graceful|stop]",
351                  pad);
352 #endif /* AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN */
353 #endif
354     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
355                  "       %s [-v] [-V] [-h] [-l] [-L] [-t] [-S]", pad);
356     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
357                  "Options:");
358
359 #ifdef SHARED_CORE
360     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
361                  "  -R directory       : specify an alternate location for "
362                  "shared object files");
363 #endif
364
365     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
366                  "  -D name            : define a name for use in "
367                  "<IfDefine name> directives");
368     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
369                  "  -d directory       : specify an alternate initial "
370                  "ServerRoot");
371     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
372                  "  -f file            : specify an alternate ServerConfigFile");
373     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
374                  "  -C \"directive\"     : process directive before reading "
375                  "config files");
376     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
377                  "  -c \"directive\"     : process directive after reading "
378                  "config files");
379
380 #ifdef NETWARE
381     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
382                  "  -n name            : set screen name");
383 #endif
384 #ifdef WIN32
385     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
386                  "  -n name            : set service name and use its "
387                  "ServerConfigFile");
388     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
389                  "  -k start           : tell Apache to start");
390     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
391                  "  -k restart         : tell running Apache to do a graceful "
392                  "restart");
393     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
394                  "  -k stop|shutdown   : tell running Apache to shutdown");
395     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
396                  "  -k install         : install an Apache service");
397     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
398                  "  -k config          : change startup Options of an Apache "
399                  "service");
400     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
401                  "  -k uninstall       : uninstall an Apache service");
402     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
403                  "  -w                 : hold open the console window on error");
404 #endif
405
406     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
407                  "  -e level           : show startup errors of level "
408                  "(see LogLevel)");
409     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
410                  "  -E file            : log startup errors to file");
411     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
412                  "  -v                 : show version number");
413     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
414                  "  -V                 : show compile settings");
415     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
416                  "  -h                 : list available command line options "
417                  "(this page)");
418     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
419                  "  -l                 : list compiled in modules");
420     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
421                  "  -L                 : list available configuration "
422                  "directives");
423     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
424                  "  -t -D DUMP_VHOSTS  : show parsed settings (currently only "
425                  "vhost settings)");
426     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
427                  "  -S                 : a synonym for -t -D DUMP_VHOSTS");
428     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
429                  "  -t -D DUMP_MODULES : show all loaded modules ");
430     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
431                  "  -M                 : a synonym for -t -D DUMP_MODULES");
432     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
433                  "  -t                 : run syntax check for config files");
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 configtestonly = 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     server_rec *server_conf;
448     apr_pool_t *pglobal;
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 *optarg;
457     APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
458
459     AP_MONCONTROL(0); /* turn off profiling of startup */
460
461     apr_app_initialize(&argc, &argv, NULL);
462
463     process = create_process(argc, argv);
464     pglobal = process->pool;
465     pconf = process->pconf;
466     ap_server_argv0 = process->short_name;
467
468     /* Set up the OOM callback in the global pool, so all pools should
469      * by default inherit it. */
470     apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
471
472 #if APR_CHARSET_EBCDIC
473     if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
474         destroy_and_exit_process(process, 1);
475     }
476 #endif
477
478     apr_pool_create(&pcommands, pglobal);
479     apr_pool_tag(pcommands, "pcommands");
480     ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
481     ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
482     ap_server_config_defines   = apr_array_make(pcommands, 1, sizeof(char *));
483
484     error = ap_setup_prelinked_modules(process);
485     if (error) {
486         ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, "%s: %s",
487                      ap_server_argv0, error);
488         destroy_and_exit_process(process, 1);
489     }
490
491     ap_run_rewrite_args(process);
492
493     /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
494      * to safely pass on our args from its rewrite_args() handler.
495      */
496     apr_getopt_init(&opt, pcommands, process->argc, process->argv);
497
498     while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg))
499             == APR_SUCCESS) {
500         char **new;
501
502         switch (c) {
503         case 'c':
504             new = (char **)apr_array_push(ap_server_post_read_config);
505             *new = apr_pstrdup(pcommands, optarg);
506             break;
507
508         case 'C':
509             new = (char **)apr_array_push(ap_server_pre_read_config);
510             *new = apr_pstrdup(pcommands, optarg);
511             break;
512
513         case 'd':
514             def_server_root = optarg;
515             break;
516
517         case 'D':
518             new = (char **)apr_array_push(ap_server_config_defines);
519             *new = apr_pstrdup(pcommands, optarg);
520             /* Setting -D DUMP_VHOSTS is equivalent to setting -S */
521             if (strcmp(optarg, "DUMP_VHOSTS") == 0)
522                 configtestonly = 1;
523             /* Setting -D DUMP_MODULES is equivalent to setting -M */
524             if (strcmp(optarg, "DUMP_MODULES") == 0)
525                 configtestonly = 1;
526             break;
527
528         case 'e':
529             if (strcasecmp(optarg, "emerg") == 0) {
530                 ap_default_loglevel = APLOG_EMERG;
531             }
532             else if (strcasecmp(optarg, "alert") == 0) {
533                 ap_default_loglevel = APLOG_ALERT;
534             }
535             else if (strcasecmp(optarg, "crit") == 0) {
536                 ap_default_loglevel = APLOG_CRIT;
537             }
538             else if (strncasecmp(optarg, "err", 3) == 0) {
539                 ap_default_loglevel = APLOG_ERR;
540             }
541             else if (strncasecmp(optarg, "warn", 4) == 0) {
542                 ap_default_loglevel = APLOG_WARNING;
543             }
544             else if (strcasecmp(optarg, "notice") == 0) {
545                 ap_default_loglevel = APLOG_NOTICE;
546             }
547             else if (strcasecmp(optarg, "info") == 0) {
548                 ap_default_loglevel = APLOG_INFO;
549             }
550             else if (strcasecmp(optarg, "debug") == 0) {
551                 ap_default_loglevel = APLOG_DEBUG;
552             }
553             else {
554                 usage(process);
555             }
556             break;
557
558         case 'E':
559             temp_error_log = apr_pstrdup(process->pool, optarg);
560             break;
561
562         case 'X':
563             new = (char **)apr_array_push(ap_server_config_defines);
564             *new = "DEBUG";
565             break;
566
567         case 'f':
568             confname = optarg;
569             break;
570
571         case 'v':
572             printf("Server version: %s\n", ap_get_server_version());
573             printf("Server built:   %s\n", ap_get_server_built());
574             destroy_and_exit_process(process, 0);
575
576         case 'V':
577             show_compile_settings();
578             destroy_and_exit_process(process, 0);
579
580         case 'l':
581             ap_show_modules();
582             destroy_and_exit_process(process, 0);
583
584         case 'L':
585             ap_show_directives();
586             destroy_and_exit_process(process, 0);
587
588         case 't':
589             configtestonly = 1;
590             break;
591
592         case 'S':
593             configtestonly = 1;
594             new = (char **)apr_array_push(ap_server_config_defines);
595             *new = "DUMP_VHOSTS";
596             break;
597
598         case 'M':
599             configtestonly = 1;
600             new = (char **)apr_array_push(ap_server_config_defines);
601             *new = "DUMP_MODULES";
602             break;
603
604         case 'h':
605         case '?':
606             usage(process);
607         }
608     }
609
610     /* bad cmdline option?  then we die */
611     if (rv != APR_EOF || opt->ind < opt->argc) {
612         usage(process);
613     }
614
615     apr_pool_create(&plog, pglobal);
616     apr_pool_tag(plog, "plog");
617     apr_pool_create(&ptemp, pconf);
618     apr_pool_tag(ptemp, "ptemp");
619
620     /* Note that we preflight the config file once
621      * before reading it _again_ in the main loop.
622      * This allows things, log files configuration
623      * for example, to settle down.
624      */
625
626     ap_server_root = def_server_root;
627     if (temp_error_log) {
628         ap_replace_stderr_log(process->pool, temp_error_log);
629     }
630     server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
631     if (!server_conf) {
632         destroy_and_exit_process(process, 1);
633     }
634
635     if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
636         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
637                      NULL, "Pre-configuration failed");
638         destroy_and_exit_process(process, 1);
639     }
640
641     rv = ap_process_config_tree(server_conf, ap_conftree,
642                                 process->pconf, ptemp);
643     if (rv == OK) {
644         ap_fixup_virtual_hosts(pconf, server_conf);
645         ap_fini_vhost_config(pconf, server_conf);
646         apr_hook_sort_all();
647
648         if (configtestonly) {
649             ap_run_test_config(pconf, server_conf);
650             ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
651             destroy_and_exit_process(process, 0);
652         }
653     }
654
655     signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
656     if (signal_server) {
657         int exit_status;
658
659         if (signal_server(&exit_status, pconf) != 0) {
660             destroy_and_exit_process(process, exit_status);
661         }
662     }
663
664     /* If our config failed, deal with that here. */
665     if (rv != OK) {
666         destroy_and_exit_process(process, 1);
667     }
668
669     apr_pool_clear(plog);
670
671     if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
672         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
673                      0, NULL, "Unable to open logs");
674         destroy_and_exit_process(process, 1);
675     }
676
677     if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
678         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
679                      NULL, "Configuration Failed");
680         destroy_and_exit_process(process, 1);
681     }
682
683     apr_pool_destroy(ptemp);
684
685     for (;;) {
686         apr_hook_deregister_all();
687         apr_pool_clear(pconf);
688
689         for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
690             ap_register_hooks(*mod, pconf);
691         }
692
693         /* This is a hack until we finish the code so that it only reads
694          * the config file once and just operates on the tree already in
695          * memory.  rbb
696          */
697         ap_conftree = NULL;
698         apr_pool_create(&ptemp, pconf);
699         apr_pool_tag(ptemp, "ptemp");
700         ap_server_root = def_server_root;
701         server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
702         if (!server_conf) {
703             destroy_and_exit_process(process, 1);
704         }
705
706         if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
707             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
708                          0, NULL, "Pre-configuration failed");
709             destroy_and_exit_process(process, 1);
710         }
711
712         if (ap_process_config_tree(server_conf, ap_conftree, process->pconf,
713                                    ptemp) != OK) {
714             destroy_and_exit_process(process, 1);
715         }
716         ap_fixup_virtual_hosts(pconf, server_conf);
717         ap_fini_vhost_config(pconf, server_conf);
718         apr_hook_sort_all();
719         apr_pool_clear(plog);
720         if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
721             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
722                          0, NULL, "Unable to open logs");
723             destroy_and_exit_process(process, 1);
724         }
725
726         if (ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
727             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
728                          0, NULL, "Configuration Failed");
729             destroy_and_exit_process(process, 1);
730         }
731
732         apr_pool_destroy(ptemp);
733         apr_pool_lock(pconf, 1);
734
735         ap_run_optional_fn_retrieve();
736
737         if (ap_mpm_run(pconf, plog, server_conf))
738             break;
739
740         apr_pool_lock(pconf, 0);
741     }
742
743     apr_pool_lock(pconf, 0);
744     destroy_and_exit_process(process, 0);
745
746     return 0; /* Termination 'ok' */
747 }
748
749 #ifdef AP_USING_AUTOCONF
750 /* This ugly little hack pulls any function referenced in exports.c into
751  * the web server.  exports.c is generated during the build, and it
752  * has all of the APR functions specified by the apr/apr.exports and
753  * apr-util/aprutil.exports files.
754  */
755 const void *suck_in_APR(void);
756 const void *suck_in_APR(void)
757 {
758     extern const void *ap_ugly_hack;
759
760     return ap_ugly_hack;
761 }
762 #endif