]> granicus.if.org Git - apache/blob - server/main.c
Clarify the operation of the SessionCryptoPassphrase directive as raised by rpluem...
[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_request.h"
39 #include "http_vhost.h"
40 #include "apr_uri.h"
41 #include "util_ebcdic.h"
42 #include "ap_mpm.h"
43 #include "mpm_common.h"
44 #include "ap_expr.h"
45
46 #if APR_HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
49
50 /* WARNING: Win32 binds http_main.c dynamically to the server. Please place
51  *          extern functions and global data in another appropriate module.
52  *
53  * Most significant main() global data can be found in http_config.c
54  */
55
56 static void show_mpm_settings(void)
57 {
58     int mpm_query_info;
59     apr_status_t retval;
60
61     printf("Server MPM:     %s\n", ap_show_mpm());
62
63     retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
64
65     if (retval == APR_SUCCESS) {
66         printf("  threaded:     ");
67
68         if (mpm_query_info == AP_MPMQ_DYNAMIC) {
69             printf("yes (variable thread count)\n");
70         }
71         else if (mpm_query_info == AP_MPMQ_STATIC) {
72             printf("yes (fixed thread count)\n");
73         }
74         else {
75             printf("no\n");
76         }
77     }
78
79     retval = ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_query_info);
80
81     if (retval == APR_SUCCESS) {
82         printf("    forked:     ");
83
84         if (mpm_query_info == AP_MPMQ_DYNAMIC) {
85             printf("yes (variable process count)\n");
86         }
87         else if (mpm_query_info == AP_MPMQ_STATIC) {
88             printf("yes (fixed process count)\n");
89         }
90         else {
91             printf("no\n");
92         }
93     }
94 }
95
96 static void show_compile_settings(void)
97 {
98     printf("Server version: %s\n", ap_get_server_description());
99     printf("Server built:   %s\n", ap_get_server_built());
100     printf("Server's Module Magic Number: %u:%u\n",
101            MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
102     printf("Server loaded:  APR %s, APR-UTIL %s\n",
103            apr_version_string(), apu_version_string());
104     printf("Compiled using: APR %s, APR-UTIL %s\n",
105            APR_VERSION_STRING, APU_VERSION_STRING);
106     /* sizeof(foo) is long on some platforms so we might as well
107      * make it long everywhere to keep the printf format
108      * consistent
109      */
110     printf("Architecture:   %ld-bit\n", 8 * (long)sizeof(void *));
111
112     show_mpm_settings();
113
114     printf("Server compiled with....\n");
115 #ifdef BIG_SECURITY_HOLE
116     printf(" -D BIG_SECURITY_HOLE\n");
117 #endif
118
119 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
120     printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
121 #endif
122
123 #ifdef OS
124     printf(" -D OS=\"" OS "\"\n");
125 #endif
126
127 #ifdef APACHE_MPM_DIR
128     printf(" -D APACHE_MPM_DIR=\"" APACHE_MPM_DIR "\"\n");
129 #endif
130
131 #ifdef HAVE_SHMGET
132     printf(" -D HAVE_SHMGET\n");
133 #endif
134
135 #if APR_FILE_BASED_SHM
136     printf(" -D APR_FILE_BASED_SHM\n");
137 #endif
138
139 #if APR_HAS_SENDFILE
140     printf(" -D APR_HAS_SENDFILE\n");
141 #endif
142
143 #if APR_HAS_MMAP
144     printf(" -D APR_HAS_MMAP\n");
145 #endif
146
147 #ifdef NO_WRITEV
148     printf(" -D NO_WRITEV\n");
149 #endif
150
151 #ifdef NO_LINGCLOSE
152     printf(" -D NO_LINGCLOSE\n");
153 #endif
154
155 #if APR_HAVE_IPV6
156     printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
157 #ifdef AP_ENABLE_V4_MAPPED
158     printf("enabled)\n");
159 #else
160     printf("disabled)\n");
161 #endif
162 #endif
163
164 #if APR_USE_FLOCK_SERIALIZE
165     printf(" -D APR_USE_FLOCK_SERIALIZE\n");
166 #endif
167
168 #if APR_USE_SYSVSEM_SERIALIZE
169     printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
170 #endif
171
172 #if APR_USE_POSIXSEM_SERIALIZE
173     printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
174 #endif
175
176 #if APR_USE_FCNTL_SERIALIZE
177     printf(" -D APR_USE_FCNTL_SERIALIZE\n");
178 #endif
179
180 #if APR_USE_PROC_PTHREAD_SERIALIZE
181     printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
182 #endif
183
184 #if APR_USE_PTHREAD_SERIALIZE
185     printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
186 #endif
187
188 #if APR_PROCESS_LOCK_IS_GLOBAL
189     printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
190 #endif
191
192 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
193     printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
194 #endif
195
196 #if APR_HAS_OTHER_CHILD
197     printf(" -D APR_HAS_OTHER_CHILD\n");
198 #endif
199
200 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
201     printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
202 #endif
203
204 #ifdef BUFFERED_LOGS
205     printf(" -D BUFFERED_LOGS\n");
206 #ifdef PIPE_BUF
207     printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
208 #endif
209 #endif
210
211     printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
212
213 #if APR_CHARSET_EBCDIC
214     printf(" -D APR_CHARSET_EBCDIC\n");
215 #endif
216
217 #ifdef NEED_HASHBANG_EMUL
218     printf(" -D NEED_HASHBANG_EMUL\n");
219 #endif
220
221 #ifdef SHARED_CORE
222     printf(" -D SHARED_CORE\n");
223 #endif
224
225 /* This list displays the compiled in default paths: */
226 #ifdef HTTPD_ROOT
227     printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
228 #endif
229
230 #ifdef SUEXEC_BIN
231     printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
232 #endif
233
234 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
235     printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
236 #endif
237
238 #ifdef DEFAULT_PIDLOG
239     printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
240 #endif
241
242 #ifdef DEFAULT_SCOREBOARD
243     printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
244 #endif
245
246 #ifdef DEFAULT_LOCKFILE
247     printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
248 #endif
249
250 #ifdef DEFAULT_ERRORLOG
251     printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
252 #endif
253
254 #ifdef AP_TYPES_CONFIG_FILE
255     printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
256 #endif
257
258 #ifdef SERVER_CONFIG_FILE
259     printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
260 #endif
261 }
262
263 static void destroy_and_exit_process(process_rec *process,
264                                      int process_exit_value)
265 {
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]", pad);
361     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
362                  "       %s [-k install|config|uninstall] [-n service_name]",
363                  pad);
364 #endif
365 #ifdef AP_MPM_WANT_SIGNAL_SERVER
366 #ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN
367     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
368                  "       %s [-k start|restart|graceful|graceful-stop|stop]",
369                  pad);
370 #else
371     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
372                  "       %s [-k start|restart|graceful|stop]",
373                  pad);
374 #endif /* AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN */
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");
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;
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     server_rec *server_conf;
470     apr_pool_t *pglobal;
471     apr_pool_t *pconf;
472     apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
473     apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
474     apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
475     apr_getopt_t *opt;
476     apr_status_t rv;
477     module **mod;
478     const char *optarg;
479     APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
480
481     AP_MONCONTROL(0); /* turn off profiling of startup */
482
483     process = init_process(&argc, &argv);
484     pglobal = process->pool;
485     pconf = process->pconf;
486     ap_server_argv0 = process->short_name;
487
488     /* Set up the OOM callback in the global pool, so all pools should
489      * by default inherit it. */
490     apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
491
492 #if APR_CHARSET_EBCDIC
493     if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
494         destroy_and_exit_process(process, 1);
495     }
496 #endif
497     if (ap_expr_init(pglobal) != APR_SUCCESS) {
498         destroy_and_exit_process(process, 1);
499     }
500
501     apr_pool_create(&pcommands, pglobal);
502     apr_pool_tag(pcommands, "pcommands");
503     ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
504     ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
505     ap_server_config_defines   = apr_array_make(pcommands, 1, sizeof(char *));
506
507     error = ap_setup_prelinked_modules(process);
508     if (error) {
509         ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, "%s: %s",
510                      ap_server_argv0, error);
511         destroy_and_exit_process(process, 1);
512     }
513
514     ap_run_rewrite_args(process);
515
516     /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
517      * to safely pass on our args from its rewrite_args() handler.
518      */
519     apr_getopt_init(&opt, pcommands, process->argc, process->argv);
520
521     while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg))
522             == APR_SUCCESS) {
523         char **new;
524
525         switch (c) {
526         case 'c':
527             new = (char **)apr_array_push(ap_server_post_read_config);
528             *new = apr_pstrdup(pcommands, optarg);
529             break;
530
531         case 'C':
532             new = (char **)apr_array_push(ap_server_pre_read_config);
533             *new = apr_pstrdup(pcommands, optarg);
534             break;
535
536         case 'd':
537             def_server_root = optarg;
538             break;
539
540         case 'D':
541             new = (char **)apr_array_push(ap_server_config_defines);
542             *new = apr_pstrdup(pcommands, optarg);
543             /* Setting -D DUMP_VHOSTS is equivalent to setting -S */
544             if (strcmp(optarg, "DUMP_VHOSTS") == 0)
545                 configtestonly = 1;
546             /* Setting -D DUMP_MODULES is equivalent to setting -M */
547             if (strcmp(optarg, "DUMP_MODULES") == 0)
548                 configtestonly = 1;
549             break;
550
551         case 'e':
552             if (strcasecmp(optarg, "emerg") == 0) {
553                 ap_default_loglevel = APLOG_EMERG;
554             }
555             else if (strcasecmp(optarg, "alert") == 0) {
556                 ap_default_loglevel = APLOG_ALERT;
557             }
558             else if (strcasecmp(optarg, "crit") == 0) {
559                 ap_default_loglevel = APLOG_CRIT;
560             }
561             else if (strncasecmp(optarg, "err", 3) == 0) {
562                 ap_default_loglevel = APLOG_ERR;
563             }
564             else if (strncasecmp(optarg, "warn", 4) == 0) {
565                 ap_default_loglevel = APLOG_WARNING;
566             }
567             else if (strcasecmp(optarg, "notice") == 0) {
568                 ap_default_loglevel = APLOG_NOTICE;
569             }
570             else if (strcasecmp(optarg, "info") == 0) {
571                 ap_default_loglevel = APLOG_INFO;
572             }
573             else if (strcasecmp(optarg, "debug") == 0) {
574                 ap_default_loglevel = APLOG_DEBUG;
575             }
576             else {
577                 usage(process);
578             }
579             break;
580
581         case 'E':
582             temp_error_log = apr_pstrdup(process->pool, optarg);
583             break;
584
585         case 'X':
586             new = (char **)apr_array_push(ap_server_config_defines);
587             *new = "DEBUG";
588             break;
589
590         case 'f':
591             confname = optarg;
592             break;
593
594         case 'v':
595             printf("Server version: %s\n", ap_get_server_description());
596             printf("Server built:   %s\n", ap_get_server_built());
597             destroy_and_exit_process(process, 0);
598
599         case 'V':
600             show_compile_settings();
601             destroy_and_exit_process(process, 0);
602
603         case 'l':
604             ap_show_modules();
605             destroy_and_exit_process(process, 0);
606
607         case 'L':
608             ap_show_directives();
609             destroy_and_exit_process(process, 0);
610
611         case 't':
612             configtestonly = 1;
613             break;
614
615         case 'S':
616             configtestonly = 1;
617             new = (char **)apr_array_push(ap_server_config_defines);
618             *new = "DUMP_VHOSTS";
619             break;
620
621         case 'M':
622             configtestonly = 1;
623             new = (char **)apr_array_push(ap_server_config_defines);
624             *new = "DUMP_MODULES";
625             break;
626
627         case 'h':
628         case '?':
629             usage(process);
630         }
631     }
632
633     /* bad cmdline option?  then we die */
634     if (rv != APR_EOF || opt->ind < opt->argc) {
635         usage(process);
636     }
637
638     apr_pool_create(&plog, pglobal);
639     apr_pool_tag(plog, "plog");
640     apr_pool_create(&ptemp, pconf);
641     apr_pool_tag(ptemp, "ptemp");
642
643     /* Note that we preflight the config file once
644      * before reading it _again_ in the main loop.
645      * This allows things, log files configuration
646      * for example, to settle down.
647      */
648
649     ap_server_root = def_server_root;
650     if (temp_error_log) {
651         ap_replace_stderr_log(process->pool, temp_error_log);
652     }
653     server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
654     if (!server_conf) {
655         destroy_and_exit_process(process, 1);
656     }
657
658     if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
659         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
660                      NULL, "Pre-configuration failed");
661         destroy_and_exit_process(process, 1);
662     }
663
664     rv = ap_process_config_tree(server_conf, ap_conftree,
665                                 process->pconf, ptemp);
666     if (rv == OK) {
667         ap_fixup_virtual_hosts(pconf, server_conf);
668         ap_fini_vhost_config(pconf, server_conf);
669         apr_hook_sort_all();
670
671         if (ap_run_check_config(pconf, plog, ptemp, server_conf) != OK) {
672             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
673                          NULL, "Configuration check failed");
674             destroy_and_exit_process(process, 1);
675         }
676
677         if (configtestonly) {
678             ap_run_test_config(pconf, server_conf);
679             ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
680             destroy_and_exit_process(process, 0);
681         }
682     }
683
684     signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
685     if (signal_server) {
686         int exit_status;
687
688         if (signal_server(&exit_status, pconf) != 0) {
689             destroy_and_exit_process(process, exit_status);
690         }
691     }
692
693     /* If our config failed, deal with that here. */
694     if (rv != OK) {
695         destroy_and_exit_process(process, 1);
696     }
697
698     apr_pool_clear(plog);
699
700     if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
701         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
702                      0, NULL, "Unable to open logs");
703         destroy_and_exit_process(process, 1);
704     }
705
706     if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
707         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
708                      NULL, "Configuration Failed");
709         destroy_and_exit_process(process, 1);
710     }
711
712     apr_pool_destroy(ptemp);
713
714     for (;;) {
715         apr_hook_deregister_all();
716         apr_pool_clear(pconf);
717         ap_clear_auth_internal(server_conf);
718
719         for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
720             ap_register_hooks(*mod, pconf);
721         }
722
723         /* This is a hack until we finish the code so that it only reads
724          * the config file once and just operates on the tree already in
725          * memory.  rbb
726          */
727         ap_conftree = NULL;
728         apr_pool_create(&ptemp, pconf);
729         apr_pool_tag(ptemp, "ptemp");
730         ap_server_root = def_server_root;
731         server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
732         if (!server_conf) {
733             destroy_and_exit_process(process, 1);
734         }
735
736         if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
737             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
738                          0, NULL, "Pre-configuration failed");
739             destroy_and_exit_process(process, 1);
740         }
741
742         if (ap_process_config_tree(server_conf, ap_conftree, process->pconf,
743                                    ptemp) != OK) {
744             destroy_and_exit_process(process, 1);
745         }
746         ap_fixup_virtual_hosts(pconf, server_conf);
747         ap_fini_vhost_config(pconf, server_conf);
748         apr_hook_sort_all();
749
750         if (ap_run_check_config(pconf, plog, ptemp, server_conf) != OK) {
751             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
752                          NULL, "Configuration check failed");
753             destroy_and_exit_process(process, 1);
754         }
755
756         apr_pool_clear(plog);
757         if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
758             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
759                          0, NULL, "Unable to open logs");
760             destroy_and_exit_process(process, 1);
761         }
762
763         if (ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
764             ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
765                          0, NULL, "Configuration Failed");
766             destroy_and_exit_process(process, 1);
767         }
768
769         apr_pool_destroy(ptemp);
770         apr_pool_lock(pconf, 1);
771
772         ap_run_optional_fn_retrieve();
773
774         if (ap_mpm_run(pconf, plog, server_conf))
775             break;
776
777         apr_pool_lock(pconf, 0);
778     }
779
780     apr_pool_lock(pconf, 0);
781     destroy_and_exit_process(process, 0);
782
783     return 0; /* Termination 'ok' */
784 }
785
786 #ifdef AP_USING_AUTOCONF
787 /* This ugly little hack pulls any function referenced in exports.c into
788  * the web server.  exports.c is generated during the build, and it
789  * has all of the APR functions specified by the apr/apr.exports and
790  * apr-util/aprutil.exports files.
791  */
792 const void *suck_in_APR(void);
793 const void *suck_in_APR(void)
794 {
795     extern const void *ap_ugly_hack;
796
797     return ap_ugly_hack;
798 }
799 #endif