summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-03-20 15:15:46 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-03-20 15:15:46 +0000
commit61155e02bcb5b386720fa147e1e57b3bebfb427a (patch)
treeedc997c1dc80291043ba9fb7c4816071791bc176 /usr.bin
parent25ee8c5b80130a3d64b99dd5922b960c4b20a196 (diff)
The newsyslog(8) utility used to keep one archived log file more than
requested; bug reported and patch sent by David Alten. I resolved the problem in a different way, also fixing the following additional issue: When you reduced the "count" in newsyslog.conf(5), the archived logs with higher numbers got orphaned and never deleted. Nic fixed another off-by-one error in this patch, thanks! "I like it; definitely cleaner" DAlten at friedkin dot com ok nicm@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/newsyslog/newsyslog.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/usr.bin/newsyslog/newsyslog.c b/usr.bin/newsyslog/newsyslog.c
index 84b65c74536..d1ef7024186 100644
--- a/usr.bin/newsyslog/newsyslog.c
+++ b/usr.bin/newsyslog/newsyslog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newsyslog.c,v 1.86 2009/10/27 23:59:40 deraadt Exp $ */
+/* $OpenBSD: newsyslog.c,v 1.87 2010/03/20 15:15:45 schwarze Exp $ */
/*
* Copyright (c) 1999, 2002, 2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -750,22 +750,25 @@ void
rotate(struct conf_entry *ent, const char *oldlog)
{
char file1[MAXPATHLEN], file2[MAXPATHLEN], *suffix;
- int numdays = ent->numlogs;
+ int numdays = ent->numlogs - 1;
+ int done = 0;
- /* Remove oldest log (may not exist) */
- (void)snprintf(file1, sizeof(file1), "%s.%d", oldlog, numdays);
- (void)snprintf(file2, sizeof(file2), "%s.%d%s", oldlog, numdays,
- COMPRESS_POSTFIX);
-
- if (noaction) {
- printf("\trm -f %s %s\n", file1, file2);
- } else {
- (void)unlink(file1);
- (void)unlink(file2);
- }
+ /* Remove old logs */
+ do {
+ (void)snprintf(file1, sizeof(file1), "%s.%d", oldlog, numdays);
+ (void)snprintf(file2, sizeof(file2), "%s.%d%s", oldlog,
+ numdays, COMPRESS_POSTFIX);
+ if (noaction) {
+ printf("\trm -f %s %s\n", file1, file2);
+ done = access(file1, 0) && access(file2, 0);
+ } else {
+ done = unlink(file1) && unlink(file2);
+ }
+ numdays++;
+ } while (done == 0);
/* Move down log files */
- while (numdays--) {
+ for (numdays = ent->numlogs - 2; numdays >= 0; numdays--) {
/*
* If both the compressed archive and the non-compressed archive
* exist, we decide which to rotate based on the CE_COMPACT flag