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