]> granicus.if.org Git - apache/commitdiff
rotatelogs: Log the current file size and error code/description
authorJeff Trawick <trawick@apache.org>
Thu, 10 Apr 2008 15:33:05 +0000 (15:33 +0000)
committerJeff Trawick <trawick@apache.org>
Thu, 10 Apr 2008 15:33:05 +0000 (15:33 +0000)
when failing to write to the log file.

Sometimes users have a hard time believing that their little log
file was really big enough to reach quota/filesystem/other limit
back at the time of the error.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@646845 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
support/rotatelogs.c

diff --git a/CHANGES b/CHANGES
index 6eb237ea53bf2c08ff0e952531d29811e5c69c3d..d32bcd659cacb7b0c55f9e9b1cbd68fc74ff1124 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 Changes with Apache 2.3.0
 [ When backported to 2.2.x, remove entry from this file ]
 
+  *) rotatelogs: Log the current file size and error code/description
+     when failing to write to the log file.  [Jeff Trawick]
+
   *) mod_dbd: Handle integer configuration directive parameters with a
      dedicated function.
 
index 80fa86bfd95aa200e18d32b59ebe191a932a2e62..8fd99dc77deeead1ba29f09cccbb3bf589b90837 100644 (file)
@@ -58,7 +58,7 @@
 #endif
 
 #define BUFSIZE         65536
-#define ERRMSGSZ        128
+#define ERRMSGSZ        256
 
 #ifndef MAX_PATH
 #define MAX_PATH        1024
@@ -299,13 +299,32 @@ int main (int argc, const char * const argv[])
          */
         if (!bypass_io) {
             nWrite = nRead;
-            apr_file_write(nLogFD, buf, &nWrite);
+            rv = apr_file_write(nLogFD, buf, &nWrite);
+            if (rv == APR_SUCCESS && nWrite != nRead) {
+                /* buffer partially written, which for rotatelogs means we encountered
+                 * an error such as out of space or quota or some other limit reached;
+                 * try to write the rest so we get the real error code
+                 */
+                apr_size_t nWritten = nWrite;
+
+                nRead  = nRead - nWritten;
+                nWrite = nRead;
+                rv = apr_file_write(nLogFD, buf + nWritten, &nWrite);
+            }
             if (nWrite != nRead) {
+                char strerrbuf[120];
+                apr_off_t cur_offset;
+                
+                cur_offset = 0;
+                if (apr_file_seek(nLogFD, APR_CUR, &cur_offset) != APR_SUCCESS) {
+                    cur_offset = -1;
+                }
+                apr_strerror(rv, strerrbuf, sizeof strerrbuf);
                 nMessCount++;
-                sprintf(errbuf,
-                        "Error writing to log file. "
-                        "%10d messages lost.\n",
-                        nMessCount);
+                apr_snprintf(errbuf, sizeof errbuf,
+                             "Error %d writing to log file at offset %" APR_OFF_T_FMT ". "
+                             "%10d messages lost (%s)\n",
+                             rv, cur_offset, nMessCount, strerrbuf);
                 nWrite = strlen(errbuf);
                 apr_file_trunc(nLogFD, 0);
                 if (apr_file_write(nLogFD, errbuf, &nWrite) != APR_SUCCESS) {