Bug 290089 - w libxo output has extra padding in uptime-human
Summary: w libxo output has extra padding in uptime-human
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Many People
Assignee: Dag-Erling Smørgrav
URL: https://reviews.freebsd.org/D53167
Keywords:
Depends on:
Blocks:
 
Reported: 2025-10-08 09:41 UTC by Sulev-Madis Silber
Modified: 2025-10-30 23:53 UTC (History)
1 user (show)

See Also:
des: mfc-stable15+
des: mfc-stable14+
des: mfc-stable13+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sulev-Madis Silber 2025-10-08 09:41:53 UTC
uptime-human field has padding at the start in all xo output


example:

> w --libxo=json,pretty
{
  "__version": "1",
  "uptime-information": {
    "time-of-day": "12:39PM",
    "uptime": 18188,
    "days": 0,
    "hours": 5,
    "minutes": 3,
    "seconds": 8,
    "uptime-human": "  5:03,",
    "users": 0,
    "load-average-1": 0.32,
    "load-average-5": 0.34,
    "load-average-15": 0.31,
    "user-table": {
      "user-entry": [
      ]
    }
  }
}
Comment 1 Sulev-Madis Silber 2025-10-14 07:40:43 UTC
load makes invalid json if decimal is comma:


> env LANG=de_DE.ISO8859-15 uptime --libxo=json,pretty
{
  "uptime-information": {
    "time-of-day": "10:38",
    "uptime": 255092,
    "days": 2,
    "hours": 22,
    "minutes": 51,
    "seconds": 32,
    "uptime-human": " 2 days, 22:52,",
    "users": 6,
    "load-average-1": 0,29,
    "load-average-5": 0,42,
    "load-average-15": 0,47
  }
}
Comment 2 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2025-10-17 16:36:13 UTC
The second issue is a libxo bug, can you please open a separate ticket for it?
Comment 3 Sulev-Madis Silber 2025-10-17 17:08:01 UTC
(In reply to Dag-Erling Smørgrav from comment #2)

while writing, i found

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=276304

seems like it needs "refix"?

new bug can still be filed if needed, hmm
Comment 4 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2025-10-17 17:17:14 UTC
That clearly got broken again somehow but it was the wrong fix in the first place, libxo needs to either quote numbers or (more likely) force the C locale when emitting json.
Comment 5 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2025-10-17 17:24:58 UTC
I am unable to reproduce the locale bug on 16, unless I first revert Baptiste's change.  What were you testing on?
Comment 6 Sulev-Madis Silber 2025-10-17 17:29:09 UTC
(In reply to Dag-Erling Smørgrav from comment #4)

i made https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=290328 and messed with it's status as you see

in 16 it's ok, but if you say so, that working if is wrong, the we have separate bug now for it
Comment 7 Sulev-Madis Silber 2025-10-17 19:09:10 UTC
i think something else got fishy there, maybe while it was fixed for decimals, as now json outputs show 12h clock in time-of-day


now 13 shows wrong decimals, and 24h clock. but 16 shows forced dot decimals but also forced 12h clock because LANG=C specifies that

i did read a while ago how ps output was switched to forced 24h clock

unsure if this pisses people off but currently i need stupid hacks like

uptime  env LC_TIME=de_DE.ISO8859-15 uptime
w       env LC_TIME=de_DE.ISO8859-15 w

i even wrote a whole shell script to find locales where clock is 24h. i even have made special locale past, solely in order to get 24h clocks. it's ridiculous!

p.s.: oh, and time-of-day field ALSO has padding

while debugging stuff i also found that gpart show on very latest 16 gives me text and empty json output at same time

maybe there's need for xo enabled utils output test to verify they still do the right thing. i don't know if tests exist for that. seems like while libxo is awesome machine readable output maker, there are tons and tons of bugs there
Comment 8 commit-hook freebsd_committer freebsd_triage 2025-10-23 10:29:20 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4d5789532a940144c869d66505e756ce816f8a50

commit 4d5789532a940144c869d66505e756ce816f8a50
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-10-23 10:28:44 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-10-23 10:29:01 +0000

    w: Trim whitespace and commas from time and uptime

    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")
    Reviewed by:    marius.h_lden.org
    Differential Revision:  https://reviews.freebsd.org/D53167

 usr.bin/w/w.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-10-28 11:09:28 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ca16a115a0fa4da67b153d0b90c9ec08adc9b2fb

commit ca16a115a0fa4da67b153d0b90c9ec08adc9b2fb
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-10-23 10:28:44 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-10-28 11:08:12 +0000

    w: Trim whitespace and commas from time and uptime

    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")
    Reviewed by:    marius.h_lden.org
    Differential Revision:  https://reviews.freebsd.org/D53167

    (cherry picked from commit 4d5789532a940144c869d66505e756ce816f8a50)

 usr.bin/w/w.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2025-10-28 11:09:30 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5572a45c0f6122477e218e54a4b88e63563f3359

commit 5572a45c0f6122477e218e54a4b88e63563f3359
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-10-23 10:28:44 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-10-28 11:08:14 +0000

    w: Trim whitespace and commas from time and uptime

    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")
    Reviewed by:    marius.h_lden.org
    Differential Revision:  https://reviews.freebsd.org/D53167

    (cherry picked from commit 4d5789532a940144c869d66505e756ce816f8a50)

 usr.bin/w/w.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2025-10-28 11:09:31 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ce8559897261b0610990b88a18efa44df42a9747

commit ce8559897261b0610990b88a18efa44df42a9747
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-10-23 10:28:44 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-10-28 11:08:30 +0000

    w: Trim whitespace and commas from time and uptime

    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")
    Reviewed by:    marius.h_lden.org
    Differential Revision:  https://reviews.freebsd.org/D53167

    (cherry picked from commit 4d5789532a940144c869d66505e756ce816f8a50)

 usr.bin/w/w.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)
Comment 12 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2025-10-28 11:12:11 UTC
Please open a separate ticket for gpart if you haven't already.
Comment 13 commit-hook freebsd_committer freebsd_triage 2025-10-30 23:53:33 UTC
A commit in branch releng/15.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8cf76cbac85119fa8d081fdc9b7cbfd1b6728071

commit 8cf76cbac85119fa8d081fdc9b7cbfd1b6728071
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-10-23 10:28:44 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-10-30 23:48:28 +0000

    w: Trim whitespace and commas from time and uptime

    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.

    Approved by:    re (cperciva)
    PR:             290089
    Fixes:          6e6febb54da9 ("w: Fix idle time in json output, add login/idle times to json output")
    Reviewed by:    marius.h_lden.org
    Differential Revision:  https://reviews.freebsd.org/D53167

    (cherry picked from commit 4d5789532a940144c869d66505e756ce816f8a50)
    (cherry picked from commit ca16a115a0fa4da67b153d0b90c9ec08adc9b2fb)

 usr.bin/w/w.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)