Page MenuHomeFreeBSD

w: Trim whitespace and commas from time and uptime
ClosedPublic

Authored by des on Oct 17 2025, 4:37 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 10, 6:48 AM
Unknown Object (File)
Sat, Dec 6, 7:37 PM
Unknown Object (File)
Thu, Dec 4, 7:11 AM
Unknown Object (File)
Thu, Dec 4, 5:20 AM
Unknown Object (File)
Wed, Dec 3, 8:55 PM
Unknown Object (File)
Mon, Dec 1, 11:28 AM
Unknown Object (File)
Sun, Nov 30, 4:14 PM
Unknown Object (File)
Sat, Nov 29, 2:24 PM
Subscribers

Details

Summary

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")

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Oct 17 2025, 4:37 PM

The json and xml output looks good to me, but in the plain text output it's missing a space between "up" and the time.

2:54PM  up3 minutes 1 user, load averages: 0.08, 0.09, 0.04

ah shit I didn't realize the same string was being used for both, I'll have to rethink this

I think you can do something as simple as this to get an extra white space it the plain text output, since it's outside the "uptime-human" format string it won't be included in the encoded outputs.

diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index cbd5ab1459af..c00871d6b85e 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -528,7 +528,7 @@ pr_header(time_t *nowp, int nusers)
                            secs, secs > 1 ? "s" : "");
                if (sbuf_finish(&upbuf) != 0)
                        xo_err(1, "Could not generate output");
-               xo_emit("{:uptime-human/%s}", sbuf_data(&upbuf) + 2);
+               xo_emit(" {:uptime-human/%s}", sbuf_data(&upbuf) + 2);
                sbuf_delete(&upbuf);
        }

That's not enough. I completely changed the format because I thought I was only affecting json and xml output. The non-libxo output needs to remain unchanged.

des retitled this revision from w: Make human-readable uptime actually human-readable to w: Trim whitespace and commas from time and uptime.Oct 20 2025, 5:36 PM
des edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Oct 22 2025, 7:15 PM