From owner-dev-commits-src-main@freebsd.org Sun Feb 28 22:32:37 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4158A54DC70; Sun, 28 Feb 2021 22:32:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DpdSP1MFVz3JMv; Sun, 28 Feb 2021 22:32:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2183418E9C; Sun, 28 Feb 2021 22:32:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 11SMWbre013272; Sun, 28 Feb 2021 22:32:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11SMWbuq013271; Sun, 28 Feb 2021 22:32:37 GMT (envelope-from git) Date: Sun, 28 Feb 2021 22:32:37 GMT Message-Id: <202102282232.11SMWbuq013271@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Juraj Lutter Subject: git: c7d27b225df8 - main - newsyslog(8): Implement a new 'E' flag to not rotate empty log files MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: otis X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c7d27b225df8d7fb36a31a21737d4309593c4604 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Feb 2021 22:32:37 -0000 The branch main has been updated by otis (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=c7d27b225df8d7fb36a31a21737d4309593c4604 commit c7d27b225df8d7fb36a31a21737d4309593c4604 Author: Juraj Lutter AuthorDate: 2021-02-28 22:07:14 +0000 Commit: Juraj Lutter CommitDate: 2021-02-28 22:32:19 +0000 newsyslog(8): Implement a new 'E' flag to not rotate empty log files Based on an idea from dvl's coworker, László DANIELISZ, implement a new flag, 'E', that prevents newsyslog(8) from rotating the empty log files. This 'E' flag ist mostly usable in conjunction with 'B' flag that instructs newsyslog(8) to not insert an informational message into the log file after rotation, keeping it still empty. Reviewed by: markj, ian, manpages (rpokala) Approved by: markj, ian, manpages (rpokala) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D28940 --- usr.sbin/newsyslog/newsyslog.c | 11 ++++++++++- usr.sbin/newsyslog/newsyslog.conf.5 | 14 +++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index dc3ea51c8032..8f8bb54e9b46 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -114,7 +114,8 @@ __FBSDID("$FreeBSD$"); #define CE_PID2CMD 0x0400 /* Replace PID file with a shell command.*/ #define CE_PLAIN0 0x0800 /* Do not compress zero'th history file */ #define CE_RFC5424 0x1000 /* Use RFC5424 format rotation message */ - +#define CE_NOEMPTY 0x2000 /* Do not rotate the file when its size */ + /* is zero */ #define MIN_PID 5 /* Don't touch pids lower than this */ #define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */ @@ -531,6 +532,11 @@ do_entry(struct conf_entry * ent) printf("does not exist, skipped%s.\n", temp_reason); } } else { + if (ent->flags & CE_NOEMPTY && ent->fsize == 0) { + if (verbose) + printf("--> Not rotating empty file\n"); + return (free_or_keep); + } if (ent->flags & CE_TRIMAT && !force && !rotatereq && !oversized) { diffsecs = ptimeget_diff(timenow, ent->trim_at); @@ -1291,6 +1297,9 @@ no_trimat: case 'd': working->flags |= CE_NODUMP; break; + case 'e': + working->flags |= CE_NOEMPTY; + break; case 'g': working->flags |= CE_GLOB; break; diff --git a/usr.sbin/newsyslog/newsyslog.conf.5 b/usr.sbin/newsyslog/newsyslog.conf.5 index d6b1191aa8b2..b897389b99dd 100644 --- a/usr.sbin/newsyslog/newsyslog.conf.5 +++ b/usr.sbin/newsyslog/newsyslog.conf.5 @@ -21,7 +21,7 @@ .\" the suitability of this software for any purpose. It is .\" provided "as is" without express or implied warranty. .\" -.Dd August 21, 2018 +.Dd February 26, 2021 .Dt NEWSYSLOG.CONF 5 .Os .Sh NAME @@ -286,6 +286,18 @@ this log file. This option would affect how the .Xr dump 8 command treats the log file when making a file system backup. +.It Cm E +indicates that the log file should not be rotated when its +size is zero. +The +.Cm E +flag is mostly useful in conjunction with +.Cm B +flag to prevent +.Xr newsyslog 8 +from inserting an informational +.Tn ASCII +message into the new file. .It Cm G indicates that the specified .Ar logfile_name