[ntpsec commit] ntptime is now JSON-enabled.
Eric S. Raymond
esr at ntpsec.org
Thu Oct 15 20:00:17 UTC 2015
Module: ntpsec
Branch: master
Commit: a2a473ba3c1b986ccd2bdb83c571f2f31e1cc4d2
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=a2a473ba3c1b986ccd2bdb83c571f2f31e1cc4d2
Author: Eric S. Raymond <esr at thyrsus.com>
Date: Thu Oct 15 07:29:33 2015 -0400
ntptime is now JSON-enabled.
---
docs/includes/ntptime-body.txt | 8 +++++++-
util/ntptime.c | 6 ++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/docs/includes/ntptime-body.txt b/docs/includes/ntptime-body.txt
index a29efb3..0defa5c 100644
--- a/docs/includes/ntptime-body.txt
+++ b/docs/includes/ntptime-body.txt
@@ -5,7 +5,9 @@
== Synopsis ==
["literal",subs="normal"]
-{ntptime} [ -chr ] [ -e 'est_error' ] [ -f 'frequency' ] [ -m 'max_error' ] [ -o 'offset' ] [ -s 'status' ] [ -t 'time_constant']
+{ntptime} [ -chr ] [ -e 'est_error' ] [ -f 'frequency' ] [-j]
+ [ -m 'max_error' ] [ -o 'offset' ] [ -s 'status' ]
+ [ -t 'time_constant']
== Description ==
@@ -39,4 +41,8 @@ and `kerninfo` command.
`-t` 'time_constant'::
Specify time constant, an integer in the range 0-10.
+== Bugs ==
+
+The format for modes and status in the JSON report is less than ideal.
+
//end
diff --git a/util/ntptime.c b/util/ntptime.c
index d5c4459..e1b2895 100644
--- a/util/ntptime.c
+++ b/util/ntptime.c
@@ -303,7 +303,8 @@ main(
ts.l_ui += JAN_1970;
ts.l_uf += ts_roundbit;
ts.l_uf &= ts_mask;
- printf(json ? jfmt2 : ofmt2, prettydate(&ts), fdigits, (int)time_frac);
+ /* FIXME: ugly hack - we shouldn't use prettydate() here */
+ printf(json ? jfmt2 : ofmt2, prettydate(&ts) + (json?18:0), fdigits, (int)time_frac);
printf(json ? jfmt3 : ofmt3, (u_long)ntv.maxerror, (u_long)ntv.esterror);
if (rawtime)
printf(json ? jfmt4 : ofmt4,
@@ -382,7 +383,8 @@ main(
(u_long)ntx.stbcnt, (u_long)ntx.errcnt);
}
if (json)
- fputs("}\n", stdout);
+ /* hack to avoid trailing comma - not semabtically needed */
+ fputs("\"version\":\"" NTPS_VERSION_STRING "\"}\n", stdout);
exit(EXIT_SUCCESS);
}
More information about the vc
mailing list