static int init_jk()

in native/apache-2.0/mod_jk.c [3550:3669]


static int init_jk(apr_pool_t * pconf, jk_server_conf_t * conf,
                    server_rec * s)
{
    int rc;
    int is_threaded;
    int mpm_threads = 1;
    jk_log_context_t log_ctx;
    jk_log_context_t *l = &log_ctx;
    l->logger = conf->log;
    l->id = "JK_INIT";

    if (!jk_worker_properties)
        jk_map_alloc(&jk_worker_properties);
    jk_map_put(jk_worker_properties, "ServerRoot", ap_server_root, NULL);

    /* Set default connection cache size for multi-threaded MPMs */
    if (ap_mpm_query(AP_MPMQ_IS_THREADED, &is_threaded) == APR_SUCCESS &&
        is_threaded != AP_MPMQ_NOT_SUPPORTED) {
        if (ap_mpm_query(AP_MPMQ_MAX_THREADS, &mpm_threads) != APR_SUCCESS)
            mpm_threads = 1;
    }
    if (mpm_threads > 1) {
#if _MT_CODE
        /* _MT_CODE  */
        if (JK_IS_DEBUG_LEVEL(l)) {
#if !defined(WIN32)
#if USE_FLOCK_LK
            jk_log(l, JK_LOG_DEBUG,
                   "Using flock() for locking.");
#else
            jk_log(l, JK_LOG_DEBUG,
                   "Using fcntl() for locking.");
#endif /* USE_FLOCK_LK */
#else  /* WIN32 */
            jk_log(l, JK_LOG_DEBUG,
                   "Not using locking.");
#endif
        }
#else
        /* !_MT_CODE */
        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s,
                     "Cannot run prefork mod_jk on threaded server.");
        return JK_FALSE;
#endif
    }
    if (JK_IS_DEBUG_LEVEL(l))
        jk_log(l, JK_LOG_DEBUG,
               "Setting default connection pool max size to %d",
               mpm_threads);
    jk_set_worker_def_cache_size(mpm_threads);

    if ((jk_worker_file != NULL) &&
        !jk_map_read_properties(jk_worker_properties, NULL, jk_worker_file, NULL,
                                JK_MAP_HANDLE_DUPLICATES, l)) {
        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s,
                     "Error in reading worker properties from '%s'",
                     jk_worker_file);
        return JK_FALSE;
    }

    if (jk_map_resolve_references(jk_worker_properties, "worker.",
                                  1, 1, l) == JK_FALSE) {
        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s,
                     "Error in resolving configuration references");
        return JK_FALSE;
    }

#if !defined(WIN32)
    if (!jk_shm_file) {
        jk_shm_file = ap_server_root_relative(pconf, JK_SHM_DEF_FILE);
        if (jk_shm_file)
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                         "No JkShmFile defined in httpd.conf. "
                         "Using default %s", jk_shm_file);
    }
#endif
    if (jk_shm_size == 0) {
        jk_shm_size = jk_shm_calculate_size(jk_worker_properties, l);
    }
    else if (jk_shm_size_set) {
        jk_log(l, JK_LOG_WARNING,
               "The optimal shared memory size can now be determined automatically.");
        jk_log(l, JK_LOG_WARNING,
               "You can remove the JkShmSize directive if you want to use the optimal size.");
    }
    if ((rc = jk_shm_open(jk_shm_file, jk_shm_size, l)) == 0) {
        apr_pool_cleanup_register(pconf, l->logger,
                                  jk_cleanup_proc,
                                  apr_pool_cleanup_null);
    }
    else {
        jk_error_exit(JKLOG_MARK, APLOG_EMERG, s, s->process->pool,
                      "Initializing shm:%s errno=%d. Unable to start due to shared memory failure.",
                      jk_shm_name(), rc);
    }
    /* we add the URI->WORKER MAP since workers using AJP14
       will feed it */
    worker_env.uri_to_worker = conf->uw_map;
    worker_env.virtual = "*";   /* for now */
#if ((AP_MODULE_MAGIC_AT_LEAST(20051115,4)) && !defined(API_COMPATIBILITY)) || (MODULE_MAGIC_NUMBER_MAJOR >= 20060905)
    worker_env.server_name = (char *)ap_get_server_description();
#else
    worker_env.server_name = (char *)ap_get_server_version();
#endif
    worker_env.pool = pconf;

    if (wc_open(jk_worker_properties, &worker_env, l)) {
        ap_add_version_component(pconf, JK_EXPOSED_VERSION);
        jk_log(l, JK_LOG_INFO,
               "%s initialized",
               JK_FULL_EXPOSED_VERSION);
    }
    else {
        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s,
                     "Error in creating the workers."
                     " Please consult your mod_jk log file '%s'.", conf->log_file);
        return JK_FALSE;
    }
    return JK_TRUE;
}