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] Re-submit - rotatelogs fix for 1.3.x
Date Thu, 16 Nov 2000 20:46:47 GMT
Since the following received no attention the first time around, I am 
re-submitting it, as a solution to both the unwritable piped log 
killoff and the out-of-space for piped log hang.

Index: src/main/http_log.c
===================================================================
RCS file: /cvs/apache/apache-1.3/src/main/http_log.c,v
retrieving revision 1.76
diff -u -d -b -r1.76 http_log.c
--- http_log.c	1999/03/11 16:52:38	1.76
+++ http_log.c	2000/11/08 00:51:48
@@ -609,9 +609,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.11
diff -u -d -b -r1.11 rotatelogs.c
--- rotatelogs.c	1998/08/03 09:15:33	1.11
+++ rotatelogs.c	2000/11/08 00:51:48
@@ -7,21 +7,23 @@
  */
 
 
-#define BUFSIZE		65536
-#define MAX_PATH	1024
-
 #include "ap_config.h"
 #include <time.h>
 #include <errno.h>
 #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];
+    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;
 
     if (argc != 3) {
@@ -61,7 +63,7 @@
 	    if (errno != EINTR)
 		exit(4);
 	if (nLogFD >= 0 && (time(NULL) >= tLogEnd || nRead < 0)) {
-	    close(nLogFD);
+	    nLogFDprev = nLogFD;
 	    nLogFD = -1;
 	}
 	if (nLogFD < 0) {
@@ -70,13 +72,46 @@
 	    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;
+		    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 suppress the compile warning */
+    return (0);
 }

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


Mime
View raw message