diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-01-18 22:18:22 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-01-18 22:18:22 +0000 |
commit | da14caa07adc11dd72e9568cb29e5342105cc371 (patch) | |
tree | f29f37cabac4e54abf77242139d946e424521fb4 | |
parent | 4b125a934f6775d56282dda907c3e2b6f55d5f60 (diff) | |
download | s6-networking-da14caa07adc11dd72e9568cb29e5342105cc371.tar.xz |
QoL: more client warnings / earlier exit when taiclock or ntp exchange fails
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/clock/s6-sntpclock.c | 18 | ||||
-rw-r--r-- | src/clock/s6-taiclock.c | 19 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/clock/s6-sntpclock.c b/src/clock/s6-sntpclock.c index f577eb8..8a30b8a 100644 --- a/src/clock/s6-sntpclock.c +++ b/src/clock/s6-sntpclock.c @@ -82,8 +82,10 @@ int main (int argc, char const *const *argv) tain timeouttto, throttletto, globaltto ; tain globaldeadline ; unsigned int roundtrips = 10 ; + unsigned int successes = 0 ; unsigned int i = 0 ; int sock ; + int e = 0 ; int flagforce = 0 ; ip46 ipremote ; uint16_t portremote = 123 ; @@ -149,6 +151,7 @@ int main (int argc, char const *const *argv) } if (!ntp_exchange(sock, &ipremote, portremote, stamps, &deadline)) { + e = errno ; if (verbosity >= 2) { char fmt[UINT_FMT] ; @@ -192,6 +195,7 @@ int main (int argc, char const *const *argv) tain_add(&max, &stamps[3], &deltamax) ; if (tain_less(&cur, &max) && !tain_less(&cur, &min)) tain_sub(&deltamin, &cur, &stamps[3]) ; + successes++ ; } tain_add_g(&deadline, &throttletto) ; @@ -208,6 +212,20 @@ int main (int argc, char const *const *argv) } } + if (!successes) + { + errno = e ; + strerr_diefu2sys(1, "contact NTP server at ", argv[0]) ; + } + if (successes < roundtrips && verbosity >= 2) + { + char fmts[UINT_FMT] ; + char fmtr[UINT_FMT] ; + fmts[uint_fmt(fmts, successes)] = 0 ; + fmtr[uint_fmt(fmtr, roundtrips)] = 0 ; + strerr_warnw5x("only ", fmts, " server exchanges succeeded out of ", fmtr, " - uncertainty may be higher than expected") ; + } + { char adj[TAIN_PACK] ; tain delta ; diff --git a/src/clock/s6-taiclock.c b/src/clock/s6-taiclock.c index 0fdcab7..1f0c399 100644 --- a/src/clock/s6-taiclock.c +++ b/src/clock/s6-taiclock.c @@ -55,9 +55,11 @@ int main (int argc, char const *const *argv) tain timeouttto, throttletto, globaltto ; tain globaldeadline ; unsigned int roundtrips = 10 ; + unsigned int successes = 0 ; unsigned int i = 0 ; ip46 ipremote ; int sock ; + int e = 0 ; int flagforce = 0 ; uint16_t portremote = 4014 ; PROG = "s6-taiclock" ; @@ -95,6 +97,7 @@ int main (int argc, char const *const *argv) } if (!argc) dieusage() ; if (!ip46_scan(argv[0], &ipremote)) dieusage() ; + if (roundtrips < 1) roundtrips = 1 ; sock = socket_udp46(ip46_is6(&ipremote)) ; if (sock < 0) strerr_diefu1sys(111, "socket_udp") ; @@ -115,6 +118,7 @@ int main (int argc, char const *const *argv) tain_copynow(&before) ; if (!tain_exchange(sock, &ipremote, portremote, &serversays, &deadline)) { + e = errno ; if (verbosity >= 2) { char fmt[UINT_FMT] ; @@ -136,6 +140,7 @@ int main (int argc, char const *const *argv) tain_add_g(&max, &deltamax) ; if (tain_less(&cur, &max) && !tain_less(&cur, &min)) tain_sub(&deltamin, &cur, &STAMP) ; + successes++ ; } tain_add_g(&deadline, &throttletto) ; @@ -152,6 +157,20 @@ int main (int argc, char const *const *argv) } } + if (!successes) + { + errno = e ; + strerr_diefu2sys(1, "contact taiclock server at ", argv[0]) ; + } + if (successes < roundtrips && verbosity >= 2) + { + char fmts[UINT_FMT] ; + char fmtr[UINT_FMT] ; + fmts[uint_fmt(fmts, successes)] = 0 ; + fmtr[uint_fmt(fmtr, roundtrips)] = 0 ; + strerr_warnw5x("only ", fmts, " server exchanges succeeded out of ", fmtr, " - uncertainty may be higher than expected") ; + } + { char adj[TAIN_PACK] ; tain delta ; |