From 0376baeba5a50ac95cf1cb0e7206d6fd43dad364 Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Tue, 21 Nov 2000 18:40:38 +0000 Subject: [PATCH] *) Accomodate an out-of-space condition in the piped logs and the rotatelogs.c code, and no longer churn log processes for this condition. [Victor J. Orlikowski] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87049 13f79535-47bb-0310-9956-ffa450edef68 --- server/log.c | 5 ++-- support/rotatelogs.c | 60 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/server/log.c b/server/log.c index 8d0c80989a..e3158b5206 100644 --- a/server/log.c +++ b/server/log.c @@ -639,9 +639,8 @@ static void piped_log_maintenance(int reason, void *data, apr_wait_t status) break; case APR_OC_REASON_UNWRITABLE: - if (pl->pid != NULL) { - apr_kill(pl->pid, SIGTERM); - } + /* We should not kill off the pipe here, since it may only be full. + * If it really is locked, we should kill it off manually. */ break; case APR_OC_REASON_RESTART: diff --git a/support/rotatelogs.c b/support/rotatelogs.c index f791fcaabc..1fe08c0f08 100644 --- a/support/rotatelogs.c +++ b/support/rotatelogs.c @@ -72,6 +72,7 @@ #include #define BUFSIZE 65536 +#define ERRMSGSZ 82 #ifndef MAX_PATH #define MAX_PATH 1024 @@ -79,11 +80,9 @@ int main (int argc, char *argv[]) { - char buf[BUFSIZE], buf2[MAX_PATH]; - time_t tLogEnd = 0; - time_t tRotation; - int nLogFD = -1; - int nRead; + char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ]; + time_t tLogEnd = 0, tRotation; + int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite; char *szLogRoot; if (argc != 3) { @@ -123,7 +122,7 @@ int main (int argc, char *argv[]) if (errno != EINTR) exit(4); if (nLogFD >= 0 && (time(NULL) >= tLogEnd || nRead < 0)) { - close(nLogFD); + nLogFDprev = nLogFD; nLogFD = -1; } if (nLogFD < 0) { @@ -132,13 +131,52 @@ int main (int argc, char *argv[]) tLogEnd = tLogStart + tRotation; nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, 0666); if (nLogFD < 0) { - perror(buf2); - exit(2); + /* Uh-oh. Failed to open the new log file. Try to clear + * the previous log file, note the lost log entries, + * and keep on truckin'. */ + if (nLogFDprev == -1) { + perror(buf2); + exit(2); + } + else { + nLogFD = nLogFDprev; + sprintf(errbuf, + "Resetting log file due to error opening " + "new log file. %10d messages lost.\n", + nMessCount); + nWrite = strlen(errbuf); +#ifdef WIN32 + chsize(nLogFD, 0); +#else + ftruncate(nLogFD, 0); +#endif + write(nLogFD, errbuf, nWrite); + } + } + else { + close(nLogFDprev); } + nMessCount = 0; + } + do { + nWrite = write(nLogFD, buf, nRead); + } while (nWrite < 0 && errno == EINTR); + if (nWrite != nRead) { + nMessCount++; + sprintf(errbuf, + "Error writing to log file. " + "%10d messages lost.\n", + nMessCount); + nWrite = strlen(errbuf); +#ifdef WIN32 + chsize(nLogFD, 0); +#else + ftruncate(nLogFD, 0); +#endif + write (nLogFD, errbuf, nWrite); } - if (write(nLogFD, buf, nRead) != nRead) { - perror(buf2); - exit(5); + else { + nMessCount++; } } /* Of course we never, but prevent compiler warnings */ -- 2.50.1