leak-checker: Stop logging after an output error.
authorBen Pfaff <blp@nicira.com>
Thu, 30 Apr 2009 21:45:30 +0000 (14:45 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 30 Apr 2009 21:45:30 +0000 (14:45 -0700)
In particular it's not polite to continue trying to write to the output
file after ENOSPC, since it will immediately fill up the disk again should
anyone free up any space and keeping the log file open prevents usefully
deleting it.

lib/leak-checker.c

index fbca299d90bcaf1f806c7a1b84bdd4172c1d51ed..83576af25d2b4337a69491429a7765a2d02ef80e 100644 (file)
@@ -168,19 +168,27 @@ reset_hooks(void)
 {
     static int count;
 
-    if (count++ >= 100 && limit && file) {
-        struct stat s;
-        count = 0;
-        if (fstat(fileno(file), &s) < 0) {
-            VLOG_WARN("cannot fstat leak checker log file: %s",
-                      strerror(errno));
-            return;
-        }
-        if (s.st_size > limit) {
-            VLOG_WARN("leak checker log file size exceeded limit");
+    if (file) {
+        if (ferror(file)) {
+            VLOG_WARN("error writing leak checker log file");
             leak_checker_stop();
             return;
         }
+
+        if (count++ >= 100 && limit) {
+            struct stat s;
+            count = 0;
+            if (fstat(fileno(file), &s) < 0) {
+                VLOG_WARN("cannot fstat leak checker log file: %s",
+                          strerror(errno));
+                return;
+            }
+            if (s.st_size > limit) {
+                VLOG_WARN("leak checker log file size exceeded limit");
+                leak_checker_stop();
+                return;
+            }
+        }
     }
     if (file) {
         set_hooks(&our_hooks);