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 patch for 2.0
Date Fri, 17 Nov 2000 00:38:51 GMT
Same patch as posted for 1.3, ported to 2.0

Index: src/main/http_log.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/main/http_log.c,v
retrieving revision 1.73
diff -u -d -r1.73 http_log.c
--- http_log.c	2000/11/14 02:42:51	1.73
+++ http_log.c	2000/11/17 00:17:20
@@ -639,9 +639,8 @@
 	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:
Index: src/support/rotatelogs.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/support/rotatelogs.c,v
retrieving revision 1.9
diff -u -d -r1.9 rotatelogs.c
--- rotatelogs.c	2000/06/12 23:03:05	1.9
+++ rotatelogs.c	2000/11/17 00:17:20
@@ -72,6 +72,7 @@
 #include <fcntl.h>
 
 #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 @@
 	    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,44 @@
 	    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);
+		}
+	    }
+	    else {
+		close(nLogFDprev);
 	    }
+	    nMessCount = 0;
 	}
-	if (write(nLogFD, buf, nRead) != nRead) {
-	    perror(buf2);
-	    exit(5);
+	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++;
 	}
     }
     /* Of course we never, but prevent compiler warnings */

Victor
-- 
Victor J. Orlikowski
======================
v.j.orlikowski@gte.net
vjo@raleigh.ibm.com
vjo@us.ibm.com


Mime
View raw message