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