tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r550213 - in /tomcat/connectors/trunk/jk: native/apache-1.3/mod_jk.c native/apache-2.0/mod_jk.c native/common/jk_logger.h native/common/jk_util.c xdocs/miscellaneous/changelog.xml
Date Sun, 24 Jun 2007 11:51:22 GMT
Author: rjung
Date: Sun Jun 24 04:51:21 2007
New Revision: 550213

URL: http://svn.apache.org/viewvc?view=rev&rev=550213
Log:
Make writing log lines and line endings more atomic.
This should prevent corrupt log lines
and should also be a little more efficient,
since we spare a couple of I/Os.

Modified:
    tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
    tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
    tomcat/connectors/trunk/jk/native/common/jk_logger.h
    tomcat/connectors/trunk/jk/native/common/jk_util.c
    tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml

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=550213&r1=550212&r2=550213
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c Sun Jun 24 04:51:21 2007
@@ -2381,29 +2381,23 @@
     return overrides;
 }
 
-static int JK_METHOD jk_log_to_file(jk_logger_t *l,
-                                    int level, const char *what)
+static int JK_METHOD jk_log_to_file(jk_logger_t *l, int level,
+                                    int used, char *what)
 {
     if (l &&
         (l->level <= level || level == JK_LOG_REQUEST_LEVEL) &&
-         l->logger_private && what) {
+         l->logger_private && what && used > 0) {
         jk_file_logger_t *flp = l->logger_private;
         int log_fd = flp->log_fd;
-        size_t sz = strlen(what);
-        if (log_fd >= 0 && sz) {
-            if (write(log_fd, what, sz) < 0 ) {
+        if (log_fd >= 0) {
+#if defined(WIN32)
+            what[used++] = '\r';
+#endif
+            what[used++] = '\n';
+            if (write(log_fd, what, used) < 0 ) {
                 ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
                              "mod_jk: jk_log_to_file %s failed",
                              what);
-            }
-            else {
-                char c;
-#if defined(WIN32)
-                c = '\r';
-                write(log_fd, &c, 1);
-#endif
-                c = '\n';
-                write(log_fd, &c, 1);
             }
         }
 

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=550213&r1=550212&r2=550213
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c Sun Jun 24 04:51:21 2007
@@ -2512,43 +2512,40 @@
     return overrides;
 }
 
-static int JK_METHOD jk_log_to_file(jk_logger_t *l,
-                                    int level, const char *what)
+static int JK_METHOD jk_log_to_file(jk_logger_t *l, int level,
+                                    int used, char *what)
 {
     if (l &&
         (l->level <= level || level == JK_LOG_REQUEST_LEVEL) &&
-        l->logger_private && what) {
-        unsigned sz = strlen(what);
-        apr_size_t wrote = sz;
-        char error[256];
-        if (sz) {
-            apr_status_t status;
-            jk_file_logger_t *p = l->logger_private;
-            if (p->jklogfp) {
-                apr_status_t rv;
-                rv = apr_global_mutex_lock(jk_log_lock);
-                if (rv != APR_SUCCESS) {
-                    ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
-                                 "apr_global_mutex_lock(jk_log_lock) failed");
-                    /* XXX: Maybe this should be fatal? */
-                }
-                status = apr_file_write(p->jklogfp, what, &wrote);
-                if (status != APR_SUCCESS) {
-                    apr_strerror(status, error, 254);
-                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
-                                 "mod_jk: jk_log_to_file %s failed: %s",
-                                 what, error);
-                }
+        l->logger_private && what && used > 0) {
+        jk_file_logger_t *p = l->logger_private;
+        if (p->jklogfp) {
+            apr_status_t rv;
+            apr_size_t wrote;
+            rv = apr_global_mutex_lock(jk_log_lock);
+            if (rv != APR_SUCCESS) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
+                             "apr_global_mutex_lock(jk_log_lock) failed");
+                /* XXX: Maybe this should be fatal? */
+            }
 #if defined(WIN32)
-                apr_file_putc('\r', p->jklogfp);
+            what[used++] = '\r';
 #endif
-                apr_file_putc('\n', p->jklogfp);
-                rv = apr_global_mutex_unlock(jk_log_lock);
-                if (rv != APR_SUCCESS) {
-                    ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
-                                 "apr_global_mutex_unlock(jk_log_lock) failed");
-                    /* XXX: Maybe this should be fatal? */
-                }
+            what[used++] = '\n';
+            wrote = used;
+            rv = apr_file_write(p->jklogfp, what, &wrote);
+            if (rv != APR_SUCCESS) {
+                char error[256];
+                apr_strerror(rv, error, 254);
+                ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+                             "mod_jk: jk_log_to_file %s failed: %s",
+                             what, error);
+            }
+            rv = apr_global_mutex_unlock(jk_log_lock);
+            if (rv != APR_SUCCESS) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
+                             "apr_global_mutex_unlock(jk_log_lock) failed");
+                /* XXX: Maybe this should be fatal? */
             }
         }
 

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=550213&r1=550212&r2=550213
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_logger.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_logger.h Sun Jun 24 04:51:21 2007
@@ -38,7 +38,7 @@
     int level;
     const char *log_fmt;
 
-    int (JK_METHOD * log) (jk_logger_t *l, int level, const char *what);
+    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=550213&r1=550212&r2=550213
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Sun Jun 24 04:51:21 2007
@@ -352,15 +352,16 @@
     return (int)strftime(str, len, JK_TIME_FORMAT, tms);
 }
 
-static int JK_METHOD log_to_file(jk_logger_t *l, int level, const char *what)
+static int JK_METHOD log_to_file(jk_logger_t *l, int level, int used, char *what)
 {
     if (l &&
         (l->level <= level || level == JK_LOG_REQUEST_LEVEL) &&
         l->logger_private && what) {
         jk_file_logger_t *p = l->logger_private;
         if (p->logfile) {
+            what[used++] = '\n';
+            what[used] = '\0';
             fputs(what, p->logfile);
-            fputc('\n', p->logfile);
             /* [V] Flush the dam' thing! */
             fflush(p->logfile);
         }
@@ -453,8 +454,12 @@
            const char *fmt, ...)
 {
     int rc = 0;
-    /* Need to reserve space for terminating zero byte. */
-    static int usable_size = HUGE_BUFFER_SIZE - 1;
+    /*
+     * Need to reserve space for terminating zero byte
+     * and platform specific line endings added during the call
+     * to the output routing.
+     */
+    static int usable_size = HUGE_BUFFER_SIZE - 3;
     if (!l || !file || !fmt) {
         return -1;
     }
@@ -524,8 +529,7 @@
         } else {
             used = usable_size;
         }
-        buf[used] = 0;
-        l->log(l, level, buf);
+        l->log(l, level, used, buf);
 
 #ifdef NETWARE
         free(buf);

Modified: tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml?view=diff&rev=550213&r1=550212&r2=550213
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml Sun Jun 24 04:51:21 2007
@@ -27,6 +27,9 @@
   <br />
   <subsection name="Native">
     <changelog>
+      <fix>
+      Make writing log lines and line endings more atomic. (rjung)
+      </fix>
       <update>
       Common: Refactored and unified jk_map_read_prop* and jk_map_load_prop*
       for all use cases. (rjung)



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


Mime
View raw message