From nobody Fri Aug 29 14:53:56 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 4cD1Vr4ZS8z65fn8; Fri, 29 Aug 2025 14:53:56 +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 4cD1Vr3RnCz3stp; Fri, 29 Aug 2025 14:53:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756479236; 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=6b1Pyu7R6iY9lN+mtE7O8LY9fzPnz6eSqFNqRAaZOQM=; b=mmQUyakumzzOYARor0nakK6NUVmx/YtYBJHPZ8wt4Fx4MlBzP5UTo1AOVOD6zy52xlmurh 99YIwf4IWzvIM+inu4zuoaqwXYuP3SOa2bEm9iYTwN9O/BrjRzr95mAquJrpRIKsyCA1x1 B0WMJavqy/1fUMb0SVbF72IMj/dZMCjSiv/1PIAJ4AHehIMPDSaXhBG7P9WOLFfK4rGpM1 zfSC1ly0+F2QKFXXKjVGftECY0TyLxNwW0V+1RCM+KpgGwcjZijlSLsD47OQveiQXeN0/7 9EClCJ7/+iNriFA9y8QaFDe92c+nuC3XaMNCNed/yzmaQz0kJ7uYju6eabzkLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756479236; 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=6b1Pyu7R6iY9lN+mtE7O8LY9fzPnz6eSqFNqRAaZOQM=; b=Zi79rOGPoh6F+Y3he+asGtCFgdSCIRJjVKQwi3qcXvQ+YhE5AQ9hWBazz7oU0LfqcDsGaI flBr3m3U+hHG7G+pc+32iMF8m4p7d+xZMenF5hUic2gF5xozYTrxCyGAO1O6FNpEBIKki3 daGYgLgatSNAXh1yMLhoQCGxjI5XdY9v92xFnONemNXbaJSTGrnm0/SsR81n2vF0AXBwvH KK4Y9qDYnjq3bIh9tr03B1Eorhok1VMTTQhM9lqn8taIj4ksemVyL4kvWgwZjuSwgMbtGm TzIiqoDM35+dcUei+s9f4mctnhMYTVnlxCO9a1Jb3LhzoggDiC6KKUOJ4t64GA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756479236; a=rsa-sha256; cv=none; b=cDMYhFUE3lVPGndVoqwbEmAMe8/pn7mV7tL1XoaTeDGemqPra5pZGFHXFpzYUK1FTHFINc uCS7mxtlG08LHKcrkiQAtXMsD8nX3WHR75cTF4vIZx5RoKsYGS0WweS5n3Nabm5Xvy8Qbm ztnmNP+PEWunDSF4GPxv8l6gxEiJSe4IKFjiishCNxiWdUb/cyUcS/u5XPQhl9YHLjjEOH BVi1WAUWES8JE/dsWAWUd92Mc3X4acfJJRRAtWtiTDdlM4Gyqz1yst+3spHfJTf7d8f6vk bKYG9ebsvGNmfwfL6QmK5cPo384lDSvFX8SeLdc0TQJ3nlpnpbBGf8IxrD7lkw== 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 4cD1Vr2lq8zlMV; Fri, 29 Aug 2025 14:53:56 +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 57TErum3060589; Fri, 29 Aug 2025 14:53:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57TEruEW060586; Fri, 29 Aug 2025 14:53:56 GMT (envelope-from git) Date: Fri, 29 Aug 2025 14:53:56 GMT Message-Id: <202508291453.57TEruEW060586@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 6e6febb54da9 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6e6febb54da91bf5e13007c3d8f4a54495273969 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=6e6febb54da91bf5e13007c3d8f4a54495273969 commit 6e6febb54da91bf5e13007c3d8f4a54495273969 Author: Marius Halden AuthorDate: 2025-08-29 14:36:32 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-08-29 14:53:26 +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 --- 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 aef8b5dfaa87..445431fe3ec5 100644 --- a/usr.bin/w/pr_time.c +++ b/usr.bin/w/pr_time.c @@ -79,8 +79,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) @@ -100,10 +105,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) @@ -111,16 +122,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 */ }