From nobody Thu Nov 21 05:40:58 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 4Xv6XV5BHYz5fGXB; Thu, 21 Nov 2024 05:40:58 +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 4Xv6XV4kdvz4pBp; Thu, 21 Nov 2024 05:40:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732167658; 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=j4TVAqQ1JH9eNwWrXvDMQl4zHZns6jcoclim4TEdMjU=; b=TC8ULldohhspdDPZYZEq/udMtIdkkoJK5qiYemU/xEETqFo8/qiEn2itzdXqSi4r/nRRHB uCMCrZycXUL8OMt7wG8KK/S32LJczXbh2nMQsi6dvTQsCAJPGlSyH4l4gFccXsXae61fVF migjyge/5Ml6ZL5KwZm1pnecmwN4SekhMTTEDOg6vnTR1s5DXrL5Pa6OSxtgpIvJbjNITr KUrR+1Gr12vqooOoSJ4gQ66kWinq2cJakoHkZxSsGm8zSBhAdxdV/iPSzXt/0D1kVGc83R 7elywrC6iyi5ZpGY2Z//KNNZdQ8Mg7WrruDc4SNshL6sGztsguvsWRJq7Eo4rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732167658; 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=j4TVAqQ1JH9eNwWrXvDMQl4zHZns6jcoclim4TEdMjU=; b=JqSgSpU80x0ku6nJ1WdEJj7UifcgGB5eJdGFYlR4+SbCLMpU0jFf3mAiyKWGlbi6PNZGQB HKxndEa9DgD+bl6RK219+VVeVj5dzWhnQZfk48yfIJx54XJyAAwLGOI+hSs0iBTRtFCq6R SIsUEdkNh4kObgFqKDd0l+hNVZgUiwZR4IRveRSrWE9Yl9WQiKlwSEe8DitQTaVm8jL3xx RZhbQAxURsohRZNhvaB53q0Kb9eJDF2vH6FEN2FurdmGYyhJLC7/s5FMzfOj8u8ItZpUdh t1OtzUPWtHXjvlyvSWvrfD4BxEGlCo8H2iOvC7DFcI5uEtw2ue2/OqFVUnWTaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732167658; a=rsa-sha256; cv=none; b=DlRyELsDE7kzmCcyfJ4Dt36XRGTiCKMPIqIENJ/2KSoXOefQ+ylLan9nNhBw3dGKLoT9QF sCrkAnay4ycyBgDSfHXicUSGo5kzMKvpt34Yf8EMvhD3vrc7JCUv4fuylFoAJV73lY4SzB N2bqW4tLlbZGfO5hEcC70lc/eh8cnR1gA6emqRVQL9H8mCdODxTNvtFR+yHs03UTVcHcxd wquAjin/dq6mHTztv1hycLytDzFmvLSoc4aLNMI2X4RCVdH0DofnhsjdEK+LgrSVwlVnQQ FajRuphlked/6qttuSGJ3RLZNJbh11Cf+1425BHSEedaY4RhY3KB5qRg2kT59g== 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 4Xv6XV4Km6zR5T; Thu, 21 Nov 2024 05:40:58 +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 4AL5ewd5013449; Thu, 21 Nov 2024 05:40:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AL5ewVl013446; Thu, 21 Nov 2024 05:40:58 GMT (envelope-from git) Date: Thu, 21 Nov 2024 05:40:58 GMT Message-Id: <202411210540.4AL5ewVl013446@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Li-Wen Hsu Subject: git: 1f78bbb5c415 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 1f78bbb5c415efefa782c1be7f9a2e4a5008903b Auto-Submitted: auto-generated The branch main has been updated by lwhsu: URL: https://cgit.FreeBSD.org/src/commit/?id=1f78bbb5c415efefa782c1be7f9a2e4a5008903b commit 1f78bbb5c415efefa782c1be7f9a2e4a5008903b Author: K Rin AuthorDate: 2024-11-01 05:12:06 +0000 Commit: Li-Wen Hsu CommitDate: 2024-11-21 05:39:09 +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 --- 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 0afbe3b814a7..26ff30d4a0b3 100644 --- a/usr.sbin/newsyslog/Makefile +++ b/usr.sbin/newsyslog/Makefile @@ -6,7 +6,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 e9b84bae342d..d07f302fd24f 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -1335,9 +1336,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 a8ab132edaa8..a9deb079e294 100644 --- a/usr.sbin/newsyslog/newsyslog.conf.5 +++ b/usr.sbin/newsyslog/newsyslog.conf.5 @@ -18,7 +18,7 @@ .\" the suitability of this software for any purpose. It is .\" provided "as is" without express or implied warranty. .\" -.Dd December 25, 2023 +.Dd November 11, 2024 .Dt NEWSYSLOG.CONF 5 .Os .Sh NAME @@ -116,8 +116,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 suffix 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. @@ -438,6 +440,7 @@ entry: .Xr gzip 1 , .Xr xz 1 , .Xr zstd 1 , +.Xr expand_number 3 , .Xr syslog 3 , .Xr chown 8 , .Xr newsyslog 8 ,