Return-Path: Delivered-To: apmail-new-httpd-archive@apache.org Received: (qmail 61748 invoked by uid 500); 17 Nov 2000 00:38:31 -0000 Mailing-List: contact new-httpd-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list new-httpd@apache.org Received: (qmail 61722 invoked from network); 17 Nov 2000 00:38:30 -0000 From: "Victor J. Orlikowski" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14868.32235.526737.652041@critterling.garfield.home> Date: Thu, 16 Nov 2000 19:38:03 -0500 To: new-httpd@apache.org Subject: [PATCH] rotatelogs fix .. update X-Mailer: VM 6.82 under Emacs 20.7.1 Reply-To: v.j.orlikowski@gte.net X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N There were some indention problems in the rotatelogs patch I posted earlier. Ben Laurie likes tabs, not spaces. Here's the patch that takes that into account. Index: src/main/http_log.c =================================================================== RCS file: /cvs/apache/apache-1.3/src/main/http_log.c,v retrieving revision 1.87 diff -u -d -r1.87 http_log.c --- http_log.c 2000/11/14 09:57:08 1.87 +++ http_log.c 2000/11/17 00:35:38 @@ -664,9 +664,8 @@ break; case OC_REASON_UNWRITABLE: - if (pl->pid != -1) { - 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 OC_REASON_RESTART: Index: src/support/rotatelogs.c =================================================================== RCS file: /cvs/apache/apache-1.3/src/support/rotatelogs.c,v retrieving revision 1.12 diff -u -d -r1.12 rotatelogs.c --- rotatelogs.c 2000/06/21 22:54:45 1.12 +++ rotatelogs.c 2000/11/17 00:35:39 @@ -13,17 +13,16 @@ #include #define BUFSIZE 65536 +#define ERRMSGSZ 82 #ifndef MAX_PATH #define MAX_PATH 1024 #endif 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) { @@ -63,7 +62,7 @@ if (errno != EINTR) exit(4); if (nLogFD >= 0 && (time(NULL) >= tLogEnd || nRead < 0)) { - close(nLogFD); + nLogFDprev = nLogFD; nLogFD = -1; } if (nLogFD < 0) { @@ -72,15 +71,46 @@ 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); + ftruncate(nLogFD, 0); + write(nLogFD, errbuf, nWrite); + } } - } - if (write(nLogFD, buf, nRead) != nRead) { - perror(buf2); - exit(5); + 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); + ftruncate(nLogFD, 0); + write (nLogFD, errbuf, nWrite); + } + else { + nMessCount++; } } - /* We never get here, but surpress the compile warning */ + /* We never get here, but suppress the compile warning */ return (0); } Victor -- Victor J. Orlikowski ====================== v.j.orlikowski@gte.net vjo@raleigh.ibm.com vjo@us.ibm.com