You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Victor J. Orlikowski" <v....@gte.net> on 2000/11/17 19:13:29 UTC

[PATCH] rotatelogs, part 3 - against the fixed rotatelogs

Here is the 1.3 version of the rotatelogs patch, after the style patch
has been applied.

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 -u -d -r1.87 http_log.c
--- http_log.c	2000/11/14 09:57:08	1.87
+++ http_log.c	2000/11/17 17:57:35
@@ -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.13
diff -u -d -u -d -r1.13 rotatelogs.c
--- rotatelogs.c	2000/11/17 14:55:39	1.13
+++ rotatelogs.c	2000/11/17 17:57:40
@@ -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);
+                }
             }
+            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++; 
         }
     }
-    /* 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