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.
Details
- Reviewers
jmg marcel - Commits
- rS281625: Fix libxo output from uptime command
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
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:
- Avoid underscores and use dashes/hyphens instead: Thus, the key becomes "uptime-seconds" (*)
- (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..
Updated to use sbuf instead of a static malloc
Use uptime-human, since all of the existing keys use dashes