You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2006/11/19 20:31:57 UTC

svn commit: r476894 - in /tomcat/connectors/trunk/jk/native: apache-1.3/mod_jk.c apache-2.0/mod_jk.c

Author: rjung
Date: Sun Nov 19 11:31:57 2006
New Revision: 476894

URL: http://svn.apache.org/viewvc?view=rev&rev=476894
Log:
Adding a real config hierarchie for loggers with respect to vhosts.
We try to keep track of the pathes and piped we already have opened.
As long as they are writte in the same way, the descriptors will be
shared.

Modified:
    tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
    tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c

Modified: tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c?view=diff&rev=476894&r1=476893&r2=476894
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c Sun Nov 19 11:31:57 2006
@@ -198,6 +198,7 @@
 } dir_config_rec;
 
 static jk_logger_t *main_log = NULL;
+static table *jk_log_fds = NULL;
 static jk_worker_env_t worker_env;
 static char *jk_shm_file = NULL;
 static size_t jk_shm_size = JK_SHM_DEF_SIZE;
@@ -1037,6 +1038,7 @@
                                                   &jk_module);
 
     conf->stamp_format_string = ap_pstrdup(cmd->pool, log_format);
+ 
     return NULL;
 }
 
@@ -2044,7 +2046,6 @@
     c->mount_file = NULL;
     c->log_file = NULL;
     c->log_fd = -1;
-    c->log_level = JK_LOG_DEF_LEVEL;
     c->log = NULL;
     c->alias_dir = NULL;
     c->stamp_format_string = NULL;
@@ -2052,6 +2053,11 @@
     c->format = NULL;
     c->mountcopy = JK_FALSE;
     c->options = JK_OPT_FWDURIDEFAULT;
+    if (s->is_virtual) {
+        c->log_level = JK_UNSET;
+    } else {
+        c->log_level = JK_LOG_DEF_LEVEL;
+    }
 
     c->worker_indicator = JK_ENV_WORKER_NAME;
 
@@ -2126,6 +2132,11 @@
     jk_server_conf_t *base = (jk_server_conf_t *) basev;
     jk_server_conf_t *overrides = (jk_server_conf_t *) overridesv;
 
+    if (!overrides->log_file)
+        overrides->log_file = base->log_file;
+    if (overrides->log_level == JK_UNSET)
+        overrides->log_level = base->log_level;
+
     overrides->worker_indicator = base->worker_indicator;
 
     if (base->ssl_enable) {
@@ -2191,8 +2202,26 @@
     return JK_FALSE;
 }
 
+static int log_fd_get(char *key)
+{
+    const char *buf=ap_table_get(jk_log_fds, key);
+    if (buf)
+        return atoi(buf);
+    return 0;
+}
+
+static void log_fd_set(pool *p, char *key, int v)
+{
+    char *buf=(char *)ap_pcalloc(p, 8*sizeof(char));
+    ap_snprintf(buf, 8, "%d", v);
+    ap_table_setn(jk_log_fds, key, buf);
+}
+
 static void open_jk_log(server_rec *s, pool *p)
 {
+    const char *fname;
+    int jklogfd;
+    piped_log *pl;
     jk_logger_t *jkl;
     file_logger_t *flp;
     jk_server_conf_t *conf =
@@ -2207,36 +2236,56 @@
                          "Using default %s", conf->log_file);
     }
 
-    if (s->is_virtual && (!conf->log_file || conf->log_fd >= 0))
-        return;               /* virtual log shared w/main server */
+    if (s->is_virtual && conf->log_file == NULL) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                     "mod_jk: Invalid JkLogFile NULL");
+        conf->log = main_log;
+        return;
+    }
+    if (s->is_virtual && *(conf->log_file) == '\0') {
+        ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                     "mod_jk: Invalid JkLogFile EMPTY");
+        conf->log = main_log;
+        return;
+    }
 
-    if (*conf->log_file == '|') {
-        piped_log *pl;
+#ifdef CHROOTED_APACHE
+    ap_server_strip_chroot(conf->log_file, 0);
+#endif
 
-        pl = ap_open_piped_log(p, conf->log_file + 1);
-        if (pl == NULL) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                         "mod_jk: could not open reliable pipe "
-                         "to jk log %s", conf->log_file + 1);
-            exit(1);
+    jklogfd = log_fd_get(conf->log_file);
+    if (!jklogfd) {
+        if (*conf->log_file == '|') {
+            if ((pl = ap_open_piped_log(p, conf->log_file + 1)) == NULL) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                             "mod_jk: could not open reliable pipe "
+                             "to jk log %s", conf->log_file + 1);
+                exit(1);
+            }
+            jklogfd = ap_piped_log_write_fd(pl);
         }
