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 /src/clock/s6-sntpclock.c | |
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>
Diffstat (limited to 'src/clock/s6-sntpclock.c')
-rw-r--r-- | src/clock/s6-sntpclock.c | 18 |
1 files changed, 18 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 ; |