From nobody Fri Nov 29 05:21:32 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 4Y01kP4Dpqz5fqL6; Fri, 29 Nov 2024 05:21:33 +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 4Y01kP3G8zz4jlS; Fri, 29 Nov 2024 05:21:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732857693; 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=zv2aYxksfDJXEWfbqtaE4EI5EpVOfaa98KGQNuD/wz4=; b=S1Z4CMw2cf7clfxDkPEkRijDwF25VNvjRh70qKYBmXeXBDzCWedHqFqYYrJStLEK7doVL/ yg3eec6Q7pPc2BkmycYdFOUY2aeWMYst3AIQaDC6JqQC7Cm1orHDvvM8fmKSlFmdFF3ZHS 7sNo116fucKD5aD8oC7e0YipvHv6KTY623MFOrIJW4BvPP/CiEp5NE0d2rTpjf+a5cup3S 6mJ+HTEOp51oaOYn5dhZQSyKM2tRS8/o3obtQHARODeNazX4gQFndQ876+7ofuJ7IP5wIk 3XnBG4ItAVqb7mGG95+VKXH/1fHi8EwSkhZ2Qowo5ZvkryvaTTx/JL1feEuYzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732857693; 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=zv2aYxksfDJXEWfbqtaE4EI5EpVOfaa98KGQNuD/wz4=; b=tUs0uIAPY7riMfL3/PVj2yknEefYfnuz9vpQ4dW/6CtXoh/v6i+weUkRR1Vor22RamNAfu p/fnlZBpup/vDJlxP/kVezmlgE44uVrtaYfxhJKuxULKVgQlaoxQ4Cg1sr35K1UpZ1xEtd 4afDLXfYS5yJ/kmh+vSePq0unBSAsTNTSXkf6u4JmShtuviwqcL2X5kBivqbh9WPcFzSRp hIDEb08tWUJaW4SJxiw2IT6tGbUL9M1HtfuV5dpkuEccJjJ9a3qipCZbqtvJiW1TDeCE/K +P2cbK7YPUbHuvG0IDwDXhRshokEwJFzo2ylAwMhJZaKfqSXIKRV2E6kJHNCvg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732857693; a=rsa-sha256; cv=none; b=s5Xkxm3DjW7XwdePzXlannXHljJwmRUdx+kMz9tDkPz6izcCK/gImvlnbKYHxT0d4Lelz0 jl5jwCO2sTVixLRwByDc/DNbub82NRgxC7lsL/FvpNoztT841OOM5I+oB6mND1MfVcM9cL vBMdAGJBWSTU8eAhV5hia2cHllVDxT5NyjV0wNoYbMhoP3K2UJBiyv25bmu3q9vzEELsr9 RR9W67mZTMmYmsdSDDBZv/gqdNGv8aHxKGmaT7RjB2dFe632FtG+v1wB+k/1CDXc7M3CWW 8JZQsQ5/RzTlYnM21KKcMSRQwwC+5FEBK13O74H+/cSHu0ItPA7YLGd1k3+5rw== 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 4Y01kP0QpDz192R; Fri, 29 Nov 2024 05:21:33 +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 4AT5LWXp083497; Fri, 29 Nov 2024 05:21:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AT5LWfM083494; Fri, 29 Nov 2024 05:21:32 GMT (envelope-from git) Date: Fri, 29 Nov 2024 05:21:32 GMT Message-Id: <202411290521.4AT5LWfM083494@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: 1bfd6cb606da - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 1bfd6cb606da39604ea70e1e5fe8d28534010f99 Auto-Submitted: auto-generated The branch stable/13 has been updated by lwhsu: URL: https://cgit.FreeBSD.org/src/commit/?id=1bfd6cb606da39604ea70e1e5fe8d28534010f99 commit 1bfd6cb606da39604ea70e1e5fe8d28534010f99 Author: K Rin AuthorDate: 2024-11-01 05:12:06 +0000 Commit: Li-Wen Hsu CommitDate: 2024-11-29 05:20:41 +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 115192058c82..a043e891aba0 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 0a516fc56785..fd23837a3990 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. @@ -414,6 +416,7 @@ entry: .Xr bzip2 1 , .Xr gzip 1 , .Xr xz 1 , +.Xr expand_number 3 , .Xr syslog 3 , .Xr chown 8 , .Xr newsyslog 8 ,