From f191592855ce0c76451ec38fca54dfa09e3eb920 Mon Sep 17 00:00:00 2001 From: gad Date: Mon, 5 May 2003 23:38:03 +0000 Subject: Fix age_old_log checking so that it will notice log files which were rotated and then compressed with bzip2 instead of gzip. Otherwise, any file which had a time-interval specified for 'when' and also specified the 'J' flag would be rotated every time newsyslog was run. (this is a quick-fix, trying to beat the code-freeze for 5.1-release) PR: bin/51519 MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'usr.sbin/newsyslog') diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index d70d744..b9abb78 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -1468,7 +1468,9 @@ static int age_old_log(char *file) { struct stat sb; - char tmp[MAXPATHLEN + sizeof(".0") + sizeof(COMPRESS_POSTFIX) + 1]; + char *endp; + char tmp[MAXPATHLEN + sizeof(".0") + sizeof(COMPRESS_POSTFIX) + + sizeof(BZCOMPRESS_POSTFIX) + 1]; if (archtodir) { char *p; @@ -1497,9 +1499,22 @@ age_old_log(char *file) (void) strlcpy(tmp, file, sizeof(tmp)); } - if (stat(strcat(tmp, ".0"), &sb) < 0) - if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0) - return (-1); + strlcat(tmp, ".0", sizeof(tmp)); + if (stat(tmp, &sb) < 0) { + /* + * A plain '.0' file does not exist. Try again, first + * with the added suffix of '.gz', then with an added + * suffix of '.bz2' instead of '.gz'. + */ + endp = strchr(tmp, '\0'); + strlcat(tmp, COMPRESS_POSTFIX, sizeof(tmp)); + if (stat(tmp, &sb) < 0) { + *endp = '\0'; /* Remove .gz */ + strlcat(tmp, BZCOMPRESS_POSTFIX, sizeof(tmp)); + if (stat(tmp, &sb) < 0) + return (-1); + } + } return ((int)(timenow - sb.st_mtime + 1800) / 3600); } -- cgit v1.1