httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Victor J. Orlikowski" <v.j.orlikow...@gte.net>
Subject [PATCH] rotatelogs fix .. update
Date Fri, 17 Nov 2000 00:38:03 GMT
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 <fcntl.h>
 
 #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


Mime
View raw message