From nobody Tue Oct 28 11:09:07 2025 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 4cwngl6Prwz6Dhtn; Tue, 28 Oct 2025 11:09:07 +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 4cwngl5VmDz3Pdc; Tue, 28 Oct 2025 11:09:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761649747; 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=JMFRPTRYaS6MvtZGWk6EuBsXazOgo1DWV3fZXnHyy48=; b=HoVZGAlT7ijgNaB9QsPG/Y2EBZsVI72ucKAwxNHhwcI8bBW9YbGEU6VpwnpZm9GWRxL9Ke Ps83iO45p6/fMMG38jF4ZaMynesJc9IjCK8hp+4IbMR2Q/64KD0SQTbGDXnN2mcSr1jpes nkCD9k07ClIzRSz5cThHVv6MMn+XxyzcPzT3hPGYlvq0yimHCsz5gdPnn+Mn4jLgF5HoSk fWvlWnYwK4YfNPIBc+yhdzrqVnBtx89DeNwsOFGvh7Q3ucU5K4blOJ9bz3ThayomBOiWax 5E3C2uKIkBfsCu43sV7iFOXrl1jxG9uuUcST97A7IUrSD8owlmAhCpYmN9kKXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761649747; 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=JMFRPTRYaS6MvtZGWk6EuBsXazOgo1DWV3fZXnHyy48=; b=qfk0n9/puVVnTm87BZ7/3ME/74dUt6VZr1VVPR58Vg9lLlYeFTww4duUlZrZWw/wwnE1tY EK4ku4A2ivXcl99HNjLlCgY8NN7lKeHlO6+5dMytYelXZDimtqg8gPWfpBl+51q/HDqMHb gZtC7T6ofJn1yJCLTPhwAsV3WDkWbCLS4TsQ+ehAtYIbLEhAn855YhdtCyenrCmr3t5J5V r0dBT5ii75CsAKPs5Jd3c0DtiqBODj6lsvQhN/tiGkzWdd+KaRnC2p+JB+DcbnwxIlsjEx A+OIAFZlolRa8LIdijqA32oR5YXiItS5++tifTT9ewn+vXXyGKQZrLjuITLl4Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761649747; a=rsa-sha256; cv=none; b=GVyQZwsGTeDnsEAbYGp6KoUagcl0gRu9bQu4XlPJQ4nibhqKceahhy1M/k9gfJoD6if2E1 17dE7fUDaWeD/jCEqIwObfdBK5UOdua3z8jTPE++cE9MdkeNpHgwQH2vd0WY82W6Nbt/83 cRzYhI1Jvbshd5Q956/v3umAfAVMO0vDMgieb0KRg6s8jyup5djDVAUPgDvSbYQUCyrwts OzaVnZx0F3o63icpnRHS4aOtA2O1NV/21uVWfy0wY4Mfvb5M+NBKsS26tQUCzn8JCDosOC lC9GR+589aNmN/rZnuK9R2DH3bMsdCTV/3I7nNCtrzRmFBdeqLoT9FPMOELXSw== 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 4cwngl4dkTznbF; Tue, 28 Oct 2025 11:09:07 +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 59SB979L008603; Tue, 28 Oct 2025 11:09:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59SB973p008600; Tue, 28 Oct 2025 11:09:07 GMT (envelope-from git) Date: Tue, 28 Oct 2025 11:09:07 GMT Message-Id: <202510281109.59SB973p008600@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 5572a45c0f61 - stable/14 - w: Trim whitespace and commas from time and uptime 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: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5572a45c0f6122477e218e54a4b88e63563f3359 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=5572a45c0f6122477e218e54a4b88e63563f3359 commit 5572a45c0f6122477e218e54a4b88e63563f3359 Author: Dag-Erling Smørgrav AuthorDate: 2025-10-23 10:28:44 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-28 11:08:14 +0000 w: Trim whitespace and commas from time and uptime When producing formatted output, trim leading whitespace and trailing commas from the human-readable time and uptime before emitting them. The text output remains unchanged. PR: 290089 Fixes: 6e6febb54da9 ("w: Fix idle time in json output, add login/idle times to json output") Reviewed by: marius.h_lden.org Differential Revision: https://reviews.freebsd.org/D53167 (cherry picked from commit 4d5789532a940144c869d66505e756ce816f8a50) --- usr.bin/w/w.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 69ff8c33cbbf..69387f44449a 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -481,7 +481,7 @@ main(int argc, char *argv[]) static void pr_header(time_t *nowp, int nusers) { - char buf[64]; + char buf[64], *s, *e; struct sbuf upbuf; double avenrun[3]; struct timespec tp; @@ -492,8 +492,15 @@ pr_header(time_t *nowp, int nusers) * Print time of day. */ if (strftime(buf, sizeof(buf), - use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0) - xo_emit("{:time-of-day/%s} ", buf); + use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0) { + s = buf; + if (xo_get_style(NULL) != XO_STYLE_TEXT) { + /* trim leading whitespace */ + while (isspace((unsigned char)*s)) + s++; + } + xo_emit("{:time-of-day/%s} ", s); + } /* * Print how long system has been up. */ @@ -524,21 +531,31 @@ pr_header(time_t *nowp, int nusers) if (days > 0) sbuf_printf(&upbuf, " %ld day%s,", - days, days > 1 ? "s" : ""); + days, days > 1 ? "s" : ""); if (hrs > 0 && mins > 0) sbuf_printf(&upbuf, " %2ld:%02ld,", hrs, mins); else if (hrs > 0) sbuf_printf(&upbuf, " %ld hr%s,", - hrs, hrs > 1 ? "s" : ""); + hrs, hrs > 1 ? "s" : ""); else if (mins > 0) sbuf_printf(&upbuf, " %ld min%s,", - mins, mins > 1 ? "s" : ""); + mins, mins > 1 ? "s" : ""); else sbuf_printf(&upbuf, " %ld sec%s,", - secs, secs > 1 ? "s" : ""); + secs, secs > 1 ? "s" : ""); if (sbuf_finish(&upbuf) != 0) xo_err(1, "Could not generate output"); - xo_emit("{:uptime-human/%s}", sbuf_data(&upbuf)); + s = sbuf_data(&upbuf); + if (xo_get_style(NULL) != XO_STYLE_TEXT) { + e = s + sbuf_len(&upbuf) - 1; + /* trim leading whitespace */ + while (isspace((unsigned char)*s)) + s++; + /* trim trailing comma */ + if (e > s && *e == ',') + *e = '\0'; + } + xo_emit("{:uptime-human/%s}", s); sbuf_delete(&upbuf); }