-        conf->log_fd = ap_piped_log_write_fd(pl);
-    }
-    else if (*conf->log_file != '\0') {
-        char *log_file = ap_server_root_relative(p, conf->log_file);
+        else {
+            fname = ap_server_root_relative(p, conf->log_file);
+            if (!fname) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                             "mod_jk: Invalid JkLog " "path %s", conf->log_file);
+                exit(1);
+            }
 #if AP_MODULE_MAGIC_AT_LEAST(19990320,14)
-        if ((conf->log_fd = ap_popenf_ex(p, log_file, xfer_flags, xfer_mode, 1))
-             < 0) {
+            if ((jklogfd = ap_popenf_ex(p, fname, xfer_flags, xfer_mode, 1))
+                 < 0) {
 #else
-        if ((conf->log_fd = ap_popenf(p, log_file, xfer_flags, xfer_mode))
-             < 0) {
+            if ((jklogfd = ap_popenf(p, fname, xfer_flags, xfer_mode))
+                 < 0) {
 #endif
-            ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                         "mod_jk: could not open JkLog " "file %s", log_file);
-            exit(1);
+                ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                             "mod_jk: could not open JkLog " "file %s", fname);
+                exit(1);
+            }
         }
+        log_fd_set(p, conf->log_file, jklogfd);
     }
-
+    conf->log_fd = jklogfd;
     jkl = (jk_logger_t *)ap_palloc(p, sizeof(jk_logger_t));
     flp = (file_logger_t *)ap_palloc(p, sizeof(file_logger_t));
     if (jkl && flp) {
@@ -2263,10 +2312,11 @@
                                                   &jk_module);
     jk_map_t *init_map = conf->worker_properties;
 
-    open_jk_log(s, p);
-    main_log = conf->log;
+    jk_log_fds = ap_make_table(p, 0);
+
     for (t=s; t; t = t->next)
         open_jk_log(t, p);
+
 #if !defined(WIN32) && !defined(NETWARE)
     if (!jk_shm_file) {
         jk_shm_file = ap_server_root_relative(p, JK_SHM_DEF_FILE);

Modified: tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c?view=diff&rev=476894&r1=476893&r2=476894
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c Sun Nov 19 11:31:57 2006
@@ -211,6 +211,7 @@
 typedef struct apache_private_data apache_private_data_t;
 
 static jk_logger_t *main_log = NULL;
+static apr_hash_t *jk_log_fps = NULL;
 static jk_worker_env_t worker_env;
 static apr_global_mutex_t *jk_log_lock = NULL;
 static char *jk_shm_file = NULL;
@@ -1054,6 +1055,7 @@
                                                   &jk_module);
 
     conf->stamp_format_string = apr_pstrdup(cmd->pool, log_format);
+
     return NULL;
 }
 
@@ -2162,7 +2164,6 @@
     c->worker_file = NULL;
     c->mount_file = NULL;
     c->log_file = NULL;
-    c->log_level = JK_LOG_DEF_LEVEL;
     c->log = NULL;
     c->alias_dir = NULL;
     c->stamp_format_string = NULL;
@@ -2171,9 +2172,14 @@
     c->mountcopy = JK_FALSE;
     c->was_initialized = JK_FALSE;
     c->options = JK_OPT_FWDURIDEFAULT;
-
     c->worker_indicator = JK_ENV_WORKER_NAME;
 
+    if (s->is_virtual) {
+        c->log_level = JK_UNSET;
+    } else {
+        c->log_level = JK_LOG_DEF_LEVEL;
+    }
+
     /*
      * By default we will try to gather SSL info.
      * Disable this functionality through JkExtractSSL
@@ -2250,6 +2256,11 @@
     jk_server_conf_t *base = (jk_server_conf_t *) basev;
     jk_server_conf_t *overrides = (jk_server_conf_t *) overridesv;
 
+    if (!overrides->log_file)
+        overrides->log_file = base->log_file;
+    if (overrides->log_level == JK_UNSET)
+        overrides->log_level = base->log_level;
+    
     overrides->worker_indicator = base->worker_indicator;
 
     if (base->ssl_enable) {
@@ -2344,7 +2355,7 @@
 static apr_status_t jklog_cleanup(void *d)
 {
     /* set the main_log to NULL */
