From 8a462aa5f9340b87853ff3f94cce3c84ebb059cc Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 30 Apr 2009 14:45:30 -0700 Subject: [PATCH] leak-checker: Stop logging after an output error. 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 | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/leak-checker.c b/lib/leak-checker.c index fbca299d..83576af2 100644 --- a/lib/leak-checker.c +++ b/lib/leak-checker.c @@ -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); -- 2.30.2