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