Return-Path: Delivered-To: apmail-new-httpd-archive@apache.org Received: (qmail 93572 invoked by uid 500); 6 Nov 2000 17:45:39 -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 93443 invoked from network); 6 Nov 2000 17:45:06 -0000 From: "Victor J. Orlikowski" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14854.60933.844703.798213@critterling.garfield.home> Date: Mon, 6 Nov 2000 12:44:37 -0500 To: new-httpd@apache.org Subject: [PATCH] Piped logs, rotatelogs, and 1.3.x X-Mailer: VM 6.76 under Emacs 20.7.1 Reply-To: v.j.orlikowski@gte.net X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N The following patch repairs rotatelogs to be more reliable in the case that open(2) or write(2) to the error log fail, whatever the cause. Further, we make piped logs ignore write errors, since this can simply be the result of a full pipe. Index: src/main/http_log.c =================================================================== RCS file: /cvs/apache/apache-1.3/src/main/http_log.c,v retrieving revision 1.85 diff -u -d -b -r1.85 http_log.c --- http_log.c 2000/06/19 20:44:27 1.85 +++ http_log.c 2000/11/06 17:42:11 @@ -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 -b -r1.12 rotatelogs.c --- rotatelogs.c 2000/06/21 22:54:45 1.12 +++ rotatelogs.c 2000/11/06 17:42:11 @@ -13,18 +13,19 @@ #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]; + char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ]; time_t tLogEnd = 0; time_t tRotation; - int nLogFD = -1; - int nRead; + int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite; char *szLogRoot; + const char *errmsg = "Error writing to log file. Lost a message.\n"; if (argc != 3) { fprintf(stderr, @@ -63,7 +64,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 +73,44 @@ tLogEnd = tLogStart + tRotation; nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, 0666); if (nLogFD < 0) { + /* 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; + ftruncate(nLogFD, 0); + sprintf(errbuf, + "Resetting log file due to error opening " + "new log file. %10d messages lost.\n", + nMessCount); + nWrite = strlen(errbuf) + 1; + write(nLogFD, errbuf, nWrite); } - if (write(nLogFD, buf, nRead) != nRead) { - perror(buf2); - exit(5); } + else { + close(nLogFDprev); } - /* We never get here, but surpress the compile warning */ + nMessCount = 0; + } + do { + nWrite = write(nLogFD, buf, nRead); + } while (nWrite < 0 && errno == EINTR); + if (nWrite != nRead) { + /* Problem with the log. Try to seek back and + * state that a message was lost. */ + nWrite = strlen(errmsg) + 1; + lseek (nLogFD, nWrite, SEEK_CUR); + write (nLogFD, errbuf, nWrite); + + } + else { + nMessCount++; + } + } + /* 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