]> granicus.if.org Git - apache/commitdiff
*) Accomodate an out-of-space condition in the piped logs and the
authorWilliam A. Rowe Jr <wrowe@apache.org>
Tue, 21 Nov 2000 18:40:38 +0000 (18:40 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Tue, 21 Nov 2000 18:40:38 +0000 (18:40 +0000)
     rotatelogs.c code, and no longer churn log processes for this
     condition.  [Victor J. Orlikowski]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87049 13f79535-47bb-0310-9956-ffa450edef68

server/log.c
support/rotatelogs.c

index 8d0c80989a1fd5c095f1a7eab5923f05f8faacec..e3158b5206aca4cb1aa6c995475837dbee478cd7 100644 (file)
@@ -639,9 +639,8 @@ static void piped_log_maintenance(int reason, void *data, apr_wait_t status)
        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 f791fcaabca1f4f1da8ea4d94edb4bbfa39b4e18..1fe08c0f08e786fb51796fde6a1fe98ba95ce347 100644 (file)
@@ -72,6 +72,7 @@
 #include <fcntl.h>
 
 #define BUFSIZE         65536
+#define ERRMSGSZ        82
 
 #ifndef MAX_PATH
 #define MAX_PATH        1024
 
 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 @@ int main (int argc, char *argv[])
             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,52 @@ int main (int argc, char *argv[])
             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);
+#ifdef WIN32
+                    chsize(nLogFD, 0);
+#else
+                    ftruncate(nLogFD, 0);
+#endif
+                    write(nLogFD, errbuf, nWrite);
+                }
+            }
+            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);
+#ifdef WIN32
+            chsize(nLogFD, 0);
+#else
+            ftruncate(nLogFD, 0);
+#endif
+            write (nLogFD, errbuf, nWrite);
         }
-        if (write(nLogFD, buf, nRead) != nRead) {
-            perror(buf2);
-            exit(5);
+        else {
+            nMessCount++;
         }
     }
     /* Of course we never, but prevent compiler warnings */