static int jk_post_config()

in native/apache-2.0/mod_jk.c [3653:3824]


static int jk_post_config(apr_pool_t * pconf,
                          apr_pool_t * plog,
                          apr_pool_t * ptemp, server_rec * s)
{
    apr_status_t rv;
    jk_server_conf_t *conf;
    jk_log_context_t log_ctx;
    jk_log_context_t *l = &log_ctx;
    server_rec *srv = s;
    const char *err_string = NULL;
    int remain;
    void *data = NULL;

    l->logger = NULL;
    l->id = "POST_CONFIG";
    remain = jk_check_buffer_size();
    if (remain < 0) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s,
                     "mod_jk: JK_MAX_ATTRIBUTE_NAME_LEN in jk_util.c is too small, "
                     "increase by %d", -1 * remain);
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    apr_pool_userdata_get(&data, JK_LOG_LOCK_KEY, s->process->pool);
    if (data == NULL) {
        /* create the jk log lockfiles in the parent */
        if ((rv = apr_global_mutex_create(&jk_log_lock, NULL,
                                          APR_LOCK_DEFAULT,
                                          s->process->pool)) != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                         "mod_jk: could not create jk_log_lock");
            return HTTP_INTERNAL_SERVER_ERROR;
        }

#if JK_NEED_SET_MUTEX_PERMS
#if (MODULE_MAGIC_NUMBER_MAJOR >= 20090208)
        rv = ap_unixd_set_global_mutex_perms(jk_log_lock);
#else
        rv = unixd_set_global_mutex_perms(jk_log_lock);
#endif
        if (rv != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                         "mod_jk: Could not set permissions on "
                         "jk_log_lock; check User and Group directives");
            return HTTP_INTERNAL_SERVER_ERROR;
        }
#endif
        apr_pool_userdata_set((const void *)jk_log_lock, JK_LOG_LOCK_KEY,
                              apr_pool_cleanup_null, s->process->pool);
    }
    else {
        jk_log_lock = (apr_global_mutex_t *)data;
    }

    main_server = s;
    jk_log_fps = apr_hash_make(pconf);

    if (!s->is_virtual) {
        conf = (jk_server_conf_t *)ap_get_module_config(s->module_config,
                                                        &jk_module);
        l->logger = conf->log;
        if (conf->was_initialized == JK_FALSE) {
            /* step through the servers and open each jk logfile
             * and do additional post config initialization.
             */
            for (; srv; srv = srv->next) {
                jk_server_conf_t *sconf = (jk_server_conf_t *)ap_get_module_config(srv->module_config,
                                                                                   &jk_module);

/*
 * If a virtual server contains no JK directive, httpd shares
 * the config structure. But we don't want to share some settings
 * by default, especially the JkMount rules.
 * Therefore we check, if this config structure really belongs to this
 * vhost, otherwise we create a new one and merge.
 */
                if (sconf && sconf->s != srv) {
                    jk_server_conf_t *srvconf = (jk_server_conf_t *)create_jk_config(pconf, srv);
                    sconf = (jk_server_conf_t *)merge_jk_config(pconf, sconf, srvconf);
                    ap_set_module_config(srv->module_config, &jk_module, sconf);
                }

                if (sconf && sconf->was_initialized == JK_FALSE) {
                    sconf->was_initialized = JK_TRUE;
                    if (open_jklog(srv, pconf))
                        return HTTP_INTERNAL_SERVER_ERROR;
                    l->logger = sconf->log;
                    sconf->options &= ~sconf->exclude_options;
                    dump_options(srv, pconf);
                    if (sconf->uri_to_context) {
                        if (!uri_worker_map_alloc(&(sconf->uw_map),
                                                  sconf->uri_to_context, l))
                            jk_error_exit(JKLOG_MARK, APLOG_EMERG, srv,
                                          srv->process->pool, "Memory error");
                        if (sconf->options & JK_OPT_REJECTUNSAFE)
                            sconf->uw_map->reject_unsafe = 1;
                        else
                            sconf->uw_map->reject_unsafe = 0;
                        if (sconf->mount_file) {
                            sconf->uw_map->fname = sconf->mount_file;
                            sconf->uw_map->reload = sconf->mount_file_reload;
                            uri_worker_map_switch(sconf->uw_map, l);
                            uri_worker_map_load(sconf->uw_map, l);
                        }
                        if (sconf->options & JK_OPT_COLLAPSEMASK) {
                            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                                         "Deprecated CollapseSlashes setting ignored");
                        }
                    }
                    else {
                        if (sconf->mountcopy == JK_TRUE) {
                            sconf->uw_map = conf->uw_map;
                        }
                    }
                    if (sconf->format_string) {
                        sconf->format =
                            parse_request_log_string(pconf, sconf->format_string, &err_string);
                        if (sconf->format == NULL)
                            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                                         "JkRequestLogFormat format array NULL");
                    }
                    if (sconf->envvars && sconf->envvars_has_own) {
                        int i;
                        const apr_array_header_t *arr;
                        const apr_table_entry_t *elts;
                        envvar_item *item;
                        const char *envvar_def;

                        arr = apr_table_elts(sconf->envvars);
                        if (arr) {
                            elts = (const apr_table_entry_t *)arr->elts;
                            for (i = 0; i < arr->nelts; ++i) {
                                item = (envvar_item *)apr_array_push(sconf->envvar_items);
                                if (!item)
                                    return HTTP_INTERNAL_SERVER_ERROR;
                                item->name = elts[i].key;
                                envvar_def = apr_table_get(sconf->envvars_def, elts[i].key);
                                if (envvar_def && !strcmp("1", envvar_def)) {
                                    item->value = elts[i].val;
                                    item->has_default = 1;
                                }
                                else {
                                    item->value = "";
                                    item->has_default = 0;
                                }
                            }
                        }
                    }
                }
            }
            conf->was_initialized = JK_TRUE;
            l->logger = conf->log;
            if (init_jk(pconf, conf, s) == JK_FALSE)
                return HTTP_INTERNAL_SERVER_ERROR;
            if (conf->uw_map) {
                uri_worker_map_ext(conf->uw_map, l);
                uri_worker_map_switch(conf->uw_map, l);
            }
            for (srv = s; srv; srv = srv->next) {
                jk_server_conf_t *sconf = (jk_server_conf_t *)ap_get_module_config(srv->module_config,
                                                                                   &jk_module);
                l->logger = sconf->log;
                if (conf->uw_map != sconf->uw_map && sconf->uw_map) {
                    uri_worker_map_ext(sconf->uw_map, l);
                    uri_worker_map_switch(sconf->uw_map, l);
                }
            }

        }
    }

    return OK;
}