From nobody Tue Sep 16 13:59:22 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 4cR3RZ5lP5z67Jbt; Tue, 16 Sep 2025 13:59:22 +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 4cR3RZ3tbqz3Xd7; Tue, 16 Sep 2025 13:59:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758031162; 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=qbGTIGjX+VJK0fzwUaOAYM5Ny300Rqg0gAHXDR/BKwk=; b=o2K6QrNpCLYLjZysRgQrBjqKkQ+iJhmTVm+FFQvvld6NbBLGXlTQVmdsgJZjMbIkBZTvVP SAWij8Xc36++X9YZJQ5YHy9bPiWbrJOMKHswwrEt4x0KjnHJFG+AufpdUmm9Z32UHo/srr 61r/Rq8bske4z79QU5rztUgElKQeTJueTUhurbYHwzmi85+tXH9nDf1hUwVSHYLdEMbk7f Azm2hgmuTTPSVrQ1cpnWMM9IIxo9s1IuNuZa9CTrIPLodmlY0a1lu6KbaEH2stMspVHBBT RJ649UC0R/85RDOaNv1pxde/BQ43kpAk7KRnF4h7pPHRPL47v0+C3GGzUgsdeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758031162; 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=qbGTIGjX+VJK0fzwUaOAYM5Ny300Rqg0gAHXDR/BKwk=; b=b4SwT2soHl84YC8q/vIjnf3xYFp4A08Aih8b80saW/LArSckO7Z5x7dJ9ISNAM5wWrKZPr uAiyiH1LZA6YxdMG7uJu6uNbhgOlrAQH0jgnDNZyY/6sasyiXMZXnahYgz1UN5tjEPhx/I ug2iPchXF9L+5UDV1si3zwHL3fYBgI6fBOTu0Rbz2HCg/9FVb8/G6EAXllHkb+KrymKaF4 0OyNjctL52xJNnnLMIODgIYtVhB2DAkLkTZLUoXtMgsyUwn4et2vKW2A25r2EVneGpz+le ASOl+UodadgQhb72VglCMLp81GAHLmV4a8FCUIPPmVep/tg4xohgvfl5Rb9Tzw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758031162; a=rsa-sha256; cv=none; b=sUrpsbp2NOVu77SnoSkA/Uc4C4QBvXtgnBHQQQtY2B0TgQ60yY8vC+BzLO251AibQIfB9a RIE/DwCAzDej+BHztHtmlsy+SG3Wu4b71ysxNtnLHwPSW4aVCL7wBjsAbT+tYgl8xOWvIk RqF6ffQS4lIvYdh/E5IfdMNUKjakurW742MSogMvIqBYP1svebJXufWvYTCCx9qt0H1hZI +KFyKDIXMmLET46JU1IfZH6GuVR3ZrConJy1GD6vw8cEmLT5SCCuJgLN9DT8RxEg67W0Ps Z4S4yAIqoJ0xSdn5mBwZFQ+lPoTKONWJs6ESC3DwDUuhpw4BPP+rgn//aAvBdg== 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 4cR3RZ3MzlzkNd; Tue, 16 Sep 2025 13:59:22 +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 58GDxMoS064895; Tue, 16 Sep 2025 13:59:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58GDxM68064892; Tue, 16 Sep 2025 13:59:22 GMT (envelope-from git) Date: Tue, 16 Sep 2025 13:59:22 GMT Message-Id: <202509161359.58GDxM68064892@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: d703ae86bfa1 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: d703ae86bfa1283ffbbaac37c884c61e8c1ead1c Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d703ae86bfa1283ffbbaac37c884c61e8c1ead1c commit d703ae86bfa1283ffbbaac37c884c61e8c1ead1c Author: Marius Halden AuthorDate: 2025-08-29 14:36:32 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-09-16 13:03:57 +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 */ }