switch to a 60 bit hash
[httpd-crcsyncproxy.git] / server / main.c
blobf9c8d89f223f8bf64da440d9651a2ffc662de236
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
27 #define APR_WANT_STDIO
28 #define APR_WANT_STRFUNC
29 #include "apr_want.h"
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 "mpm_common.h"
43 #include "ap_expr.h"
45 #if APR_HAVE_UNISTD_H
46 #include <unistd.h>
47 #endif
49 /* WARNING: Win32 binds http_main.c dynamically to the server. Please place
50 * extern functions and global data in another appropriate module.
52 * Most significant main() global data can be found in http_config.c
55 static void show_mpm_settings(void)
57 int mpm_query_info;
58 apr_status_t retval;
60 printf("Server MPM: %s\n", ap_show_mpm());
62 retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
64 if (retval == APR_SUCCESS) {
65 printf(" threaded: ");
67 if (mpm_query_info == AP_MPMQ_DYNAMIC) {
68 printf("yes (variable thread count)\n");
70 else if (mpm_query_info == AP_MPMQ_STATIC) {
71 printf("yes (fixed thread count)\n");
73 else {
74 printf("no\n");
78 retval = ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_query_info);
80 if (retval == APR_SUCCESS) {
81 printf(" forked: ");
83 if (mpm_query_info == AP_MPMQ_DYNAMIC) {
84 printf("yes (variable process count)\n");
86 else if (mpm_query_info == AP_MPMQ_STATIC) {
87 printf("yes (fixed process count)\n");
89 else {
90 printf("no\n");
95 static void show_compile_settings(void)
97 printf("Server version: %s\n", ap_get_server_description());
98 printf("Server built: %s\n", ap_get_server_built());
99 printf("Server's Module Magic Number: %u:%u\n",
100 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
101 printf("Server loaded: APR %s, APR-UTIL %s\n",
102 apr_version_string(), apu_version_string());
103 printf("Compiled using: APR %s, APR-UTIL %s\n",
104 APR_VERSION_STRING, APU_VERSION_STRING);
105 /* sizeof(foo) is long on some platforms so we might as well
106 * make it long everywhere to keep the printf format
107 * consistent
109 printf("Architecture: %ld-bit\n", 8 * (long)sizeof(void *));
111 show_mpm_settings();
113 printf("Server compiled with....\n");
114 #ifdef BIG_SECURITY_HOLE
115 printf(" -D BIG_SECURITY_HOLE\n");
116 #endif
118 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
119 printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
120 #endif
122 #ifdef OS
123 printf(" -D OS=\"" OS "\"\n");
124 #endif
126 #ifdef APACHE_MPM_DIR
127 printf(" -D APACHE_MPM_DIR=\"" APACHE_MPM_DIR "\"\n");
128 #endif
130 #ifdef HAVE_SHMGET
131 printf(" -D HAVE_SHMGET\n");
132 #endif
134 #if APR_FILE_BASED_SHM
135 printf(" -D APR_FILE_BASED_SHM\n");
136 #endif
138 #if APR_HAS_SENDFILE
139 printf(" -D APR_HAS_SENDFILE\n");
140 #endif
142 #if APR_HAS_MMAP
143 printf(" -D APR_HAS_MMAP\n");
144 #endif
146 #ifdef NO_WRITEV
147 printf(" -D NO_WRITEV\n");
148 #endif
150 #ifdef NO_LINGCLOSE
151 printf(" -D NO_LINGCLOSE\n");
152 #endif
154 #if APR_HAVE_IPV6
155 printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
156 #ifdef AP_ENABLE_V4_MAPPED
157 printf("enabled)\n");
158 #else
159 printf("disabled)\n");
160 #endif
161 #endif
163 #if APR_USE_FLOCK_SERIALIZE
164 printf(" -D APR_USE_FLOCK_SERIALIZE\n");
165 #endif
167 #if APR_USE_SYSVSEM_SERIALIZE
168 printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
169 #endif
171 #if APR_USE_POSIXSEM_SERIALIZE
172 printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
173 #endif
175 #if APR_USE_FCNTL_SERIALIZE
176 printf(" -D APR_USE_FCNTL_SERIALIZE\n");
177 #endif
179 #if APR_USE_PROC_PTHREAD_SERIALIZE
180 printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
181 #endif
183 #if APR_USE_PTHREAD_SERIALIZE
184 printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
185 #endif
187 #if APR_PROCESS_LOCK_IS_GLOBAL
188 printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
189 #endif
191 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
192 printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
193 #endif
195 #if APR_HAS_OTHER_CHILD
196 printf(" -D APR_HAS_OTHER_CHILD\n");
197 #endif
199 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
200 printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
201 #endif
203 #ifdef BUFFERED_LOGS
204 printf(" -D BUFFERED_LOGS\n");
205 #ifdef PIPE_BUF
206 printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
207 #endif
208 #endif
210 printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
212 #if APR_CHARSET_EBCDIC
213 printf(" -D APR_CHARSET_EBCDIC\n");
214 #endif
216 #ifdef NEED_HASHBANG_EMUL
217 printf(" -D NEED_HASHBANG_EMUL\n");
218 #endif
220 #ifdef SHARED_CORE
221 printf(" -D SHARED_CORE\n");
222 #endif
224 /* This list displays the compiled in default paths: */
225 #ifdef HTTPD_ROOT
226 printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
227 #endif
229 #ifdef SUEXEC_BIN
230 printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
231 #endif
233 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
234 printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
235 #endif
237 #ifdef DEFAULT_PIDLOG
238 printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
239 #endif
241 #ifdef DEFAULT_SCOREBOARD
242 printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
243 #endif
245 #ifdef DEFAULT_LOCKFILE
246 printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
247 #endif
249 #ifdef DEFAULT_ERRORLOG
250 printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
251 #endif
253 #ifdef AP_TYPES_CONFIG_FILE
254 printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
255 #endif
257 #ifdef SERVER_CONFIG_FILE
258 printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
259 #endif
262 #define TASK_SWITCH_SLEEP 10000
264 static void destroy_and_exit_process(process_rec *process,
265 int process_exit_value)
268 * Sleep for TASK_SWITCH_SLEEP micro seconds to cause a task switch on
269 * OS layer and thus give possibly started piped loggers a chance to
270 * process their input. Otherwise it is possible that they get killed
271 * by us before they can do so. In this case maybe valueable log messages
272 * might get lost.
274 apr_sleep(TASK_SWITCH_SLEEP);
275 apr_pool_destroy(process->pool); /* and destroy all descendent pools */
276 apr_terminate();
277 exit(process_exit_value);
280 #define OOM_MESSAGE "[crit] Memory allocation failed, " \
281 "aborting process." APR_EOL_STR
283 /* APR callback invoked if allocation fails. */
284 static int abort_on_oom(int retcode)
286 write(STDERR_FILENO, OOM_MESSAGE, strlen(OOM_MESSAGE));
287 abort();
288 return retcode; /* unreachable, hopefully. */
291 static process_rec *init_process(int *argc, const char * const * *argv)
293 process_rec *process;
294 apr_pool_t *cntx;
295 apr_status_t stat;
296 const char *failed = "apr_app_initialize()";
298 stat = apr_app_initialize(argc, argv, NULL);
299 if (stat == APR_SUCCESS) {
300 failed = "apr_pool_create()";
301 stat = apr_pool_create(&cntx, NULL);
304 if (stat != APR_SUCCESS) {
305 /* For all intents and purposes, this is impossibly unlikely,
306 * but APR doesn't exist yet, we can't use it for reporting
307 * these earliest two failures;
309 * XXX: Note the apr_ctime() and apr_time_now() calls. These
310 * work, today, against an uninitialized APR, but in the future
311 * (if they relied on global pools or mutexes, for example) then
312 * the datestamp logic will need to be replaced.
314 char ctimebuff[APR_CTIME_LEN];
315 apr_ctime(ctimebuff, apr_time_now());
316 fprintf(stderr, "[%s] [crit] (%d) %s: %s failed "
317 "to initial context, exiting\n",
318 ctimebuff, stat, (*argv)[0], failed);
319 apr_terminate();
320 exit(1);
323 apr_pool_abort_set(abort_on_oom, cntx);
324 apr_pool_tag(cntx, "process");
325 ap_open_stderr_log(cntx);
327 /* Now we have initialized apr and our logger, no more
328 * exceptional error reporting required for the lifetime
329 * of this server process.
332 process = apr_palloc(cntx, sizeof(process_rec));
333 process->pool = cntx;
335 apr_pool_create(&process->pconf, process->pool);
336 apr_pool_tag(process->pconf, "pconf");
337 process->argc = *argc;
338 process->argv = *argv;
339 process->short_name = apr_filepath_name_get((*argv)[0]);
340 return process;
343 static void usage(process_rec *process)
345 const char *bin = process->argv[0];
346 char pad[MAX_STRING_LEN];
347 unsigned i;
349 for (i = 0; i < strlen(bin); i++) {
350 pad[i] = ' ';
353 pad[i] = '\0';
355 #ifdef SHARED_CORE
356 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL ,
357 "Usage: %s [-R directory] [-D name] [-d directory] [-f file]",
358 bin);
359 #else
360 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
361 "Usage: %s [-D name] [-d directory] [-f file]", bin);
362 #endif
364 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
365 " %s [-C \"directive\"] [-c \"directive\"]", pad);
367 #ifdef WIN32
368 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
369 " %s [-w] [-k start|restart|stop|shutdown]", pad);
370 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
371 " %s [-k install|config|uninstall] [-n service_name]",
372 pad);
373 #endif
374 #ifdef AP_MPM_WANT_SIGNAL_SERVER
375 #ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN
376 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
377 " %s [-k start|restart|graceful|graceful-stop|stop]",
378 pad);
379 #else
380 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
381 " %s [-k start|restart|graceful|stop]",
382 pad);
383 #endif /* AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN */
384 #endif
385 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
386 " %s [-v] [-V] [-h] [-l] [-L] [-t] [-S]", pad);
387 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
388 "Options:");
390 #ifdef SHARED_CORE
391 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
392 " -R directory : specify an alternate location for "
393 "shared object files");
394 #endif
396 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
397 " -D name : define a name for use in "
398 "<IfDefine name> directives");
399 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
400 " -d directory : specify an alternate initial "
401 "ServerRoot");
402 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
403 " -f file : specify an alternate ServerConfigFile");
404 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
405 " -C \"directive\" : process directive before reading "
406 "config files");
407 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
408 " -c \"directive\" : process directive after reading "
409 "config files");
411 #ifdef NETWARE
412 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
413 " -n name : set screen name");
414 #endif
415 #ifdef WIN32
416 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
417 " -n name : set service name and use its "
418 "ServerConfigFile");
419 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
420 " -k start : tell Apache to start");
421 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
422 " -k restart : tell running Apache to do a graceful "
423 "restart");
424 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
425 " -k stop|shutdown : tell running Apache to shutdown");
426 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
427 " -k install : install an Apache service");
428 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
429 " -k config : change startup Options of an Apache "
430 "service");
431 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
432 " -k uninstall : uninstall an Apache service");
433 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
434 " -w : hold open the console window on error");
435 #endif
437 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
438 " -e level : show startup errors of level "
439 "(see LogLevel)");
440 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
441 " -E file : log startup errors to file");
442 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
443 " -v : show version number");
444 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
445 " -V : show compile settings");
446 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
447 " -h : list available command line options "
448 "(this page)");
449 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
450 " -l : list compiled in modules");
451 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
452 " -L : list available configuration "
453 "directives");
454 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
455 " -t -D DUMP_VHOSTS : show parsed settings (currently only "
456 "vhost settings)");
457 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
458 " -S : a synonym for -t -D DUMP_VHOSTS");
459 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
460 " -t -D DUMP_MODULES : show all loaded modules ");
461 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
462 " -M : a synonym for -t -D DUMP_MODULES");
463 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
464 " -t : run syntax check for config files");
466 destroy_and_exit_process(process, 1);
469 int main(int argc, const char * const argv[])
471 char c;
472 int configtestonly = 0;
473 const char *confname = SERVER_CONFIG_FILE;
474 const char *def_server_root = HTTPD_ROOT;
475 const char *temp_error_log = NULL;
476 const char *error;
477 process_rec *process;
478 server_rec *server_conf;
479 apr_pool_t *pglobal;
480 apr_pool_t *pconf;
481 apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
482 apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
483 apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
484 apr_getopt_t *opt;
485 apr_status_t rv;
486 module **mod;
487 const char *optarg;
488 APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
490 AP_MONCONTROL(0); /* turn off profiling of startup */
492 process = init_process(&argc, &argv);
493 pglobal = process->pool;
494 pconf = process->pconf;
495 ap_server_argv0 = process->short_name;
497 /* Set up the OOM callback in the global pool, so all pools should
498 * by default inherit it. */
499 apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
501 #if APR_CHARSET_EBCDIC
502 if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
503 destroy_and_exit_process(process, 1);
505 #endif
506 if (ap_expr_init(pglobal) != APR_SUCCESS) {
507 destroy_and_exit_process(process, 1);
510 apr_pool_create(&pcommands, pglobal);
511 apr_pool_tag(pcommands, "pcommands");
512 ap_server_pre_read_config = apr_array_make(pcommands, 1, sizeof(char *));
513 ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
514 ap_server_config_defines = apr_array_make(pcommands, 1, sizeof(char *));
516 error = ap_setup_prelinked_modules(process);
517 if (error) {
518 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, "%s: %s",
519 ap_server_argv0, error);
520 destroy_and_exit_process(process, 1);
523 ap_run_rewrite_args(process);
525 /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
526 * to safely pass on our args from its rewrite_args() handler.
528 apr_getopt_init(&opt, pcommands, process->argc, process->argv);
530 while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg))
531 == APR_SUCCESS) {
532 char **new;
534 switch (c) {
535 case 'c':
536 new = (char **)apr_array_push(ap_server_post_read_config);
537 *new = apr_pstrdup(pcommands, optarg);
538 break;
540 case 'C':
541 new = (char **)apr_array_push(ap_server_pre_read_config);
542 *new = apr_pstrdup(pcommands, optarg);
543 break;
545 case 'd':
546 def_server_root = optarg;
547 break;
549 case 'D':
550 new = (char **)apr_array_push(ap_server_config_defines);
551 *new = apr_pstrdup(pcommands, optarg);
552 /* Setting -D DUMP_VHOSTS is equivalent to setting -S */
553 if (strcmp(optarg, "DUMP_VHOSTS") == 0)
554 configtestonly = 1;
555 /* Setting -D DUMP_MODULES is equivalent to setting -M */
556 if (strcmp(optarg, "DUMP_MODULES") == 0)
557 configtestonly = 1;
558 break;
560 case 'e':
561 if (strcasecmp(optarg, "emerg") == 0) {
562 ap_default_loglevel = APLOG_EMERG;
564 else if (strcasecmp(optarg, "alert") == 0) {
565 ap_default_loglevel = APLOG_ALERT;
567 else if (strcasecmp(optarg, "crit") == 0) {
568 ap_default_loglevel = APLOG_CRIT;
570 else if (strncasecmp(optarg, "err", 3) == 0) {
571 ap_default_loglevel = APLOG_ERR;
573 else if (strncasecmp(optarg, "warn", 4) == 0) {
574 ap_default_loglevel = APLOG_WARNING;
576 else if (strcasecmp(optarg, "notice") == 0) {
577 ap_default_loglevel = APLOG_NOTICE;
579 else if (strcasecmp(optarg, "info") == 0) {
580 ap_default_loglevel = APLOG_INFO;
582 else if (strcasecmp(optarg, "debug") == 0) {
583 ap_default_loglevel = APLOG_DEBUG;
585 else {
586 usage(process);
588 break;
590 case 'E':
591 temp_error_log = apr_pstrdup(process->pool, optarg);
592 break;
594 case 'X':
595 new = (char **)apr_array_push(ap_server_config_defines);
596 *new = "DEBUG";
597 break;
599 case 'f':
600 confname = optarg;
601 break;
603 case 'v':
604 printf("Server version: %s\n", ap_get_server_description());
605 printf("Server built: %s\n", ap_get_server_built());
606 destroy_and_exit_process(process, 0);
608 case 'V':
609 show_compile_settings();
610 destroy_and_exit_process(process, 0);
612 case 'l':
613 ap_show_modules();
614 destroy_and_exit_process(process, 0);
616 case 'L':
617 ap_show_directives();
618 destroy_and_exit_process(process, 0);
620 case 't':
621 configtestonly = 1;
622 break;
624 case 'S':
625 configtestonly = 1;
626 new = (char **)apr_array_push(ap_server_config_defines);
627 *new = "DUMP_VHOSTS";
628 break;
630 case 'M':
631 configtestonly = 1;
632 new = (char **)apr_array_push(ap_server_config_defines);
633 *new = "DUMP_MODULES";
634 break;
636 case 'h':
637 case '?':
638 usage(process);
642 /* bad cmdline option? then we die */
643 if (rv != APR_EOF || opt->ind < opt->argc) {
644 usage(process);
647 apr_pool_create(&plog, pglobal);
648 apr_pool_tag(plog, "plog");
649 apr_pool_create(&ptemp, pconf);
650 apr_pool_tag(ptemp, "ptemp");
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.
658 ap_server_root = def_server_root;
659 if (temp_error_log) {
660 ap_replace_stderr_log(process->pool, temp_error_log);
662 server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
663 if (!server_conf) {
664 destroy_and_exit_process(process, 1);
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);
673 rv = ap_process_config_tree(server_conf, ap_conftree,
674 process->pconf, ptemp);
675 if (rv == OK) {
676 ap_fixup_virtual_hosts(pconf, server_conf);
677 ap_fini_vhost_config(pconf, server_conf);
678 apr_hook_sort_all();
680 if (ap_run_check_config(pconf, plog, ptemp, 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);
686 if (configtestonly) {
687 ap_run_test_config(pconf, server_conf);
688 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
689 destroy_and_exit_process(process, 0);
693 signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
694 if (signal_server) {
695 int exit_status;
697 if (signal_server(&exit_status, pconf) != 0) {
698 destroy_and_exit_process(process, exit_status);
702 /* If our config failed, deal with that here. */
703 if (rv != OK) {
704 destroy_and_exit_process(process, 1);
707 apr_pool_clear(plog);
709 if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
710 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
711 0, NULL, "Unable to open logs");
712 destroy_and_exit_process(process, 1);
715 if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
716 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
717 NULL, "Configuration Failed");
718 destroy_and_exit_process(process, 1);
721 apr_pool_destroy(ptemp);
723 for (;;) {
724 apr_hook_deregister_all();
725 apr_pool_clear(pconf);
726 ap_clear_auth_internal();
728 for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
729 ap_register_hooks(*mod, pconf);
732 /* This is a hack until we finish the code so that it only reads
733 * the config file once and just operates on the tree already in
734 * memory. rbb
736 ap_conftree = NULL;
737 apr_pool_create(&ptemp, pconf);
738 apr_pool_tag(ptemp, "ptemp");
739 ap_server_root = def_server_root;
740 server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
741 if (!server_conf) {
742 destroy_and_exit_process(process, 1);
745 if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
746 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
747 0, NULL, "Pre-configuration failed");
748 destroy_and_exit_process(process, 1);
751 if (ap_process_config_tree(server_conf, ap_conftree, process->pconf,
752 ptemp) != OK) {
753 destroy_and_exit_process(process, 1);
755 ap_fixup_virtual_hosts(pconf, server_conf);
756 ap_fini_vhost_config(pconf, server_conf);
757 apr_hook_sort_all();
759 if (ap_run_check_config(pconf, plog, ptemp, server_conf) != OK) {
760 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
761 NULL, "Configuration check failed");
762 destroy_and_exit_process(process, 1);
765 apr_pool_clear(plog);
766 if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
767 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
768 0, NULL, "Unable to open logs");
769 destroy_and_exit_process(process, 1);
772 if (ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
773 ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
774 0, NULL, "Configuration Failed");
775 destroy_and_exit_process(process, 1);
778 apr_pool_destroy(ptemp);
779 apr_pool_lock(pconf, 1);
781 ap_run_optional_fn_retrieve();
783 if (ap_mpm_run(pconf, plog, server_conf))
784 break;
786 apr_pool_lock(pconf, 0);
789 apr_pool_lock(pconf, 0);
790 destroy_and_exit_process(process, 0);
792 return 0; /* Termination 'ok' */
795 #ifdef AP_USING_AUTOCONF
796 /* This ugly little hack pulls any function referenced in exports.c into
797 * the web server. exports.c is generated during the build, and it
798 * has all of the APR functions specified by the apr/apr.exports and
799 * apr-util/aprutil.exports files.
801 const void *ap_suck_in_APR(void);
802 const void *ap_suck_in_APR(void)
804 extern const void *ap_ugly_hack;
806 return ap_ugly_hack;
808 #endif