From: Amos Jeffries Date: Thu, 29 Nov 2012 11:20:58 +0000 (-0700) Subject: log_file_daemon: better error reporting X-Git-Tag: SQUID_3_2_4~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b946f0a41b25ef547e120ce1f62f45dec6174392;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 ee4c7c0008..aa946fd9cb 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");