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