Date: Fri, 29 Aug 2025 14:53:56 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 6e6febb54da9 - main - w: Fix idle time in json output, add login/idle times to json output Message-ID: <202508291453.57TEruEW060586@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=6e6febb54da91bf5e13007c3d8f4a54495273969 commit 6e6febb54da91bf5e13007c3d8f4a54495273969 Author: Marius Halden <marius.halden@modirum.com> AuthorDate: 2025-08-29 14:36:32 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> 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 */ }help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202508291453.57TEruEW060586>
