From 92c2a85ef4fe80ef4bd70c4345f4af94a38a0fbd Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Thu, 10 Apr 2008 15:33:05 +0000 Subject: [PATCH] rotatelogs: Log the current file size and error code/description 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 | 3 +++ support/rotatelogs.c | 31 +++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 6eb237ea53..d32bcd659c 100644 --- 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. diff --git a/support/rotatelogs.c b/support/rotatelogs.c index 80fa86bfd9..8fd99dc77d 100644 --- a/support/rotatelogs.c +++ b/support/rotatelogs.c @@ -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) { -- 2.40.0