From: Amos Jeffries Date: Sat, 24 Nov 2012 03:41:34 +0000 (-0700) Subject: log_file_daemon: better error reporting X-Git-Tag: SQUID_3_3_0_2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e7b56a14144622e34af285fbbf91b355ffb0e7d;p=thirdparty%2Fsquid.git log_file_daemon: better error reporting Report rotation errors and log file removal errors instead of silently ignoring them. Detected by Coverity Scan. Issue 740316 --- diff --git a/helpers/log_daemon/file/log_file_daemon.cc b/helpers/log_daemon/file/log_file_daemon.cc index 234d4d80b0..5b46c1854c 100644 --- a/helpers/log_daemon/file/log_file_daemon.cc +++ b/helpers/log_daemon/file/log_file_daemon.cc @@ -57,16 +57,24 @@ rotate(const char *path, int rotate_count) snprintf(from, MAXPATHLEN, "%s.%d", path, i - 1); snprintf(to, MAXPATHLEN, "%s.%d", path, i); #if _SQUID_OS2_ || _SQUID_WINDOWS_ - remove(to); + if (remove(to) < 0) { + fprintf(stderr, "WARNING: remove '%s' failure: %s\n", to, xstrerror()); + } #endif - rename(from, to); + if (rename(path, to) < 0 && errno != ENOENT) { + fprintf(stderr, "WARNING: rename '%s' to '%s' failure: %s\n", path, to, xstrerror()); + } } if (rotate_count > 0) { snprintf(to, MAXPATHLEN, "%s.%d", path, 0); #if _SQUID_OS2_ || _SQUID_WINDOWS_ - remove(to); + if (remove(to) < 0) { + fprintf(stderr, "WARNING: remove '%s' failure: %s\n", to, xstrerror()); + } #endif - rename(path, to); + if (rename(path, to) < 0 && errno != ENOENT) { + fprintf(stderr, "WARNING: rename %s to %s failure: %s\n", path, to, xstrerror()); + } } } @@ -119,7 +127,7 @@ main(int argc, char *argv[]) * out of device space - recover by rotating and hoping that rotation count drops a big one. */ if (err == EFBIG || err == ENOSPC) { - fprintf(stderr, "WARNING: %s writing %s. Attempting to recover via a log rotation.\n",strerror(err),argv[1]); + fprintf(stderr, "WARNING: %s writing %s. Attempting to recover via a log rotation.\n",xstrerr(err),argv[1]); fclose(fp); rotate(argv[1], rotate_count); fp = fopen(argv[1], "a");