main.c revision db3fa7db7c7910f2f23c3e3ffe0cf9f41a1899b9
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* ====================================================================
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The Apache Software License, Version 1.1
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Copyright (c) 2000 The Apache Software Foundation. All rights
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * reserved.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Redistribution and use in source and binary forms, with or without
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * modification, are permitted provided that the following conditions
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * are met:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 1. Redistributions of source code must retain the above copyright
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * notice, this list of conditions and the following disclaimer.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 2. Redistributions in binary form must reproduce the above copyright
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * notice, this list of conditions and the following disclaimer in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the documentation and/or other materials provided with the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distribution.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 3. The end-user documentation included with the redistribution,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if any, must include the following acknowledgment:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * "This product includes software developed by the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Apache Software Foundation (http://www.apache.org/)."
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Alternately, this acknowledgment may appear in the software itself,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if and wherever such third-party acknowledgments normally appear.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 4. The names "Apache" and "Apache Software Foundation" must
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * not be used to endorse or promote products derived from this
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * software without prior written permission. For written
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * permission, please contact apache@apache.org.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 5. Products derived from this software may not be called "Apache",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * nor may "Apache" appear in their name, without prior written
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * permission of the Apache Software Foundation.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SUCH DAMAGE.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ====================================================================
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * This software consists of voluntary contributions made by many
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * individuals on behalf of the Apache Software Foundation. For more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * information on the Apache Software Foundation, please see
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Portions of this software are based upon public domain software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * originally written at the National Center for Supercomputing Applications,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * University of Illinois, Urbana-Champaign.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* WARNING: Win32 binds http_main.c dynamically to the server. Please place
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * extern functions and global data in another appropriate module.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Most significant main() global data can be found in http_config.c
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* XXX - We should be able to grab the per-MPM settings here too */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic void show_compile_settings(void)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb printf("Server version: %s\n", ap_get_server_version());
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb printf(" -D MMAP_SEGMENT_SIZE=%ld\n",(long)MMAP_SEGMENT_SIZE);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif /*AP_USE_MMAP_FILES*/
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe/* This list displays the compiled in default paths: */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe printf(" -D DEFAULT_XFERLOG=\"" DEFAULT_XFERLOG "\"\n");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe printf(" -D TYPES_CONFIG_FILE=\"" TYPES_CONFIG_FILE "\"\n");
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic void destroy_and_exit_process(process_rec *process, int process_exit_value)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe apr_destroy_pool(process->pool); /* and destroy all descendent pools */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic process_rec *create_process(int argc, const char * const *argv)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "apr_create_pool() failed to create "
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "initial context");
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe process->short_name = apr_filename_of_pathname(argv[0]);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe unsigned i;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0,NULL , "Usage: %s [-R directory] [-D name] [-d directory] [-f file]", bin);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Usage: %s [-D name] [-d directory] [-f file]", bin);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-C \"directive\"] [-c \"directive\"]", pad);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-k restart|shutdown|start]", pad);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-n service_name]", pad);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-i] [-u]", pad);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-v] [-V] [-h] [-l] [-L] [-t] [-T]", pad);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Options:");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -R directory : specify an alternate location for shared object files");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -D name : define a name for use in <IfDefine name> directives");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -d directory : specify an alternate initial ServerRoot");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -f file : specify an alternate ServerConfigFile");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -C \"directive\" : process directive before reading config files");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -c \"directive\" : process directive after reading config files");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -n name : set service name and use its ServerConfigFile");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k shutdown : tell running Apache to shutdown");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k restart : tell running Apache to do a graceful restart");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k start : tell Apache to start");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -i : install an Apache service");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -u : uninstall an Apache service");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -v : show version number");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -V : show compile settings");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -h : list available command line options (this page)");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -l : list compiled in modules");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -L : list available configuration directives");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings)");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -t : run syntax check for config files (with docroot check)");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -T : run syntax check for config files (without docroot check)");
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* TODOC: -X goes away, expect MPMs to use -D options */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe const char *optarg;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_server_pre_read_config = apr_make_array(pcommands, 1, sizeof(char *));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_server_post_read_config = apr_make_array(pcommands, 1, sizeof(char *));
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_server_config_defines = apr_make_array(pcommands, 1, sizeof(char *));
c2cf53a40a9814eb91db2cdf820f97d943f21628coar /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * to safely pass on our args from its rewrite_args() handler.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_initopt(&opt, pcommands, process->argc, process->argv);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe while (apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg)
c57336f883da78c094fdb20659be5b92a9431b15wrowe switch (c) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe new = (char **)apr_push_array(ap_server_post_read_config);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = (char **)apr_push_array(ap_server_pre_read_config);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = (char **)apr_push_array(ap_server_config_defines);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb printf("Server version: %s\n", ap_get_server_version());
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Note that we preflight the config file once
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe before reading it _again_ in the main loop.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe This allows things, log files configuration
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe for example, to settle down. */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax OK\n");
11fb2f3611e6ff9a541e10b13e3108934f828141gregames for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* This is a hack until we finish the code so that it only reads
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * the config file once and just operates on the tree already in
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * memory. rbb
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return 0; /* Supress compiler warning. */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe/* force Expat to be linked into the server executable */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if defined(USE_EXPAT) && !defined(SHARED_CORE_BOOTSTRAP)
8aefbd756763807188d2e3ce336a8680e4893066wrowe#endif /* USE_EXPAT */
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Force apr_validate_password() into the image so that modules like
8aefbd756763807188d2e3ce336a8680e4893066wrowe * mod_auth can use it even if they're dynamically loaded.
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe/* This ugly little hack pulls any function referenced in exports.c into
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe * the web server. exports.c is generated during the build, and it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * has all of the APR functions specified by the apr/apr.exports and
8aefbd756763807188d2e3ce336a8680e4893066wroweconst void *suck_in_APR(void);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wroweconst void *suck_in_APR(void)
8aa5ca8ff2a4d8e56f62ea3d461e2799136da085trawick extern const void *ap_ugly_hack;