From nobody Tue Sep 16 13:59:13 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 4cR3RP658rz67JpJ; Tue, 16 Sep 2025 13:59:13 +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 4cR3RP47spz3XC9; Tue, 16 Sep 2025 13:59:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758031153; 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=YsjAkt+zPlBfNYhYmxX1t8AtvE4unTNnf6KiaTZepXs=; b=xsyZq61m/1l1kXlHuPOdgQP0vVE23bxy86pQw/QDfiXu6F+ga452eZVLCTWErITjPBJP4J bDMDJGr2yNYwFASb4rVZEFe45vt7OpfMBwFg8DuigHT+0QAaB/+ZF1y1RtAjkI4bS6d73O i3FNhDz60nabxzusJ1osI/4cMYw4+pZeYawRz6J30dABtIyTX/wYqLFeeIZKlI+kFtW0Kk S/kmU56QgV0a9KzmIkghQLw2jQqBgPOx/3+qZLewSggEeqZfwOdfz0hkk1yWO0F6KvMPAc x7731Tn1325Rm6pyE3vrQJ4k3d3poG2X38BMhavZWzJphwU5aXM3RTo171Zc5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758031153; 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=YsjAkt+zPlBfNYhYmxX1t8AtvE4unTNnf6KiaTZepXs=; b=h2w8bD/CYQxA4CJqabRXLc/pF2Eg8lj+D6xgDZ3Cqg8LusrycSTV6zVi4iweEoUyTgX1xx 525lwPukFVOR0l4OIWMaFxyHYEEuGPJoDWlVnicbp4bTYHxIgTP4ItR12Z6MKSFcfNExRa 4tnbIHiq7yY3hkn42XWWtGE3TWrWyQOBbJZ9ojoMLnl/gX2L73KcZPTj1Z4P0R81AUB4jg fXGZAoUsCVHAFuQb0qTWGGc3vPKHRESN2UPmlBStF/4brndcWtvXE3VXikSRdCOsCphT8W rH0TRdKI/dkJrFU3opE3u2GVm4PuN6CQFiGNCWZY5K0mOJthVEFps14h/DVDMA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758031153; a=rsa-sha256; cv=none; b=i6F2eNTUhltBGBeBnJkCcVt5MaQeV33Kl0gR1eBhZYFFZ3XgE6KY8w0G+MZse4TkNc2zx2 +EwMu2vebuE8g4n1DFCGYMKp7U2IGYE2+TMLw2baUZw0nKpBJC68cGUO1XueCrsbh8TTcI BTIUJBQCZ33r+Dr00REXw0Yo9kriZvivnt04BkvfS/R+GWsKNtk/secxMJIOeNv+ppIi3g SqaMi5fyRukud3C5StmYXgq+XiQrzkT7IctbmKCI4NsYJQymsaGQNnY1OvP/CtoV35KZY5 gFjeIGe2QJv9abZw+6ruV+MqL3Zbdslag6GrjoA5oHkfwsL/jbfTtOIOwV9Wew== 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 4cR3RP3Z4QzkRC; Tue, 16 Sep 2025 13:59:13 +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 58GDxDm2064566; Tue, 16 Sep 2025 13:59:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58GDxDn0064563; Tue, 16 Sep 2025 13:59:13 GMT (envelope-from git) Date: Tue, 16 Sep 2025 13:59:13 GMT Message-Id: <202509161359.58GDxDn0064563@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: bc8b95bb7695 - stable/14 - w: Fix idle time in json output, add login/idle times to json output 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: bc8b95bb7695b372d0d25d261fa8f3d7beed7fc8 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=bc8b95bb7695b372d0d25d261fa8f3d7beed7fc8 commit bc8b95bb7695b372d0d25d261fa8f3d7beed7fc8 Author: Marius Halden AuthorDate: 2025-08-29 14:36:32 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-09-16 13:03:58 +0000 w: Fix idle time in json output, add login/idle times to json output Currently the idle time will show as `true` part of the time in the json output and quoting depends on what is being printed. Make sure it's always printed correctly and for consistency treated as a string in the json output. Login time delta and since times are currently exposed in the xml output, expose these times in the json output as well. In the json and xml outputs expose the number of seconds idle as a new field or attribute respectively. MFC after: 1 week Sponsored by: Modirum MDPay Event: Oslo Hackathon 202508 Differential Revision: https://reviews.freebsd.org/D52237 (cherry picked from commit 6e6febb54da91bf5e13007c3d8f4a54495273969) --- usr.bin/w/pr_time.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c index 7be11b777e79..ff2da1bcc3c9 100644 --- a/usr.bin/w/pr_time.c +++ b/usr.bin/w/pr_time.c @@ -82,8 +82,13 @@ pr_attime(time_t *started, time_t *now) (void)wcsftime(buf, sizeof(buf), fmt, &tp); len = wcslen(buf); width = wcswidth(buf, len); - xo_attr("since", "%lu", (unsigned long) *started); - xo_attr("delta", "%lu", (unsigned long) diff); + if (xo_get_style(NULL) == XO_STYLE_XML) { + xo_attr("since", "%lu", (unsigned long)*started); + xo_attr("delta", "%lu", (unsigned long)diff); + } else { + xo_emit("{e:login-time-since/%lu}{e:login-time-delta/%lu}", + (unsigned long)*started, (unsigned long)diff); + } if (len == width) xo_emit("{:login-time/%-7.7ls/%ls}", buf); else if (width < 7) @@ -103,10 +108,16 @@ pr_attime(time_t *started, time_t *now) int pr_idle(time_t idle) { + /* In encoded formats, emit the raw data as well */ + if (xo_get_style(NULL) == XO_STYLE_XML) + xo_attr("seconds", "%lu", (unsigned long) idle); + else + xo_emit("{e:idle-seconds/%lu}", (unsigned long) idle); + /* If idle more than 36 hours, print as a number of days. */ if (idle >= 36 * 3600) { int days = idle / 86400; - xo_emit(" {:idle/%dday%s} ", days, days > 1 ? "s" : " " ); + xo_emit(" {q:idle/%dday%s} ", days, days > 1 ? "s" : " " ); if (days >= 100) return (2); if (days >= 10) @@ -114,16 +125,17 @@ pr_idle(time_t idle) } /* If idle more than an hour, print as HH:MM. */ - else if (idle >= 3600) - xo_emit(" {:idle/%2d:%02d/} ", + else if (idle >= 3600) { + xo_emit(" {q:idle/%2d:%02d} ", (int)(idle / 3600), (int)((idle % 3600) / 60)); + } else if (idle / 60 == 0) - xo_emit(" - "); + xo_emit(" - {q:idle//0}"); /* Else print the minutes idle. */ else - xo_emit(" {:idle/%2d} ", (int)(idle / 60)); + xo_emit(" {q:idle/%2d} ", (int)(idle / 60)); return (0); /* not idle longer than 9 days */ }