]> granicus.if.org Git - apache/blobdiff - server/main.c
Fix default Timeout & KeepaliveTimeout. Still need to limit directive
[apache] / server / main.c
index 493a7c79c4d45446c34439ccd7359638f1543f2d..47df11db6eadfbc5f404ce6a182b65286dc6131b 100644 (file)
@@ -1,59 +1,60 @@
 /* ====================================================================
- * Copyright (c) 1995-2000 The Apache Software Foundation.  All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following conditions 
- * are met: 
- * 
- * 1. Redistributions of source code must retain the above copyright 
- *    notice, this list of conditions and the following disclaimer.  
- * 
- * 2. Redistributions in binary form must reproduce the above copyright 
- *    notice, this list of conditions and the following disclaimer in 
- *    the documentation and/or other materials provided with the 
- *    distribution. 
- * 
- * 3. All advertising materials mentioning features or use of this 
- *    software must display the following acknowledgment: 
- *    "This product includes software developed by the Apache Software Foundation 
- *    for use in the Apache HTTP server project (http://www.apache.org/)." 
- * 
- * 4. The names "Apache Server" and "Apache Software Foundation" must not be used to 
- *    endorse or promote products derived from this software without 
- *    prior written permission. For written permission, please contact 
- *    apache@apache.org. 
- * 
- * 5. Products derived from this software may not be called "Apache" 
- *    nor may "Apache" appear in their names without prior written 
- *    permission of the Apache Software Foundation. 
- * 
- * 6. Redistributions of any form whatsoever must retain the following 
- *    acknowledgment: 
- *    "This product includes software developed by the Apache Software Foundation 
- *    for use in the Apache HTTP server project (http://www.apache.org/)." 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE Apache Software Foundation ``AS IS'' AND ANY 
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE Apache Software Foundation OR 
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
- * OF THE POSSIBILITY OF SUCH DAMAGE. 
- * ==================================================================== 
- * 
- * This software consists of voluntary contributions made by many 
- * individuals on behalf of the Apache Software Foundation and was originally based 
- * on public domain software written at the National Center for 
- * Supercomputing Applications, University of Illinois, Urbana-Champaign. 
- * For more information on the Apache Software Foundation and the Apache HTTP server 
- * project, please see <http://www.apache.org/>. 
- * 
- */ 
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
 
 #define CORE_PRIVATE
 #include "ap_config.h"
 #include "http_main.h" 
 #include "http_log.h" 
 #include "http_config.h"
+#include "http_vhost.h"
 #include "util_uri.h" 
+#include "util_ebcdic.h"
+#include "apr_strings.h"
 #include "apr_getopt.h"
 #include "ap_mpm.h"
 
-const char *ap_server_argv0;
-
-const char *ap_server_root;
-
-ap_array_header_t *ap_server_pre_read_config;
-ap_array_header_t *ap_server_post_read_config;
-ap_array_header_t *ap_server_config_defines;
+/* 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
+ */
 
 /* XXX - We should be able to grab the per-MPM settings here too */
 static void show_compile_settings(void)
@@ -87,23 +89,17 @@ static void show_compile_settings(void)
 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
     printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
 #endif
-#ifdef HAVE_MMAP
+#ifdef APR_HAS_MMAP
     printf(" -D HAVE_MMAP\n");
 #endif
 #ifdef HAVE_SHMGET
     printf(" -D HAVE_SHMGET\n");
 #endif
-#ifdef USE_MMAP_SCOREBOARD
-    printf(" -D USE_MMAP_SCOREBOARD\n");
+#ifdef USE_FILE_BASED_SCOREBOARD
+    printf(" -D USE_FILE_BASED_SCOREBOARD\n");
 #endif
-#ifdef USE_SHMGET_SCOREBOARD
-    printf(" -D USE_SHMGET_SCOREBOARD\n");
-#endif
-#ifdef USE_OS2_SCOREBOARD
-    printf(" -D USE_OS2_SCOREBOARD\n");
-#endif
-#ifdef USE_POSIX_SCOREBOARD
-    printf(" -D USE_POSIX_SCOREBOARD\n");
+#ifdef USE_MEM_BASED_SCOREBOARD
+    printf(" -D USE_MEM_BASED_SCOREBOARD\n");
 #endif
 #ifdef USE_MMAP_FILES
     printf(" -D USE_MMAP_FILES\n");
@@ -117,26 +113,26 @@ static void show_compile_settings(void)
 #ifdef NO_LINGCLOSE
     printf(" -D NO_LINGCLOSE\n");
 #endif
-#ifdef USE_FCNTL_SERIALIZED_ACCEPT
-    printf(" -D USE_FCNTL_SERIALIZED_ACCEPT\n");
+#if APR_USE_FLOCK_SERIALIZE
+    printf(" -D APR_USE_FLOCK_SERIALIZE\n");
 #endif
-#ifdef USE_FLOCK_SERIALIZED_ACCEPT
-    printf(" -D USE_FLOCK_SERIALIZED_ACCEPT\n");
+#if APR_USE_SYSVSEM_SERIALIZE
+    printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
 #endif
