]> granicus.if.org Git - apache/blobdiff - server/config.c
event: child_main() never returns, so remove some dead code after
[apache] / server / config.c
index 3b94b4534765234bc6c71af15fa35b88bf7a9fe5..31def823c3eed71f987fdd2af4e522cd084f50c4 100644 (file)
@@ -49,6 +49,7 @@
 #include "http_main.h"
 #include "http_vhost.h"
 #include "util_cfgtree.h"
+#include "mpm_common.h"
 
 #define APLOG_UNSET   (APLOG_NO_MODULE - 1)
 APLOG_USE_MODULE(core);
@@ -185,7 +186,7 @@ static int total_modules = 0;
  */
 static int dynamic_modules = 0;
 
-/* The maximum possible value for total_modulese, i.e. number of static
+/* The maximum possible value for total_modules, i.e. number of static
  * modules plus DYNAMIC_MODULE_LIMIT.
  */
 static int max_modules = 0;
@@ -202,10 +203,21 @@ AP_DECLARE_DATA module **ap_loaded_modules=NULL;
 
 static apr_hash_t *ap_config_hash = NULL;
 
+/* a list of the module symbol names with the trailing "_module"removed */
+static char **ap_module_short_names = NULL;
+
 typedef int (*handler_func)(request_rec *);
 typedef void *(*dir_maker_func)(apr_pool_t *, char *);
 typedef void *(*merger_func)(apr_pool_t *, void *, void *);
 
+/* A list of the merge_dir_config functions of all loaded modules, sorted
+ * by module_index.
+ * Using this list in ap_merge_per_dir_configs() is faster than following
+ * the module->next linked list because of better memory locality (resulting
+ * in better cache usage).
+ */
+static merger_func *merger_func_cache;
+
 /* maximum nesting level for config directories */
 #ifndef AP_MAX_INCLUDE_DIR_DEPTH
 #define AP_MAX_INCLUDE_DIR_DEPTH (128)
@@ -250,16 +262,14 @@ AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
     void **conf_vector = apr_palloc(p, sizeof(void *) * conf_vector_length);
     void **base_vector = (void **)base;
     void **new_vector = (void **)new_conf;