-    main_log = NULL;
+    d = NULL;
     return APR_SUCCESS;
 }
 
@@ -2353,6 +2364,7 @@
     jk_server_conf_t *conf;
     const char *fname;
     apr_status_t rc;
+    apr_file_t *jklogfp;
     piped_log *pl;
     jk_logger_t *jkl;
     file_logger_t *flp;
@@ -2362,47 +2374,51 @@
 
     conf = ap_get_module_config(s->module_config, &jk_module);
 
-    if (main_log != NULL) {
-        conf->log = main_log;
-        return 0;
-    }
     if (conf->log_file == NULL) {
         conf->log_file = ap_server_root_relative(pconf, JK_LOG_DEF_FILE);
         if (conf->log_file)
             ap_log_error(APLOG_MARK, APLOG_INFO | APLOG_NOERRNO,
-                         0, NULL,
+                         0, s,
                          "No JkLogFile defined in httpd.conf. "
                          "Using default %s", conf->log_file);
     }
     if (*(conf->log_file) == '\0') {
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s,
+                     "mod_jk: Invalid JkLogFile EMPTY");
+        conf->log = main_log;
         return 0;
     }
 
-    if (*conf->log_file == '|') {
-        if ((pl = ap_open_piped_log(p, conf->log_file + 1)) == NULL) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
-                         "mod_jk: could not open reliable pipe "
-                         "to jk log %s", conf->log_file + 1);
-            return -1;
+    jklogfp = apr_hash_get(jk_log_fps, conf->log_file, APR_HASH_KEY_STRING);
+    if (!jklogfp) {
+        if (*conf->log_file == '|') {
+            if ((pl = ap_open_piped_log(p, conf->log_file + 1)) == NULL) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
+                             "mod_jk: could not open reliable pipe "
+                             "to jk log %s", conf->log_file + 1);
+                return -1;
+            }
+            jklogfp = (void *)ap_piped_log_write_fd(pl);
         }
-        conf->jklogfp = (void *)ap_piped_log_write_fd(pl);
-    }
-    else {
-        fname = ap_server_root_relative(p, conf->log_file);
-        if (!fname) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s,
-                         "mod_jk: Invalid JkLog " "path %s", conf->log_file);
-            return -1;
-        }
-        if ((rc = apr_file_open(&conf->jklogfp, fname,
-                                jklog_flags, jklog_mode, p))
-            != APR_SUCCESS) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, rc, s,
-                         "mod_jk: could not open JkLog " "file %s", fname);
-            return -1;
+        else {
+            fname = ap_server_root_relative(p, conf->log_file);
+            if (!fname) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s,
+                             "mod_jk: Invalid JkLog " "path %s", conf->log_file);
+                return -1;
+            }
+            if ((rc = apr_file_open(&jklogfp, fname,
+                                    jklog_flags, jklog_mode, p))
+                != APR_SUCCESS) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, rc, s,
+                             "mod_jk: could not open JkLog " "file %s", fname);
+                return -1;
+            }
         }
-        apr_file_inherit_set(conf->jklogfp);
+        apr_file_inherit_set(jklogfp);
+        apr_hash_set(jk_log_fps, conf->log_file, APR_HASH_KEY_STRING, jklogfp);
     }
+    conf->jklogfp = jklogfp;
     jkl = (jk_logger_t *)apr_palloc(p, sizeof(jk_logger_t));
     flp = (file_logger_t *) apr_palloc(p, sizeof(file_logger_t));
     if (jkl && flp) {
@@ -2414,7 +2430,7 @@
         conf->log = jkl;
         if (main_log == NULL)
             main_log = conf->log;
-        apr_pool_cleanup_register(p, main_log, jklog_cleanup, jklog_cleanup);
+        apr_pool_cleanup_register(p, conf->log, jklog_cleanup, jklog_cleanup);
         return 0;
     }
 
@@ -2571,6 +2587,8 @@
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 #endif
+
+    jk_log_fps = apr_hash_make(pconf);
 
     if (!s->is_virtual) {
         conf = (jk_server_conf_t *)ap_get_module_config(s->module_config,



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org