Bug 282639 - newsyslog may "double rotate" logs with duplicate rules
Summary: newsyslog may "double rotate" logs with duplicate rules
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Alexander Ziaee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-11-09 01:42 UTC by Josef 'Jeff' Sipek
Modified: 2026-02-16 01:05 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Josef 'Jeff' Sipek 2024-11-09 01:42:35 UTC
Recently, I set up a new jail to handle my email and so I wanted to increase the number of rotated maillogs to 60 days (from the default 7).  I tried to be clever by creating /usr/local/etc/newsyslog.conf.d/maillog.conf with the following line in it:

/var/log/maillog			640  60	   *	@T00  JC

and I keeping the maillog entry in /etc/newsyslog.conf alone.

I assumed that the .d snippet would *override* the line from the main config file.

What ended up happening was that *every* rotated maillog would look like:

# bzcat maillog.20241019T000000.bz2
Oct 19 00:00:00 smtp newsyslog[33052]: logfile turned over
Oct 19 00:00:00 smtp newsyslog[33052]: logfile turned over

I believe that what happened is that newsyslog rotated the log twice every night - first based on the /etc/newsyslog.conf rule and then based on the /usr/local/etc/newsyslog.conf.d/maillog.conf rule.  Since there were no log messages from postfix during the few milliseconds between rotations, the log only had the newsyslog markers when it got rotated for the second time and the actual log contents from the first log rotation of the night got lost.

(I like timestamp-based log rotation, and so my /etc/crontab has `newsyslog -t DEFAULT`.  It is possible that using the regular integer suffixes would have resulted in every-other-log still containing the log messages from the day.  I haven't tested it.)
Comment 1 Michael Osipov freebsd_committer freebsd_triage 2024-11-09 20:47:34 UTC
What is the actual bug you are trying to report?
Comment 2 Josef 'Jeff' Sipek 2024-11-09 21:02:36 UTC
Specifying the same log file name multiple times (across newsyslog.d/*.conf snippets) doesn't result in a single log rotation - it results in the same log getting rotated multiple times resulting in log data loss since the previous rotated log is overwritten by the second/third/etc. rotation.
Comment 3 Josef 'Jeff' Sipek 2024-11-09 21:06:40 UTC
Btw, this multi-rotation happens completely silently and there is no indication that something like that is happening.

I expected one of these instead:

1. take the last entry for each log file name
2. warn if there are multiple instances of the same log file name
Comment 4 Michael Osipov freebsd_committer freebsd_triage 2024-11-09 21:38:30 UTC
(In reply to Josef 'Jeff' Sipek from comment #3)

Well, neither is documented in the manpage, I'd say that the behavior you have is undefined.
Comment 5 Josef 'Jeff' Sipek 2024-11-09 22:05:13 UTC
Agreed.  It is currently undefined.

IMO it'd be a good thing to allow the "overriding" behavior to make config management easier - rewriting existing files is always more painful than being able to drop a fragment into a .d directory.

So, I suppose this ticket is a request to define a behavior - I don't really care how it is defined, but (the current undefined behavior of) silent log file loss is a bad.
Comment 6 Mark Felder freebsd_committer freebsd_triage 2026-02-02 01:04:34 UTC
I've run into this too. The "overriding" behavior that is desired would be nice because then we don't have to manage /etc/newsyslog.conf to change how e.g., maillog is rotated.

Documenting the current behavior in the man page should be the first step
Comment 7 commit-hook freebsd_committer freebsd_triage 2026-02-12 14:15:25 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=64e612b46290617ec753b4ee6ec633a3724940e3

commit 64e612b46290617ec753b4ee6ec633a3724940e3
Author:     Alexander Ziaee <ziaee@FreeBSD.org>
AuthorDate: 2026-02-12 14:14:47 +0000
Commit:     Alexander Ziaee <ziaee@FreeBSD.org>
CommitDate: 2026-02-12 14:14:48 +0000

    newsyslog.conf.5: Add a CAVEAT

    PR:                     282639
    MFC after:              3 days
    Reviewed by:            michaelo
    Differential Revision:  https://reviews.freebsd.org/D55122

 usr.sbin/newsyslog/newsyslog.conf.5 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 8 Alexander Ziaee freebsd_committer freebsd_triage 2026-02-14 02:08:01 UTC
Okay, thanks for tagging me! I documented this in the reference manual. Current policy is that "someone else should improve this" bugs are not bugs and impose a burden on bugmeister, so I'm going to close it as fixed. If you think this is an error please reopen.
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-02-16 00:24:32 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=817f0b88ff3f03d580e187d2c5910c21c88c33c9

commit 817f0b88ff3f03d580e187d2c5910c21c88c33c9
Author:     Alexander Ziaee <ziaee@FreeBSD.org>
AuthorDate: 2026-02-12 14:14:47 +0000
Commit:     Alexander Ziaee <ziaee@FreeBSD.org>
CommitDate: 2026-02-16 00:23:30 +0000

    newsyslog.conf.5: Add a CAVEAT

    PR:                     282639
    MFC after:              3 days
    Reviewed by:            michaelo
    Differential Revision:  https://reviews.freebsd.org/D55122

    (cherry picked from commit 64e612b46290617ec753b4ee6ec633a3724940e3)

 usr.sbin/newsyslog/newsyslog.conf.5 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2026-02-16 01:05:56 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=17da2d24b7af843739be6b3d9ce244f511cde2ee

commit 17da2d24b7af843739be6b3d9ce244f511cde2ee
Author:     Alexander Ziaee <ziaee@FreeBSD.org>
AuthorDate: 2026-02-12 14:14:47 +0000
Commit:     Alexander Ziaee <ziaee@FreeBSD.org>
CommitDate: 2026-02-16 01:03:29 +0000

    newsyslog.conf.5: Add a CAVEAT

    PR:                     282639
    MFC after:              3 days (resolved merge conflicts)
    Reviewed by:            michaelo
    Differential Revision:  https://reviews.freebsd.org/D55122

    (cherry picked from commit 64e612b46290617ec753b4ee6ec633a3724940e3)

 usr.sbin/newsyslog/newsyslog.conf.5 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)