From nobody Fri Nov 29 05:15:26 2024 X-Original-To: dev-commits-src-all@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 4Y01bL3hk0z5fq8F; Fri, 29 Nov 2024 05:15:26 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y01bL38z9z4jjB; Fri, 29 Nov 2024 05:15:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732857326; 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=qvtpzuXmGGEmUe4HmfokNXba4JQaNhEC6qLSRVWj1Io=; b=eVEM7V9l2VEAIehvZJbkcpQw+njcu/FzX9+7o6RBKa/ReKRGsIQGqQQ+7PwQl/V+Ru4jwE RPFxvNabasjfsf2Xr2ksegEOWc5QnafW8cio1xZ2vHD8ygqaQsav5khtmilmeNARPNYMr+ v2PwUOy0nnjgVGS9tob5cF4U8jJ5mqm1a6LKUymW/kt/807bHyFECom0Ao4LjGTzr8VvRZ 9+il+2SRrw2NxY1ixMcI/C4CbhFW3X0AjCmpj5ys2m8y70GbwfvzjdHMSzegdVTw/tgCtq Lr2/0kuzVN813XFr5JlGRoKuBSGNvPvlCbJYhvCqBy3SkilRaxmQdFXhlt0tCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732857326; 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=qvtpzuXmGGEmUe4HmfokNXba4JQaNhEC6qLSRVWj1Io=; b=ruVqXEDID85963s3TsY1dQ6UrM1jK6TDJEWnH59ieevqp/wFVjNEbFNHH3LyWcdDtS4Jgm dbijuHPg2MrYfabrjLtJnsyksQVhCQjCH4ck6IH4m0SWrltkOW4UphObOEVW1E6dOW3kp2 mjqomHNgNtfN4aVYzFGX162dLvWlG4IJpLxVtPoFdmsWnLzKTag+dzcv3ZJHsdePFGe35f b09uqSAPCjjAegMGSkCOytkP2QY8rWD33NrlR4+K87vUJS+W7bs2mRgwP8lKaxVBrSEyg6 8WRFy32jS4BEq0N+AobkLM136LCAwg1yrwYW3NFSfZLrW9qYwcr7B1Rll95lbg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732857326; a=rsa-sha256; cv=none; b=o1pQuMXO5kHmeLqiTJunfWHw2wTLJGNBbRuZoMQ5VMHxersg1vYzj9PQ9RRkriKXfJ608e iifg8t5at0/UYO7+/m5E2l39p8b4SuYsG9pdfa2g1JU24FwqQ3fxlfAAZk9AKUplxqQOse Fnv9uvd+ijNUFpV80966LIdV41EKNSeKLgSLE/9RiN84i7vkf87049Fot4SSv7QtxVJxA/ t2qeXe0vmJ5OMAP8p06ciyzvjT1qs20TJBEt1nVY4XmxQ/ql9zbA/M2V6J22Q/2LdUrloj uPMY3LHxGPtTrvnmN+zXzcdWjx6s1xmBMfJRJybmOrNhxK+tkWQexrt/P30PkA== 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 4Y01bL2n1Kz18hf; Fri, 29 Nov 2024 05:15:26 +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 4AT5FQC8070851; Fri, 29 Nov 2024 05:15:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AT5FQqX070848; Fri, 29 Nov 2024 05:15:26 GMT (envelope-from git) Date: Fri, 29 Nov 2024 05:15:26 GMT Message-Id: <202411290515.4AT5FQqX070848@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Li-Wen Hsu Subject: git: 0dd21407bd39 - stable/14 - newsyslog.conf(5): Accept human unit suffix in the size filed List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: lwhsu X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 0dd21407bd39c5ff6770ce23ac834bbf35727f94 Auto-Submitted: auto-generated The branch stable/14 has been updated by lwhsu: URL: https://cgit.FreeBSD.org/src/commit/?id=0dd21407bd39c5ff6770ce23ac834bbf35727f94 commit 0dd21407bd39c5ff6770ce23ac834bbf35727f94 Author: K Rin AuthorDate: 2024-11-01 05:12:06 +0000 Commit: Li-Wen Hsu CommitDate: 2024-11-29 05:12:12 +0000 newsyslog.conf(5): Accept human unit suffix in the size filed MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/1505 (cherry picked from commit 1f78bbb5c415efefa782c1be7f9a2e4a5008903b) newsyslog.conf(5): Remove duplicate word Reported by: jlduran Fixes: 1f78bbb5c415 newsyslog.conf(5): Accept human unit suffix in the size filed (cherry picked from commit af2015b01f7e741125aeb4a04109cc42f988cf0f) --- usr.sbin/newsyslog/Makefile | 2 +- usr.sbin/newsyslog/newsyslog.c | 19 ++++++++++++++++--- usr.sbin/newsyslog/newsyslog.conf.5 | 9 ++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/usr.sbin/newsyslog/Makefile b/usr.sbin/newsyslog/Makefile index b2e945b6215a..57881770a901 100644 --- a/usr.sbin/newsyslog/Makefile +++ b/usr.sbin/newsyslog/Makefile @@ -7,7 +7,7 @@ CONFS= newsyslog.conf PROG= newsyslog MAN= newsyslog.8 newsyslog.conf.5 SRCS= newsyslog.c ptimes.c -LIBADD= sbuf +LIBADD= sbuf util HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index c867237d212c..6b21c8e8f855 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -1223,9 +1224,21 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p, badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; - if (isdigitch(*q)) - working->trsize = atoi(q); - else if (strcmp(q, "*") == 0) + if (isdigitch(*q)) { + char last_digit = q[strlen(q) - 1]; + if (isdigitch(last_digit)) + working->trsize = atoi(q); + else { + uint64_t trsize = 0; + if (expand_number(q, &trsize) == 0) + working->trsize = trsize / 1024; + else { + working->trsize = -1; + warnx("Invalid value of '%s' for 'size' in line:\n%s", + q, errline); + } + } + } else if (strcmp(q, "*") == 0) working->trsize = -1; else { warnx("Invalid value of '%s' for 'size' in line:\n%s", diff --git a/usr.sbin/newsyslog/newsyslog.conf.5 b/usr.sbin/newsyslog/newsyslog.conf.5 index b9fdb47fd712..92ccf54732e0 100644 --- a/usr.sbin/newsyslog/newsyslog.conf.5 +++ b/usr.sbin/newsyslog/newsyslog.conf.5 @@ -20,7 +20,7 @@ .\" the suitability of this software for any purpose. It is .\" provided "as is" without express or implied warranty. .\" -.Dd February 26, 2021 +.Dd November 11, 2024 .Dt NEWSYSLOG.CONF 5 .Os .Sh NAME @@ -105,8 +105,10 @@ Specify the maximum number of archive files which may exist. This does not consider the current log file. .It Ar size When the size of the log file reaches -.Ar size -in kilobytes, the log file will be trimmed as described above. +.Ar size , +in kilobytes by default, or with suffixes like k, M, G, ... as supported by +.Xr expand_number 3 , +the log file will be trimmed as described above. If this field contains an asterisk .Pq Ql * , the log file will not be trimmed based on size. @@ -415,6 +417,7 @@ entry: .Xr gzip 1 , .Xr xz 1 , .Xr zstd 1 , +.Xr expand_number 3 , .Xr syslog 3 , .Xr chown 8 , .Xr newsyslog 8 ,