Hi David,
> --- newsyslog.c.bak Thu Oct 22 21:18:12 2009
> +++ newsyslog.c Thu Oct 22 22:00:09 2009
> @@ -756,6 +756,9 @@
> char file1[MAXPATHLEN], file2[MAXPATHLEN], *suffix;
> int numdays = ent->numlogs;
>
> + /* We start counting at 0 so reduce for correct maximum */
> + numdays--;
> +
> /* 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,
That does part of the job, but looks slightly ugly.
When applied to a running system, it lets the excessive archive file
sit around forever, or until you manually delete it.
I like the following better:
Remove all _consecutive_ archive files above the requested limit.
That's also useful after lowering the "count" in newsyslog.conf.
Note that the loop may be terminated earlier when rotating for real
than in -n mode; specifically, when unlink() fails.
But that's fine because -n is supposed to tell you what would be tried.
Of course, what you try to do may still fail.
Any OKs?
Index: newsyslog.c
===================================================================
RCS file: /cvs/src/usr.bin/newsyslog/newsyslog.c,v
retrieving revision 1.86
diff -u -p -r1.86 newsyslog.c
--- newsyslog.c 27 Oct 2009 23:59:40 -0000 1.86
+++ newsyslog.c 10 Jan 2010 00:36:43 -0000
@@ -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 - 1; 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