-#ifdef USE_USLOCK_SERIALIZED_ACCEPT
-    printf(" -D USE_USLOCK_SERIALIZED_ACCEPT\n");
+#if APR_USE_FCNTL_SERIALIZE
+    printf(" -D APR_USE_FCNTL_SERIALIZE\n");
 #endif
-#ifdef USE_SYSVSEM_SERIALIZED_ACCEPT
-    printf(" -D USE_SYSVSEM_SERIALIZED_ACCEPT\n");
+#if APR_USE_PROC_PTHREAD_SERIALIZE
+    printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
 #endif
-#ifdef USE_PTHREAD_SERIALIZED_ACCEPT
-    printf(" -D USE_PTHREAD_SERIALIZED_ACCEPT\n");
+#if APR_USE_PTHREAD_SERIALIZE
+    printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
 #endif
 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
     printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
 #endif
-#ifdef HAS_OTHER_CHILD
-    printf(" -D HAS_OTHER_CHILD\n");
+#if APR_HAS_OTHER_CHILD
+    printf(" -D APR_HAS_OTHER_CHILD\n");
 #endif
 #ifdef HAVE_RELIABLE_PIPED_LOGS
     printf(" -D HAVE_RELIABLE_PIPED_LOGS\n");
@@ -150,6 +146,9 @@ static void show_compile_settings(void)
 #ifdef CHARSET_EBCDIC
     printf(" -D CHARSET_EBCDIC\n");
 #endif
+#ifdef APACHE_XLATE
+    printf(" -D APACHE_XLATE\n");
+#endif
 #ifdef NEED_HASHBANG_EMUL
     printf(" -D NEED_HASHBANG_EMUL\n");
 #endif
@@ -192,35 +191,35 @@ static void show_compile_settings(void)
 
 static void destroy_and_exit_process(process_rec *process, int process_exit_value)
 {
-    ap_destroy_pool(process->pool); /* and destroy all descendent pools */
-    ap_terminate();
+    apr_destroy_pool(process->pool); /* and destroy all descendent pools */
+    apr_terminate();
     exit(process_exit_value);
 }
 
-static process_rec *create_process(int argc, const char **argv)
+static process_rec *create_process(int argc, char *const *argv)
 {
     process_rec *process;
     
     {
-       ap_context_t *cntx;
-        ap_status_t stat;
+       apr_pool_t *cntx;
+        apr_status_t stat;
 
-       stat = ap_create_context(&cntx, NULL);
+       stat = apr_create_pool(&cntx, NULL);
         if (stat != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
-                         "ap_create_context() failed to create "
+                         "apr_create_pool() failed to create "
                          "initial context");
-            ap_terminate();
+            apr_terminate();
             exit(1);
         }
 
-       process = ap_palloc(cntx, sizeof(process_rec));
+       process = apr_palloc(cntx, sizeof(process_rec));
        process->pool = cntx;
     }
-    ap_create_context(&process->pconf, process->pool);
+    apr_create_pool(&process->pconf, process->pool);
     process->argc = argc;
     process->argv = argv;
-    process->short_name = ap_filename_of_pathname(argv[0]);
+    process->short_name = apr_filename_of_pathname(argv[0]);
     return process;
 }
 
@@ -275,62 +274,73 @@ static void usage(process_rec *process)
     destroy_and_exit_process(process, 1);
 }
 
-ap_context_t *g_pHookPool;
-
-#ifdef WIN32
-API_EXPORT_NONSTD(int) apache_main(int argc, char *argv[])
-#else
-API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
-#endif
+int main(int argc, char *argv[])
 {
-    int c;
+    char c;
     int configtestonly = 0;
     const char *confname = SERVER_CONFIG_FILE;
     const char *def_server_root = HTTPD_ROOT;
     process_rec *process;
     server_rec *server_conf;
-    ap_context_t *pglobal;
-    ap_context_t *pconf;
-    ap_context_t *plog; /* Pool of log streams, reset _after_ each read of conf */
-    ap_context_t *ptemp; /* Pool for temporary config stuff, reset often */
-    ap_context_t *pcommands; /* Pool for -C and -c switches */
+    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 */
+    apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
+    apr_getopt_t *opt;
     module **mod;
+    ap_directive_t *conftree = NULL;
+    const char *optarg;
 
-#ifndef WIN32 /* done in main_win32.c */
-    ap_initialize();
-#endif
-    process = create_process(argc, (const char **)argv);
+    apr_initialize();
+    process = create_process(argc, argv);
     pglobal = process->pool;
     pconf = process->pconf;
     ap_server_argv0 = process->short_name;
-    
-    ap_util_uri_init();
 
-    g_pHookPool=pconf;
+#ifdef CHARSET_EBCDIC
+    if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
+        destroy_and_exit_process(process, 1);
+    }
+#endif
+
+    ap_util_uri_init();
 
     ap_setup_prelinked_modules(process);
 