-    module *modp;
-
-    for (modp = ap_top_module; modp; modp = modp->next) {
-        int i = modp->module_index;
+    int i;
 
+    for (i = 0; i < total_modules; i++) {
         if (!new_vector[i]) {
             conf_vector[i] = base_vector[i];
         }
         else {
-            merger_func df = modp->merge_dir_config;
+            const merger_func df = merger_func_cache[i];
             if (df && base_vector[i]) {
                 conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]);
             }
@@ -467,19 +477,13 @@ struct ap_mod_list_struct {
     const command_rec *cmd;
 };
 
-static apr_status_t reload_conf_hash(void *baton)
-{
-    ap_config_hash = NULL;
-    return APR_SUCCESS;
-}
-
 static void rebuild_conf_hash(apr_pool_t *p, int add_prelinked)
 {
     module **m;
 
     ap_config_hash = apr_hash_make(p);
 
-    apr_pool_cleanup_register(p, NULL, reload_conf_hash,
+    apr_pool_cleanup_register(p, &ap_config_hash, ap_pool_cleanup_set_null,
                               apr_pool_cleanup_null);
     if (add_prelinked) {
         for (m = ap_prelinked_modules; *m != NULL; m++) {
@@ -520,8 +524,11 @@ static void ap_add_module_commands(module *m, apr_pool_t *p)
 
 /* One-time setup for precompiled modules --- NOT to be done on restart */
 
-AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
+AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
+                                       const char *sym_name)
 {
+    ap_module_symbol_t *sym = ap_prelinked_module_symbols;
+
     /* This could be called from a LoadModule httpd.conf command,
      * after the file has been linked and the module structure within it
      * teased out...
@@ -549,7 +556,30 @@ AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
                                 "reached. Please increase "
                                 "DYNAMIC_MODULE_LIMIT and recompile.", m->name);
         }
+
     }
+    else if (!sym_name) {
+        while (sym->modp != NULL) {
+            if (sym->modp == m) {
+                sym_name = sym->name;
+                break;
+            }
+            sym++;
+        }
+    }
+
+    if (sym_name) {
+        int len = strlen(sym_name);
+        int slen = strlen("_module");
+        if (len > slen && !strcmp(sym_name + len - slen, "_module")) {
+            len -= slen;
+        }
+
+        ap_module_short_names[m->module_index] = strdup(sym_name);
+        ap_module_short_names[m->module_index][len] = '\0';
+        merger_func_cache[m->module_index] = m->merge_dir_config;
+    }
+
 
     /* Some C compilers put a complete path into __FILE__, but we want
      * only the filename (e.g. mod_includes.c). So check for path
@@ -623,13 +653,18 @@ AP_DECLARE(void) ap_remove_module(module *m)
         modp->next = modp->next->next;
     }
 
+    free(ap_module_short_names[m->module_index]);
+    ap_module_short_names[m->module_index] = NULL;
+    merger_func_cache[m->module_index] = NULL;
+
     m->module_index = -1; /* simulate being unloaded, should
                            * be unnecessary */
     dynamic_modules--;
     total_modules--;
 }
 
-AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
+AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p,
+                                              const char *short_name)
 {
     module **m;
     const char *error;
@@ -637,7 +672,7 @@ AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
     /*
      *  Add module pointer to top of chained module list
      */
-    error = ap_add_module(mod, p);
+    error = ap_add_module(mod, p, short_name);
     if (error) {
         return error;
     }
@@ -709,14 +744,19 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
     conf_vector_length = max_modules;
 
     /*
-     *  Initialise list of loaded modules
+     *  Initialise list of loaded modules and short names
      */
     ap_loaded_modules = (module **)apr_palloc(process->pool,
         sizeof(module *) * conf_vector_length);
+    if (!ap_module_short_names)
+        ap_module_short_names = calloc(sizeof(char *), conf_vector_length);
+
+    if (!merger_func_cache)
+        merger_func_cache = calloc(sizeof(merger_func), conf_vector_length);
 
-    if (ap_loaded_modules == NULL) {
+    if (ap_loaded_modules == NULL || ap_module_short_names == NULL
+        || merger_func_cache == NULL)
         return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
-    }
 
     for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
         *m2++ = *m++;
@@ -727,7 +767,7 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
      *   Initialize chain of linked (=activate) modules
      */
     for (m = ap_prelinked_modules; *m != NULL; m++) {
-        error = ap_add_module(*m, process->pconf);
+        error = ap_add_module(*m, process->pconf, NULL);
         if (error) {
             return error;
         }
@@ -743,6 +783,13 @@ AP_DECLARE(const char *) ap_find_module_name(module *m)
     return m->name;
 }
 
+AP_DECLARE(const char *) ap_find_module_short_name(int module_index)
+{
+        if (module_index < 0 || module_index >= conf_vector_length)
+                return NULL;
+        return ap_module_short_names[module_index];
+}
+
 AP_DECLARE(module *) ap_find_linked_module(const char *name)
 {
     module *modp;
@@ -1129,7 +1176,7 @@ AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
      */
     l = apr_palloc(temp_pool, MAX_STRING_LEN);
 
-    bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
+    bracket = apr_pstrcat(temp_pool, orig_directive + 1, ">", NULL);
     while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
         if (!memcmp(l, "</", 2)
             && (strcasecmp(l + 2, bracket) == 0)
@@ -1141,11 +1188,11 @@ AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
         if (retval != NULL)
             return retval;
 
-        if (sub_tree == NULL && curr_parent != NULL) {
+        if (sub_tree == NULL) {
             sub_tree = *curr_parent;
         }
 
-        if (sub_tree == NULL && current != NULL) {
+        if (sub_tree == NULL) {
             sub_tree = *current;
         }
     }
@@ -1242,11 +1289,28 @@ AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
     ap_directive_t *curr_parent = NULL;
     char *l = apr_palloc (temp_pool, MAX_STRING_LEN);
     const char *errmsg;
+    ap_directive_t **last_ptr = NULL;
 
     if (current != NULL) {
+        /* If we have to traverse the whole tree again for every included
+         * config file, the required time grows as O(n^2) with the number of
+         * files. This can be a significant delay for large configurations.
+         * Therefore we cache a pointer to the last node.
+         */
+        last_ptr = &(current->last);
+
+        if(last_ptr && *last_ptr) {
+            current = *last_ptr;
+        }
+
         while (current->next) {
             current = current->next;
         }
+
+        if(last_ptr) {
+            /* update cached pointer to last node */
+            *last_ptr = current;
+        }
     }
 
     while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
@@ -1343,6 +1407,18 @@ AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
     return NULL;
 }
 
+AP_DECLARE_NONSTD(const char *) ap_set_flag_slot_char(cmd_parms *cmd,
+                                                      void *struct_ptr_v, int arg)
+{
+    int offset = (int)(long)cmd->info;
+    char *struct_ptr = (char *)struct_ptr_v;
+
+    *(struct_ptr + offset) = arg ? 1 : 0;
+
+    return NULL;
+}
+
+
 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
                                                  const char *arg)
 {
@@ -1374,18 +1450,15 @@ AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd,
 
 AP_DECLARE(void) ap_reset_module_loglevels(struct ap_logconf *l, int val)
 {
-    if (l->module_levels) {
-        int i;
-        for (i = 0; i < conf_vector_length; i++)
-            l->module_levels[i] = val;
-    }
+    if (l->module_levels)
+        memset(l->module_levels, val, conf_vector_length);
 }
 
 AP_DECLARE(void) ap_set_module_loglevel(apr_pool_t *pool, struct ap_logconf *l,
                                         int index, int level)
 {
     if (!l->module_levels) {
-        l->module_levels = apr_palloc(pool, sizeof(int) * conf_vector_length);
+        l->module_levels = apr_palloc(pool, conf_vector_length);
         if (l->level == APLOG_UNSET) {
                 ap_reset_module_loglevels(l, APLOG_UNSET);
         }
@@ -1403,7 +1476,7 @@ AP_DECLARE(void) ap_set_module_loglevel(apr_pool_t *pool, struct ap_logconf *l,
  */
 
 static cmd_parms default_parms =
-{NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+{NULL, 0, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
 
 AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file)
 {
@@ -1434,7 +1507,7 @@ AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
         args = ap_resolve_env(cmd->temp_pool, l);
 #endif
 
-        cmd_name = ap_getword_conf(cmd->pool, &args);
+        cmd_name = ap_getword_conf(cmd->temp_pool, &args);
         if (cmd_name[0] == '<') {
             if (cmd_name[1] == '/') {
                 cmd_name[strlen(cmd_name) - 1] = '\0';
@@ -1474,7 +1547,7 @@ static const char *execute_now(char *cmd_line, const char *args,
 {
     const command_rec *cmd;
     ap_mod_list *ml;
-    char *dir = apr_pstrdup(parms->pool, cmd_line);
+    char *dir = apr_pstrdup(parms->temp_pool, cmd_line);
 
     ap_str_tolower(dir);
 
@@ -1646,13 +1719,13 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
     const char *error;
     apr_status_t rv;
 
-    if (ap_is_directory(p, fname)) {
+    if (ap_is_directory(ptemp, fname)) {
         apr_dir_t *dirp;
         apr_finfo_t dirent;
         int current;
         apr_array_header_t *candidates = NULL;
         fnames *fnew;
-        char *path = apr_pstrdup(p, fname);
+        char *path = apr_pstrdup(ptemp, fname);
 
         if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) {
             return apr_psprintf(p, "Directory %s exceeds the maximum include "
@@ -1666,20 +1739,20 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
          * entries here and store 'em away. Recall we need full pathnames
          * for this.
          */
-        rv = apr_dir_open(&dirp, path, p);
+        rv = apr_dir_open(&dirp, path, ptemp);
         if (rv != APR_SUCCESS) {
             char errmsg[120];
             return apr_psprintf(p, "Could not open config directory %s: %s",
                                 path, apr_strerror(rv, errmsg, sizeof errmsg));
         }
 
-        candidates = apr_array_make(p, 1, sizeof(fnames));
+        candidates = apr_array_make(ptemp, 1, sizeof(fnames));
         while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
             /* strip out '.' and '..' */
             if (strcmp(dirent.name, ".")
                 && strcmp(dirent.name, "..")) {
                 fnew = (fnames *) apr_array_push(candidates);
-                fnew->fname = ap_make_full_path(p, path, dirent.name);
+                fnew->fname = ap_make_full_path(ptemp, path, dirent.name);
             }
         }
 
@@ -1831,10 +1904,10 @@ AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s,
     /* don't require conf/httpd.conf if we have a -C or -c switch */
     if ((ap_server_pre_read_config->nelts
         || ap_server_post_read_config->nelts)
-        && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
+        && !(strcmp(fname, ap_server_root_relative(ptemp, SERVER_CONFIG_FILE)))) {
         apr_finfo_t finfo;
 
-        if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, p) != APR_SUCCESS)
+        if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, ptemp) != APR_SUCCESS)
             return NULL;
     }
 
@@ -1961,8 +2034,9 @@ AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
                 && !APR_STATUS_IS_ENOTDIR(status)) {
                 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
                               "%s pcfg_openfile: unable to check htaccess file, "
-                              "ensure it is readable",
-                              filename);
+                              "ensure it is readable and that '%s' " 
+                              "is executable",
+                              filename, d);
                 apr_table_setn(r->notes, "error-notes",
                                "Server unable to read htaccess file, denying "
                                "access to be safe");
@@ -2003,7 +2077,7 @@ AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
     s->keep_alive = -1;
     s->keep_alive_max = -1;
     s->error_log = main_server->error_log;
-    s->log.level = main_server->log.level;
+    s->log.level = APLOG_UNSET;
     s->log.module_levels = NULL;
     /* useful default, otherwise we get a port of 0 on redirects */
     s->port = main_server->port;
@@ -2033,7 +2107,7 @@ AP_DECLARE(struct ap_logconf *) ap_new_log_config(apr_pool_t *p,
         l->level = old->level;
         if (old->module_levels) {
             l->module_levels =
-                apr_pmemdup(p, old->module_levels, sizeof(int) * conf_vector_length);
+                apr_pmemdup(p, old->module_levels, conf_vector_length);
         }
     }
     else {
@@ -2042,25 +2116,25 @@ AP_DECLARE(struct ap_logconf *) ap_new_log_config(apr_pool_t *p,
     return l;
 }
 
-AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old,
-                                     struct ap_logconf *new)
+AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old_conf,
+                                     struct ap_logconf *new_conf)
 {
-    if (new->level != APLOG_UNSET) {
+    if (new_conf->level != APLOG_UNSET) {
         /* Setting the main loglevel resets all per-module log levels.
          * I.e. if new->level has been set, we must ignore old->module_levels.
          */
         return;
     }
 
-    new->level = old->level;
-    if (new->module_levels == NULL) {
-        new->module_levels = old->module_levels;
+    new_conf->level = old_conf->level;
+    if (new_conf->module_levels == NULL) {
+        new_conf->module_levels = old_conf->module_levels;
     }
-    else if (old->module_levels != NULL) {
+    else if (old_conf->module_levels != NULL) {
         int i;
         for (i = 0; i < conf_vector_length; i++) {
-            if (new->module_levels[i] == APLOG_UNSET)
-                new->module_levels[i] = old->module_levels[i];
+            if (new_conf->module_levels[i] == APLOG_UNSET)
+                new_conf->module_levels[i] = old_conf->module_levels[i];
         }
     }
 }
@@ -2147,7 +2221,12 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
     /* NOT virtual host; don't match any real network interface */
     rv = apr_sockaddr_info_get(&s->addrs->host_addr,
                                NULL, APR_INET, 0, 0, p);
-    ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
+    if (rv != APR_SUCCESS) {
+        /* should we test here for rv being an EAIERR? */
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, rv, NULL,
+                     "initialisation: bug or getaddrinfo fail");
+        return NULL;
+    }
 
     s->addrs->host_port = 0; /* matches any port */
     s->addrs->virthost = ""; /* must be non-NULL */
@@ -2173,6 +2252,9 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
     const char *confname, *error;
     apr_pool_t *p = process->pconf;
     server_rec *s = init_server_config(process, p);
+    if (s == NULL) {
+        return s;
+    }
 
     init_config_globals(p);
 
@@ -2204,6 +2286,13 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
         return NULL;
     }
 
+    error = ap_check_mpm();
+    if (error) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
+                     "%s: Configuration error: %s", ap_server_argv0, error);
+        return NULL;
+    }
+
     /*
      * We have loaded the dynamic modules. From now on we know exactly how
      * long the config vectors need to be.