-/* Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_md5.h"
+#include "apr_time.h"
+#include "apr_version.h"
+#include "apu_version.h"
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include "apr_want.h"
-#define CORE_PRIVATE
#include "ap_config.h"
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_config.h"
#include "http_core.h"
+#include "http_request.h"
#include "http_vhost.h"
#include "apr_uri.h"
#include "util_ebcdic.h"
#include "ap_mpm.h"
#include "mpm_common.h"
+#include "ap_expr.h"
-#include "mod_so.h" /* for dumping loaded modules */
+#if APR_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
/* WARNING: Win32 binds http_main.c dynamically to the server. Please place
* extern functions and global data in another appropriate module.
static void show_compile_settings(void)
{
- printf("Server version: %s\n", ap_get_server_version());
+ printf("Server version: %s\n", ap_get_server_description());
printf("Server built: %s\n", ap_get_server_built());
printf("Server's Module Magic Number: %u:%u\n",
MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
-
+ printf("Server loaded: APR %s, APR-UTIL %s\n",
+ apr_version_string(), apu_version_string());
+ printf("Compiled using: APR %s, APR-UTIL %s\n",
+ APR_VERSION_STRING, APU_VERSION_STRING);
/* sizeof(foo) is long on some platforms so we might as well
* make it long everywhere to keep the printf format
* consistent
#endif
#endif
+ printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
+
#if APR_CHARSET_EBCDIC
printf(" -D APR_CHARSET_EBCDIC\n");
#endif
#endif
}
+#define TASK_SWITCH_SLEEP 10000
+
static void destroy_and_exit_process(process_rec *process,
int process_exit_value)
{
+ /*
+ * Sleep for TASK_SWITCH_SLEEP micro seconds to cause a task switch on
+ * OS layer and thus give possibly started piped loggers a chance to
+ * process their input. Otherwise it is possible that they get killed
+ * by us before they can do so. In this case maybe valueable log messages
+ * might get lost.
+ */
+ apr_sleep(TASK_SWITCH_SLEEP);
apr_pool_destroy(process->pool); /* and destroy all descendent pools */
apr_terminate();
exit(process_exit_value);
}
-static process_rec *create_process(int argc, const char * const *argv)
+#define OOM_MESSAGE "[crit] Memory allocation failed, " \
+ "aborting process." APR_EOL_STR
+
+/* APR callback invoked if allocation fails. */
+static int abort_on_oom(int retcode)
+{
+ write(STDERR_FILENO, OOM_MESSAGE, strlen(OOM_MESSAGE));
+ abort();
+ return retcode; /* unreachable, hopefully. */
+}
+
+static process_rec *init_process(int *argc, const char * const * *argv)
{
process_rec *process;
apr_pool_t *cntx;
apr_status_t stat;
+ const char *failed = "apr_app_initialize()";
+
+ stat = apr_app_initialize(argc, argv, NULL);
+ if (stat == APR_SUCCESS) {
+ failed = "apr_pool_create()";
+ stat = apr_pool_create(&cntx, NULL);
+ }
- stat = apr_pool_create(&cntx, NULL);
if (stat != APR_SUCCESS) {
- /* XXX From the time that we took away the NULL pool->malloc mapping
- * we have been unable to log here without segfaulting.
+ /* For all intents and purposes, this is impossibly unlikely,
+ * but APR doesn't exist yet, we can't use it for reporting
+ * these earliest two failures;
+ *
+ * XXX: Note the apr_ctime() and apr_time_now() calls. These
+ * work, today, against an uninitialized APR, but in the future
+ * (if they relied on global pools or mutexes, for example) then
+ * the datestamp logic will need to be replaced.
*/
- ap_log_error(APLOG_MARK, APLOG_ERR, stat, NULL,
- "apr_pool_create() failed to create "
- "initial context");
+ char ctimebuff[APR_CTIME_LEN];
+ apr_ctime(ctimebuff, apr_time_now());
+ fprintf(stderr, "[%s] [crit] (%d) %s: %s failed "
+ "to initial context, exiting\n",
+ ctimebuff, stat, (*argv)[0], failed);
apr_terminate();
exit(1);
}
+ apr_pool_abort_set(abort_on_oom, cntx);
apr_pool_tag(cntx, "process");
ap_open_stderr_log(cntx);
+ /* Now we have initialized apr and our logger, no more
+ * exceptional error reporting required for the lifetime
+ * of this server process.
+ */
+
process = apr_palloc(cntx, sizeof(process_rec));
process->pool = cntx;
apr_pool_create(&process->pconf, process->pool);
apr_pool_tag(process->pconf, "pconf");
- process->argc = argc;
- process->argv = argv;
- process->short_name = apr_filepath_name_get(argv[0]);
+ process->argc = *argc;
+ process->argv = *argv;
+ process->short_name = apr_filepath_name_get((*argv)[0]);
return process;
}
" %s [-k install|config|uninstall] [-n service_name]",
pad);
#endif
-#ifdef AP_MPM_WANT_SIGNAL_SERVER
+/* XXX not all MPMs support signalling the server in general or graceful-stop
+ * in particular
+ */
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
- " %s [-k start|restart|graceful|stop]",
+ " %s [-k start|restart|graceful|graceful-stop|stop]",
pad);
-#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
" %s [-v] [-V] [-h] [-l] [-L] [-t] [-S]", pad);
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
" -t -D DUMP_VHOSTS : show parsed settings (currently only "
"vhost settings)");
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
- " -S : a synonym for -t -D DUMP_VHOSTS");
+ " -S : a synonym for -t -D DUMP_VHOSTS");
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
" -t -D DUMP_MODULES : show all loaded modules ");
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
- " -M : a synonym for -t -D DUMP_MODULES");
+ " -M : a synonym for -t -D DUMP_MODULES");
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
" -t : run syntax check for config files");
int main(int argc, const char * const argv[])
{
char c;
- int configtestonly = 0;
+ int configtestonly = 0, showcompile = 0;
const char *confname = SERVER_CONFIG_FILE;
const char *def_server_root = HTTPD_ROOT;
const char *temp_error_log = NULL;
const char *error;
process_rec *process;
- server_rec *server_conf;
- apr_pool_t *pglobal;
apr_pool_t *pconf;
apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
AP_MONCONTROL(0); /* turn off profiling of startup */
- apr_app_initialize(&argc, &argv, NULL);
-
- process = create_process(argc, argv);
- pglobal = process->pool;
+ process = init_process(&argc, &argv);
+ ap_pglobal = process->pool;
pconf = process->pconf;
ap_server_argv0 = process->short_name;
+ /* Set up the OOM callback in the global pool, so all pools should
+ * by default inherit it. */
+ apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
+
#if APR_CHARSET_EBCDIC
- if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
+ if (ap_init_ebcdic(ap_pglobal) != APR_SUCCESS) {
destroy_and_exit_process(process, 1);
}
#endif
+ if (ap_expr_init(ap_pglobal) != APR_SUCCESS) {
+ destroy_and_exit_process(process, 1);
+ }
- apr_pool_create(&pcommands, pglobal);
+ apr_pool_create(&pcommands, ap_pglobal);
apr_pool_tag(pcommands, "pcommands");
ap_server_pre_read_config = apr_array_make(pcommands, 1, sizeof(char *));
ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
break;
case 'v':
- printf("Server version: %s\n", ap_get_server_version());
+ printf("Server version: %s\n", ap_get_server_description());
printf("Server built: %s\n", ap_get_server_built());
destroy_and_exit_process(process, 0);
case 'V':
- show_compile_settings();
- destroy_and_exit_process(process, 0);
+ if (strcmp(ap_show_mpm(), "")) { /* MPM built-in? */
+ show_compile_settings();
+ destroy_and_exit_process(process, 0);
+ }
+ else {
+ showcompile = 1;
+ }
+ break;
case 'l':
ap_show_modules();
case 't':
configtestonly = 1;
break;
-
+
case 'S':
configtestonly = 1;
new = (char **)apr_array_push(ap_server_config_defines);
new = (char **)apr_array_push(ap_server_config_defines);
*new = "DUMP_MODULES";
break;
-
+
case 'h':
case '?':
usage(process);
usage(process);
}
- apr_pool_create(&plog, pglobal);
+ apr_pool_create(&plog, ap_pglobal);
apr_pool_tag(plog, "plog");
apr_pool_create(&ptemp, pconf);
apr_pool_tag(ptemp, "ptemp");
if (temp_error_log) {
ap_replace_stderr_log(process->pool, temp_error_log);
}
- server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
- if (!server_conf) {
+ ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
+ if (!ap_server_conf) {
destroy_and_exit_process(process, 1);
}
destroy_and_exit_process(process, 1);
}
- rv = ap_process_config_tree(server_conf, ap_conftree,
+ rv = ap_process_config_tree(ap_server_conf, ap_conftree,
process->pconf, ptemp);
if (rv == OK) {
- APR_OPTIONAL_FN_TYPE(ap_dump_loaded_modules) *dump_modules =
- APR_RETRIEVE_OPTIONAL_FN(ap_dump_loaded_modules);
-
- ap_fixup_virtual_hosts(pconf, server_conf);
- ap_fini_vhost_config(pconf, server_conf);
+ ap_fixup_virtual_hosts(pconf, ap_server_conf);
+ ap_fini_vhost_config(pconf, ap_server_conf);
apr_hook_sort_all();
- if (dump_modules && ap_exists_config_define("DUMP_MODULES")) {
- dump_modules(pconf, server_conf);
+ if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
+ ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
+ NULL, "Configuration check failed");
+ destroy_and_exit_process(process, 1);
}
if (configtestonly) {
+ ap_run_test_config(pconf, ap_server_conf);
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
destroy_and_exit_process(process, 0);
}
+ else if (showcompile) { /* deferred due to dynamically loaded MPM */
+ show_compile_settings();
+ destroy_and_exit_process(process, 0);
+ }
}
signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
apr_pool_clear(plog);
- if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
+ if ( ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
0, NULL, "Unable to open logs");
destroy_and_exit_process(process, 1);
}
- if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
+ if ( ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
NULL, "Configuration Failed");
destroy_and_exit_process(process, 1);
for (;;) {
apr_hook_deregister_all();
apr_pool_clear(pconf);
+ ap_clear_auth_internal();
for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
ap_register_hooks(*mod, pconf);
apr_pool_create(&ptemp, pconf);
apr_pool_tag(ptemp, "ptemp");
ap_server_root = def_server_root;
- server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
- if (!server_conf) {
+ ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
+ if (!ap_server_conf) {
destroy_and_exit_process(process, 1);
}
destroy_and_exit_process(process, 1);
}
- if (ap_process_config_tree(server_conf, ap_conftree, process->pconf,
+ if (ap_process_config_tree(ap_server_conf, ap_conftree, process->pconf,
ptemp) != OK) {
destroy_and_exit_process(process, 1);
}
- ap_fixup_virtual_hosts(pconf, server_conf);
- ap_fini_vhost_config(pconf, server_conf);
+ ap_fixup_virtual_hosts(pconf, ap_server_conf);
+ ap_fini_vhost_config(pconf, ap_server_conf);
apr_hook_sort_all();
+
+ if (ap_run_check_config(pconf, plog, ptemp, ap_server_conf) != OK) {
+ ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
+ NULL, "Configuration check failed");
+ destroy_and_exit_process(process, 1);
+ }
+
apr_pool_clear(plog);
- if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
+ if (ap_run_open_logs(pconf, plog, ptemp, ap_server_conf) != OK) {
ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
0, NULL, "Unable to open logs");
destroy_and_exit_process(process, 1);
}
- if (ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
+ if (ap_run_post_config(pconf, plog, ptemp, ap_server_conf) != OK) {
ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
0, NULL, "Configuration Failed");
destroy_and_exit_process(process, 1);
ap_run_optional_fn_retrieve();
- if (ap_mpm_run(pconf, plog, server_conf))
+ if (ap_mpm_run(pconf, plog, ap_server_conf))
break;
apr_pool_lock(pconf, 0);
return 0; /* Termination 'ok' */
}
-#ifndef SHARED_CORE_BOOTSTRAP
-/*
- * Force apr_password_validate() into the image so that modules like
- * mod_auth can use it even if they're dynamically loaded.
- */
-void suck_in_apr_password_validate(void);
-void suck_in_apr_password_validate(void)
-{
- apr_password_validate("a", "b");
-}
-#endif
-
#ifdef AP_USING_AUTOCONF
/* This ugly little hack pulls any function referenced in exports.c into
* the web server. exports.c is generated during the build, and it
* has all of the APR functions specified by the apr/apr.exports and
* apr-util/aprutil.exports files.
*/
-const void *suck_in_APR(void);
-const void *suck_in_APR(void)
+const void *ap_suck_in_APR(void);
+const void *ap_suck_in_APR(void)
{
extern const void *ap_ugly_hack;