-    ap_create_context(&pcommands, pglobal);
-    ap_server_pre_read_config  = ap_make_array(pcommands, 1, sizeof(char *));
-    ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
-    ap_server_config_defines   = ap_make_array(pcommands, 1, sizeof(char *));
+    apr_create_pool(&pcommands, pglobal);
+    ap_server_pre_read_config  = apr_make_array(pcommands, 1, sizeof(char *));
+    ap_server_post_read_config = apr_make_array(pcommands, 1, sizeof(char *));
+    ap_server_config_defines   = apr_make_array(pcommands, 1, sizeof(char *));
 
-    while (ap_getopt(argc, argv, "C:c:d:f:k:vVlLth", &c, pcommands) == APR_SUCCESS) {
+    ap_run_rewrite_args(process);
+
+    /* 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_initopt(&opt, pcommands, process->argc, process->argv);
+
+    while (apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg) 
+            == APR_SUCCESS) {
         char **new;
         switch (c) {
        case 'c':
-           new = (char **)ap_push_array(ap_server_post_read_config);
-           *new = ap_pstrdup(pcommands, ap_optarg);
+           new = (char **)apr_push_array(ap_server_post_read_config);
+           *new = apr_pstrdup(pcommands, optarg);
            break;
        case 'C':
-           new = (char **)ap_push_array(ap_server_pre_read_config);
-           *new = ap_pstrdup(pcommands, ap_optarg);
+           new = (char **)apr_push_array(ap_server_pre_read_config);
+           *new = apr_pstrdup(pcommands, optarg);
            break;
        case 'd':
-           def_server_root = ap_optarg;
+           def_server_root = optarg;
+           break;
+       case 'D':
+           new = (char **)apr_push_array(ap_server_config_defines);
+           *new = apr_pstrdup(pcommands, optarg);
            break;
        case 'f':
-           confname = ap_optarg;
+           confname = optarg;
            break;
        case 'v':
            printf("Server version: %s\n", ap_get_server_version());
@@ -348,15 +358,14 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
        case 't':
            configtestonly = 1;
            break;
-       case 'h':
-           usage(process);
        case '?':
+       case 'h':
            usage(process);
        }
     }
 
-    ap_create_context(&plog, pglobal);
-    ap_create_context(&ptemp, pconf);
+    apr_create_pool(&plog, pglobal);
+    apr_create_pool(&ptemp, pconf);
 
     /* Note that we preflight the config file once
        before reading it _again_ in the main loop.
@@ -364,31 +373,44 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
        for example, to settle down. */
 
     ap_server_root = def_server_root;
-    run_pre_config(pconf, plog, ptemp, server_conf);
-    server_conf = ap_read_config(process, ptemp, confname);
+    server_conf = ap_read_config(process, ptemp, confname, &conftree);
+    ap_run_pre_config(pconf, plog, ptemp);
+    ap_process_config_tree(server_conf, conftree, process->pconf, ptemp); 
+    ap_fixup_virtual_hosts(pconf, server_conf);
+    ap_fini_vhost_config(pconf, server_conf);
+    ap_sort_hooks();
     if (configtestonly) {
        ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax OK\n");
        destroy_and_exit_process(process, 0);
     }
-    ap_clear_pool(plog);
+    apr_clear_pool(plog);
     ap_run_open_logs(pconf, plog, ptemp, server_conf);
     ap_post_config_hook(pconf, plog, ptemp, server_conf);
-    ap_destroy_pool(ptemp);
+    apr_destroy_pool(ptemp);
 
     for (;;) {
        ap_hook_deregister_all();
-       ap_clear_pool(pconf);
+       apr_clear_pool(pconf);
        for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
                ap_register_hooks(*mod);
        }
-       ap_create_context(&ptemp, pconf);
+        /* 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
+         */
+        conftree = NULL;
+       apr_create_pool(&ptemp, pconf);
        ap_server_root = def_server_root;
-       run_pre_config(pconf, plog, ptemp, server_conf);
-       server_conf = ap_read_config(process, ptemp, confname);
-       ap_clear_pool(plog);
+        server_conf = ap_read_config(process, ptemp, confname, &conftree);
+       ap_run_pre_config(pconf, plog, ptemp);
+        ap_process_config_tree(server_conf, conftree, process->pconf, ptemp); 
+        ap_fixup_virtual_hosts(pconf, server_conf);
+        ap_fini_vhost_config(pconf, server_conf);
+        ap_sort_hooks();
+       apr_clear_pool(plog);
        ap_run_open_logs(pconf, plog, ptemp, server_conf);
        ap_post_config_hook(pconf, plog, ptemp, server_conf);
-       ap_destroy_pool(ptemp);
+       apr_destroy_pool(ptemp);
 
        if (ap_mpm_run(pconf, plog, server_conf)) break;
     }
@@ -408,13 +430,13 @@ const XML_LChar *suck_in_expat(void)
 
 #ifndef SHARED_CORE_BOOTSTRAP
 /*
- * Force ap_validate_password() into the image so that modules like
+ * Force apr_validate_password() into the image so that modules like
  * mod_auth can use it even if they're dynamically loaded.
  */
-void suck_in_ap_validate_password(void);
-void suck_in_ap_validate_password(void)
+void suck_in_apr_validate_password(void);
+void suck_in_apr_validate_password(void)
 {
-    ap_validate_password("a", "b");
+    apr_validate_password("a", "b");
 }
 #endif