Page MenuHomeFreeBSD

Fix libxo JSON output for uptime command
ClosedPublic

Authored by allanjude on Mar 14 2015, 2:09 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 18, 11:05 PM
Unknown Object (File)
Mon, Nov 18, 6:20 PM
Unknown Object (File)
Mon, Nov 18, 5:23 AM
Unknown Object (File)
Mon, Nov 18, 12:19 AM
Unknown Object (File)
Mon, Nov 11, 2:42 PM
Unknown Object (File)
Sun, Nov 10, 2:26 PM
Unknown Object (File)
Sep 24 2024, 3:20 AM
Unknown Object (File)
Sep 12 2024, 1:17 AM
Subscribers

Details

Summary

the libxo output for uptime returns multiple 'uptime' keys from the number of days,
hours, minutes etc of uptime.
This is invalid JSON.
This patch makes it output the raw number of seconds, as well as the individual units
of time, and a string of the original output from the uptime command.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

allanjude retitled this revision from to Fix libxo JSON output for uptime command.
allanjude updated this object.
allanjude edited the test plan for this revision. (Show Details)
allanjude added reviewers: marcel, jmg.
marcel edited edge metadata.

It looks like line 501 should be removed.
My suggestion is to avoid the "uptime_seconds" key and instead just use "uptime" if that's possible.
I find it less ugly (but that's in the eye of the beholder, so feel free to stick with what you like).

Other than that: ok.

This revision is now accepted and ready to land.Mar 14 2015, 4:40 PM
In D2063#4, @marcel wrote:

It looks like line 501 should be removed.
My suggestion is to avoid the "uptime_seconds" key and instead just use "uptime" if that's possible.
I find it less ugly (but that's in the eye of the beholder, so feel free to stick with what you like).

Other than that: ok.

If i use 'uptime' for the tp.tv_sec then what should I call the key that contains the 'human readable' version?

I'm sorry; I missed the other use of that key.

I can make two suggestions along the lines of the first, but again it's all in the eye of the beholder, so feel free to do what you like:

  1. Avoid underscores and use dashes/hyphens instead: Thus, the key becomes "uptime-seconds" (*)
  2. (alternatively) Use "uptime" for seconds, because that's most likely the value that machines want to work with and rename the existing "uptime" to "uptime-human", "uptime-friendly", "uptime-clock", or anything along those lines.

(*) I think it's good to develop a style guide for this, possibly with a checker. I'll look around on the net if there's already something like a JSON naming best practices or so.

In D2063#8, @marcel wrote:

I'm sorry; I missed the other use of that key.

I can make two suggestions along the lines of the first, but again it's all in the eye of the beholder, so feel free to do what you like:

  1. Avoid underscores and use dashes/hyphens instead: Thus, the key becomes "uptime-seconds" (*)
  2. (alternatively) Use "uptime" for seconds, because that's most likely the value that machines want to work with and rename the existing "uptime" to "uptime-human", "uptime-friendly", "uptime-clock", or anything along those lines.

(*) I think it's good to develop a style guide for this, possibly with a checker. I'll look around on the net if there's already something like a JSON naming best practices or so.

I prefer underscores, as they are more usable for shell scripts, which do not allow - in variable names.
However, if there is a strong style guide that recommends against _, I suppose we can do that

the JSON specification says nothing

Google's JSON API guide says:

  • The first character must be a letter, an underscore (_) or a dollar sign ($).
  • Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.

but it also calls for using camelCase, so..

allanjude edited edge metadata.

Updated with feedback from marcel@

This revision now requires review to proceed.Mar 19 2015, 5:15 AM

I'd prefer if you would make the changes.

Thanks.

usr.bin/w/w.c
477 โ†—(On Diff #4284)

just use calloc instead of malloc+memset.

507 โ†—(On Diff #4284)

why don't you use sbuf_new_auto and friends? Makes things more simple...

allanjude edited edge metadata.

Updated to use sbuf instead of a static malloc

Use uptime-human, since all of the existing keys use dashes

I need approval to commit this, as I am only a doc committer

marcel edited edge metadata.

Commit away!

This revision is now accepted and ready to land.Apr 15 2015, 5:46 AM
allanjude updated this revision to Diff 4862.

Closed by commit rS281625 (authored by @allanjude).