From nobody Sun Sep 28 14:55:11 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cZS6R6D9Cz68pqw; Sun, 28 Sep 2025 14:55:11 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cZS6R3vZFz3nPH; Sun, 28 Sep 2025 14:55:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759071311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2t6c+ZHwPceSJDTQDTQ7Ou46u5yeqC+nrVcoR3cEryA=; b=WdQKRtBlPs5QWIFDxgIEVMJSN2f29NrUnDpZORZDnw5EkBmUGsP8m8E3s1/Hke0Bjw28JD DMYODmnhuWZSkLFUsIjEBO6GoAWeiA/4EUyR0s3SohKctT7XX9bbHR6+lPSxFBASP/tTYe WMVX8g44kI8oK0ymCADfzRNLqlZnNUEqsrw93NTwOnGa8In5NAVz6RLIltc7EIv8uhBipv ++LB2maDa6Fgk3RTZ0k0pZsZkfhiO9jczV88Rfefs/ko9/gOjoM1FUq5jS8hqfT6tfrfAJ /hi2D1mjT75V9q+jLa/aRDzLvBI0LaLOZhEESPOcSgHDzIEH+bGP1vPPBvfAlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759071311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2t6c+ZHwPceSJDTQDTQ7Ou46u5yeqC+nrVcoR3cEryA=; b=pdebBEBADi4W8tpA1jx+f90GjFYRqM50uDTOiyc8kEXrQAzxy+VUMV+ivcCsrI9uKUBch9 sOrb51PHu6ts0GXa5ov0EZIfsthKbuTYofLzkXeYb53DSjVJfyqq6nqkxalNshnA0hZWvI 4j+SSvp8BL8mKBVxLqYmyXCe53fDQLEdHzgfisnItSEku40HRLr9HeyT1uExKtMgVN4Q0K S5EjJkAddCGuExzaiIh5UgdCqGylA6LOLpMu4cWNxoBWKqIGXfrjDBTIhUp71WM1HTaTv2 +MsDo0HwKyfs/h7GTEhkPYCP72Ohuql8nPq2U9zCGV/nN4Bv3fRARV1KUS3Prg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759071311; a=rsa-sha256; cv=none; b=kpqzSAec9u41IZ+Vb4cQC2zCHgundL44zQPnmCb1XvMDS83W/3MYc+c4vAS5f9sxhIBodC zHptNEG5IZPVMZTwFvHUxtfS5LtEKPJotMhUEwbZWQDwRmAarQM8Q5lcsmHWgeo4shF1rG Ds/AF/nlbj0gEqXdWFsKHUwYbl1OZcu0urhtmlsLN8q2LijHfp6Aohvpp0IooY+0xWU1TD ytH8omP7ONvV6FKetfIlelOlrvlMHHOmAlh9pBFVHiVv96/whcokzqXY9VgGu0RvT5c5lQ 5YNh8nSHCH6Pdwo5INJUj1Dq8xxHkGTmFrHwHhsZisdmdGPBIDVeB3SHF8skAA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cZS6R1qtdz8wB; Sun, 28 Sep 2025 14:55:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58SEtB0h045207; Sun, 28 Sep 2025 14:55:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58SEtB3P045204; Sun, 28 Sep 2025 14:55:11 GMT (envelope-from git) Date: Sun, 28 Sep 2025 14:55:11 GMT Message-Id: <202509281455.58SEtB3P045204@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: bbec2c9a6d9a - main - newsyslog: fix one hour rotation with frequent execution List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bbec2c9a6d9a9b8f6c6edbdd2386dfdcd1c81422 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=bbec2c9a6d9a9b8f6c6edbdd2386dfdcd1c81422 commit bbec2c9a6d9a9b8f6c6edbdd2386dfdcd1c81422 Author: Gleb Smirnoff AuthorDate: 2025-09-28 14:54:53 +0000 Commit: Gleb Smirnoff CommitDate: 2025-09-28 14:54:53 +0000 newsyslog: fix one hour rotation with frequent execution If a newsyslog.conf(5) has an entry that is configured to be rotated every hour, and crontab(8) is set to execute newsyslog several times per hour, the logic of age_old_log() is broken and it would rotate the entry too often. AFAIU, the extra 1800 seconds were added to allow some leeway for the previous newsyslog invocation, that could have been too slow and the timestamp on the old file is newer than actual time of the previous newsyslog invocation. But 30 minutes of leeway is way to much. Reduce this down to 3 minutes, which would be a compromise between a potential need to run newsyslogd every 5 minutes and a situation when newsyslog takes a significant time to rotate the logs. Provide a test case for that. Reviewed by: delphij Differential Revision: https://reviews.freebsd.org/D52700 --- usr.sbin/newsyslog/newsyslog.c | 2 +- usr.sbin/newsyslog/tests/legacy_test.sh | 53 ++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index 90b9c8d716a5..084aeb36b052 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -2615,7 +2615,7 @@ age_old_log(const char *file) mtime = sb.st_mtime; } - return ((int)(ptimeget_secs(timenow) - mtime + 1800) / 3600); + return ((int)(ptimeget_secs(timenow) - mtime + 180) / 3600); } /* Skip Over Blanks */ diff --git a/usr.sbin/newsyslog/tests/legacy_test.sh b/usr.sbin/newsyslog/tests/legacy_test.sh index c8c18a754977..ea0b0c6fc726 100644 --- a/usr.sbin/newsyslog/tests/legacy_test.sh +++ b/usr.sbin/newsyslog/tests/legacy_test.sh @@ -417,6 +417,51 @@ tests_time_rotate() { tmpdir_clean } +tests_interval_rotate() { + local hours ext h + + hours="$1" + ext="$2" + + tmpdir_create + + begin "create file" -newdir + run_newsyslog -C + ckfe ${LOGFNAME} + end + + # old file doesn't exist - forced rotation + begin "rotate interval 0" + run_newsyslog + ckfe ${LOGFNAME} + chkfcnt 1 ${dir}${LOGFNAME}.* + end + + # emulate newsyslog runs every 5 minutes + begin "rotate interval less than ${hours} hours" + m=0 + while [ $(expr ${m} / 60 ) -lt ${hours} ]; do + touch -t $(date -v -${m}M +%Y%m%d%H%M) ${LOGFNAME}.0 + run_newsyslog + ckfe ${LOGFNAME} + chkfcnt 1 ${dir}${LOGFNAME}.* + if [ $OK != 1 ]; then + break; + fi + m=$(expr ${m} + 5) + done + end + + begin "rotate interval ${hours} hours" + touch -t $(date -v -${hours}H +%Y%m%d%H%M) ${LOGFNAME}.0 + run_newsyslog + ckfe ${LOGFNAME} + chkfcnt 2 ${dir}${LOGFNAME}.* + end + + tmpdir_clean +} + tests_rfc5424() { local dir ext name_postfix newsyslog_args @@ -526,7 +571,7 @@ tests_normal_rotate_recompress() { tmpdir_clean } -echo 1..185 +echo 1..193 mkdir -p ${TMPDIR} cd ${TMPDIR} @@ -638,4 +683,10 @@ tests_p_flag_rotate ".gz" echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf tests_normal_rotate_recompress +# Interval based rotation +echo "$LOGFPATH 640 3 * 1 NC" > newsyslog.conf +tests_interval_rotate 1 +echo "$LOGFPATH 640 3 * 2 NC" > newsyslog.conf +tests_interval_rotate 2 + rm -rf "${TMPDIR}"