diff options
author | gad <gad@FreeBSD.org> | 2003-05-05 23:38:03 +0000 |
---|---|---|
committer | gad <gad@FreeBSD.org> | 2003-05-05 23:38:03 +0000 |
commit | f191592855ce0c76451ec38fca54dfa09e3eb920 (patch) | |
tree | 74954672677a7bd032c7562bfc1dd400ad51e779 | |
parent | df429f4699c1360689b59e8c2440ab71c5c80656 (diff) | |
download | FreeBSD-src-f191592855ce0c76451ec38fca54dfa09e3eb920.zip FreeBSD-src-f191592855ce0c76451ec38fca54dfa09e3eb920.tar.gz |
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
-rw-r--r-- | usr.sbin/newsyslog/newsyslog.c | 23 |
1 files changed, 19 insertions, 4 deletions
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); } |