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