main.c revision cfd9415521847b2f9394fad04fb701cfb955f503
/* 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
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_getopt.h"
#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"
#include "ap_config.h"
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_config.h"
#include "http_core.h"
#include "mod_core.h"
#include "http_request.h"
#include "http_vhost.h"
#include "apr_uri.h"
#include "util_ebcdic.h"
#include "ap_mpm.h"
#include <unistd.h>
#else
/* Not sure what absence of unistd would signify for tty. Treating it as a
* big NO is safe, as we then won't try to write to stderr that's not a tty.
*/
#define isatty(n) (0)
#endif
/* we know core's module_index is 0 */
/* WARNING: Win32 binds http_main.c dynamically to the server. Please place
* extern functions and global data in another appropriate module.
*
* Most significant main() global data can be found in http_config.c
*/
static void show_mpm_settings(void)
{
int mpm_query_info;
if (retval == APR_SUCCESS) {
printf(" threaded: ");
if (mpm_query_info == AP_MPMQ_DYNAMIC) {
printf("yes (variable thread count)\n");
}
else if (mpm_query_info == AP_MPMQ_STATIC) {
printf("yes (fixed thread count)\n");
}
else {
printf("no\n");
}
}
if (retval == APR_SUCCESS) {
printf(" forked: ");
if (mpm_query_info == AP_MPMQ_DYNAMIC) {
printf("yes (variable process count)\n");
}
else if (mpm_query_info == AP_MPMQ_STATIC) {
printf("yes (fixed process count)\n");
}
else {
printf("no\n");
}
}
}
static void show_compile_settings(void)
{
printf("Server's Module Magic Number: %u:%u\n",
#if APR_MAJOR_VERSION >= 2
printf("Server loaded: APR %s, PCRE %s\n",
printf("Compiled using: APR %s, PCRE %s\n",
#else
printf("Server loaded: APR %s, APR-UTIL %s, PCRE %s\n",
printf("Compiled using: APR %s, APR-UTIL %s, PCRE %s\n",
#endif
/* sizeof(foo) is long on some platforms so we might as well
* make it long everywhere to keep the printf format
* consistent
*/
printf("Server compiled with....\n");
#ifdef BIG_SECURITY_HOLE
printf(" -D BIG_SECURITY_HOLE\n");
#endif
printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
#endif
#ifdef OS
#endif
#ifdef HAVE_SHMGET
printf(" -D HAVE_SHMGET\n");
#endif
printf(" -D APR_FILE_BASED_SHM\n");
#endif
#if APR_HAS_SENDFILE
printf(" -D APR_HAS_SENDFILE\n");
#endif
#if APR_HAS_MMAP
printf(" -D APR_HAS_MMAP\n");
#endif
#ifdef NO_WRITEV
printf(" -D NO_WRITEV\n");
#endif
#ifdef NO_LINGCLOSE
printf(" -D NO_LINGCLOSE\n");
#endif
#if APR_HAVE_IPV6
printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
#ifdef AP_ENABLE_V4_MAPPED
printf("enabled)\n");
#else
printf("disabled)\n");
#endif
#endif
printf(" -D APR_USE_FLOCK_SERIALIZE\n");
#endif
printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
#endif
printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
#endif
printf(" -D APR_USE_FCNTL_SERIALIZE\n");
#endif
printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
#endif
printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
#endif
printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
#endif
printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
#endif
printf(" -D APR_HAS_OTHER_CHILD\n");
#endif
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
#endif
#ifdef BUFFERED_LOGS
printf(" -D BUFFERED_LOGS\n");
#ifdef PIPE_BUF
#endif
#endif
printf(" -D APR_CHARSET_EBCDIC\n");
#endif
#ifdef NEED_HASHBANG_EMUL
printf(" -D NEED_HASHBANG_EMUL\n");
#endif
/* This list displays the compiled in default paths: */
#ifdef HTTPD_ROOT
#endif
#ifdef SUEXEC_BIN
#endif
#ifdef DEFAULT_PIDLOG
#endif
#ifdef DEFAULT_SCOREBOARD
#endif
#ifdef DEFAULT_ERRORLOG
#endif
#ifdef AP_TYPES_CONFIG_FILE
#endif
#ifdef SERVER_CONFIG_FILE
#endif
}
#define TASK_SWITCH_SLEEP 10000
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.
*/
/* If we are to print an error, we need the name before we destroy pool.
* short_name is a pointer into argv, so remains valid.
*/
}
}
/* APR callback invoked if allocation fails. */
static int abort_on_oom(int retcode)
{
return retcode; /* unreachable, hopefully. */
}
{
const char *failed = "apr_app_initialize()";
if (stat == APR_SUCCESS) {
failed = "apr_pool_create()";
}
if (stat != APR_SUCCESS) {
/* 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.
*/
char ctimebuff[APR_CTIME_LEN];
"to initial context, exiting\n",
exit(1);
}
/* Now we have initialized apr and our logger, no more
* exceptional error reporting required for the lifetime
* of this server process.
*/
return process;
}
{
"Usage: %s [-D name] [-d directory] [-f file]", bin);
#ifdef WIN32
" %*s [-w] [-k start|restart|stop|shutdown] [-n service_name]",
pad_len, " ");
" %*s [-k install|config|uninstall] [-n service_name]",
pad_len, " ");
#else
/* XXX not all MPMs support signalling the server in general or graceful-stop
* in particular
*/
" %*s [-k start|restart|graceful|graceful-stop|stop]",
pad_len, " ");
#endif
" %*s [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]",
pad_len, " ");
"Options:");
" -D name : define a name for use in "
"<IfDefine name> directives");
" -d directory : specify an alternate initial "
"ServerRoot");
" -f file : specify an alternate ServerConfigFile");
" -C \"directive\" : process directive before reading "
"config files");
" -c \"directive\" : process directive after reading "
"config files");
#ifdef NETWARE
" -n name : set screen name");
#endif
#ifdef WIN32
" -n name : set service name and use its "
"ServerConfigFile and ServerRoot");
" -k start : tell Apache to start");
" -k restart : tell running Apache to do a graceful "
"restart");
" -k stop|shutdown : tell running Apache to shutdown");
" -k install : install an Apache service");
" -k config : change startup Options of an Apache "
"service");
" -k uninstall : uninstall an Apache service");
" -w : hold open the console window on error");
#endif
" -e level : show startup errors of level "
"(see LogLevel)");
" -E file : log startup errors to file");
" -v : show version number");
" -V : show compile settings");
" -h : list available command line options "
"(this page)");
" -l : list compiled in modules");
" -L : list available configuration "
"directives");
" -t -D DUMP_VHOSTS : show parsed vhost settings");
" -t -D DUMP_RUN_CFG : show parsed run settings");
" -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG");
" -t -D DUMP_MODULES : show all loaded modules ");
" -M : a synonym for -t -D DUMP_MODULES");
" -t : run syntax check for config files");
" -T : start without DocumentRoot(s) check");
" -X : debug mode (only one worker, do not detach)");
}
{
char c;
int showcompile = 0, showdirectives = 0;
const char *confname = SERVER_CONFIG_FILE;
const char *def_server_root = HTTPD_ROOT;
const char *temp_error_log = NULL;
const char *error;
const char *opt_arg;
AP_MONCONTROL(0); /* turn off profiling of startup */
/* Set up the OOM callback in the global pool, so all pools should
* by default inherit it. */
}
#endif
if (error) {
}
/* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
* to safely pass on our args from its rewrite_args() handler.
*/
== APR_SUCCESS) {
char **new;
switch (c) {
case 'c':
break;
case 'C':
break;
case 'd':
break;
case 'D':
/* Setting -D DUMP_VHOSTS should work like setting -S */
/* Setting -D DUMP_RUN_CFG should work like setting -S */
/* Setting -D DUMP_MODULES is equivalent to setting -M */
break;
case 'e':
break;
case 'E':
break;
case 'X':
*new = "DEBUG";
break;
case 'f':
break;
case 'v':
case 'l':
case 'L':
showdirectives = 1;
break;
case 't':
if (ap_run_mode == AP_SQ_RM_UNKNOWN)
break;
case 'T':
break;
case 'S':
*new = "DUMP_VHOSTS";
*new = "DUMP_RUN_CFG";
break;
case 'M':
*new = "DUMP_MODULES";
break;
case 'V':
}
else {
showcompile = 1;
}
break;
case 'h':
case '?':
}
}
if (ap_run_mode == AP_SQ_RM_UNKNOWN)
/* bad cmdline option? then we die */
}
/* Note that we preflight the config file once
* before reading it _again_ in the main loop.
* This allows things, log files configuration
* for example, to settle down.
*/
if (temp_error_log) {
}
if (!ap_server_conf) {
}
/* sort hooks here to make sure pre_config hooks are sorted properly */
}
/*
* Sort hooks again because ap_process_config_tree may have add modules
* and hence hooks. This happens with mod_perl and modules written in
* perl.
*/
}
if (ap_run_mode != AP_SQ_RM_NORMAL) {
if (showcompile) { /* deferred due to dynamically loaded MPM */
}
else if (showdirectives) { /* deferred in case of DSOs */
}
else {
if (ap_run_mode == AP_SQ_RM_CONFIG_TEST)
}
}
}
/* If our config failed, deal with that here. */
}
if (signal_server) {
int exit_status;
}
}
}
}
for (;;) {
}
/* This is a hack until we finish the code so that it only reads
* the config file once and just operates on the tree already in
* memory. rbb
*/
ap_conftree = NULL;
if (!ap_server_conf) {
}
/* sort hooks here to make sure pre_config hooks are sorted properly */
}
}
/*
* Sort hooks again because ap_process_config_tree may have add modules
* and hence hooks. This happens with mod_perl and modules written in
* perl.
*/
}
}
}
break;
apr_pool_lock(pconf, 0);
}
apr_pool_lock(pconf, 0);
return 0; /* Termination 'ok' */
}
#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 *ap_suck_in_APR(void);
const void *ap_suck_in_APR(void)
{
extern const void *ap_ugly_hack;
return ap_ugly_hack;
}
#endif