tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r559348 - in /tomcat/connectors/trunk/jk/native/common: jk_logger.h jk_util.c jk_util.h
Date Wed, 25 Jul 2007 08:17:37 GMT
Author: rjung
Date: Wed Jul 25 01:17:35 2007
New Revision: 559348

URL: http://svn.apache.org/viewvc?view=rev&rev=559348
Log:
Revert some optimizations from r559264.
Those were not thread safe.
Kept renaming constants and smaller buffer.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_logger.h
    tomcat/connectors/trunk/jk/native/common/jk_util.c
    tomcat/connectors/trunk/jk/native/common/jk_util.h

Modified: tomcat/connectors/trunk/jk/native/common/jk_logger.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_logger.h?view=diff&rev=559348&r1=559347&r2=559348
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_logger.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_logger.h Wed Jul 25 01:17:35 2007
@@ -36,11 +36,12 @@
 {
     void *logger_private;
     int level;
-    char *log_fmt;        /* the configured timestamp format for logging */
-    char *log_fmt_subsec; /* like log_fmt, but milli/micro seconds
-                             marker replaced, because strftime() doesn't handle those */
-    char *log_fmt_offset; /* at which position should we insert */
-    int log_fmt_type;     /* do we want milli or microseconds */
+    const char *log_fmt;        /* the configured timestamp format for logging */
+    const char *log_fmt_subsec; /* like log_fmt, but milli/micro seconds
+                                   marker replaced, because strftime() doesn't handle those
*/
+    int log_fmt_offset;         /* at which position should we insert */
+    int log_fmt_type;           /* do we want milli or microseconds */
+    int log_fmt_size;           /* how long is this format string */
 
     int (JK_METHOD * log) (jk_logger_t *l, int level, int used, char *what);
 

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.c?view=diff&rev=559348&r1=559347&r2=559348
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Wed Jul 25 01:17:35 2007
@@ -350,7 +350,7 @@
 #endif
 }
 
-void jk_set_time_fmt(jk_logger_t *l, char *jk_log_fmt)
+void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt)
 {
     if (l) {
         char *s;
@@ -365,7 +365,8 @@
 #endif
         }
         l->log_fmt_type = JK_TIME_SUBSEC_NONE;
-        l->log_fmt_offset = NULL;
+        l->log_fmt_offset = 0;
+        l->log_fmt_size = 0;
         l->log_fmt_subsec = jk_log_fmt;
         l->log_fmt = jk_log_fmt;
 
@@ -377,7 +378,7 @@
                 int len = strlen(JK_TIME_PATTERN_MILLI);
 
                 l->log_fmt_type = JK_TIME_SUBSEC_MILLI;
-                l->log_fmt_offset = fmt + offset;
+                l->log_fmt_offset = offset;
                 strncpy(fmt, log_fmt_safe, offset);
                 strncpy(fmt + offset, JK_TIME_PATTERN_MILLI, len);
                 strncpy(fmt + offset + len,
@@ -385,13 +386,14 @@
                         JK_TIME_MAX_SIZE - offset - len);
                 fmt[JK_TIME_MAX_SIZE-1] = '\0';
                 l->log_fmt_subsec = fmt;
+                l->log_fmt_size = strlen(fmt);
             }
             else if ( (s = strstr(log_fmt_safe, JK_TIME_CONV_MICRO)) ) {
                 int offset = s - log_fmt_safe;
                 int len = strlen(JK_TIME_PATTERN_MICRO);
 
                 l->log_fmt_type = JK_TIME_SUBSEC_MICRO;
-                l->log_fmt_offset = fmt + offset;
+                l->log_fmt_offset = offset;
                 strncpy(fmt, log_fmt_safe, offset);
                 strncpy(fmt + offset, JK_TIME_PATTERN_MICRO, len);
                 strncpy(fmt + offset + len,
@@ -399,6 +401,7 @@
                         JK_TIME_MAX_SIZE - offset - len);
                 fmt[JK_TIME_MAX_SIZE-1] = '\0';
                 l->log_fmt_subsec = fmt;
+                l->log_fmt_size = strlen(fmt);
             }
         }
     }
@@ -409,11 +412,14 @@
     time_t t;
     struct tm *tms;
     int done;
+    char log_fmt[JK_TIME_MAX_SIZE];
 
     if ( !l || !l->log_fmt ) {
         return 0;
     }
 
+    log_fmt[0] = '\0';
+
 #ifndef NO_GETTIMEOFDAY
     if ( l->log_fmt_type != JK_TIME_SUBSEC_NONE ) {
         struct timeval tv;
@@ -421,13 +427,14 @@
         if ( rc == 0 ) {
             char subsec[7];
             t = tv.tv_sec;
+            strncpy(log_fmt, l->log_fmt_subsec, l->log_fmt_size + 1);
             if ( l->log_fmt_type == JK_TIME_SUBSEC_MILLI ) {
                 sprintf(subsec, "%03d", (int)(tv.tv_usec/1000));
-                strncpy(l->log_fmt_offset, subsec, 3);
+                strncpy(log_fmt + l->log_fmt_offset, subsec, 3);
             }
             else if ( l->log_fmt_type == JK_TIME_SUBSEC_MICRO ) {
                 sprintf(subsec, "%06d", (int)(tv.tv_usec));
-                strncpy(l->log_fmt_offset, subsec, 6);
+                strncpy(log_fmt + l->log_fmt_offset, subsec, 6);
             }
         }
         else {
@@ -441,15 +448,10 @@
     t = time(NULL);
 #endif
     tms = localtime(&t);
-    done = (int)strftime(str, len, l->log_fmt_subsec, tms);
-#ifndef NO_GETTIMEOFDAY
-    if ( l->log_fmt_type == JK_TIME_SUBSEC_MILLI ) {
-        strncpy(l->log_fmt_offset, JK_TIME_PATTERN_MILLI, 3);
-    }
-    else if ( l->log_fmt_type == JK_TIME_SUBSEC_MICRO ) {
-        strncpy(l->log_fmt_offset, JK_TIME_PATTERN_MICRO, 6);
-    }
-#endif
+    if (log_fmt[0])
+        done = (int)strftime(str, len, log_fmt, tms);
+    else
+        done = (int)strftime(str, len, l->log_fmt, tms);
     return done;
 
 }

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.h?view=diff&rev=559348&r1=559347&r2=559348
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.h Wed Jul 25 01:17:35 2007
@@ -39,7 +39,7 @@
 
 void jk_sleep(int ms);
 
-void jk_set_time_fmt(jk_logger_t *l, char *jk_log_fmt);
+void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt);
 
 int jk_parse_log_level(const char *level);
 



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


Mime
View raw message