From 9ec65868668839136ee10bcf6785938c3ad9a1a1 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 17 Mar 2014 00:18:55 +0100 Subject: timedated: move test logging to test program --- src/timedate/test-timedate-sntp.c | 13 ++++++++++--- src/timedate/timedate-sntp.c | 13 +++++++++---- src/timedate/timedate-sntp.h | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/timedate/test-timedate-sntp.c b/src/timedate/test-timedate-sntp.c index 41999c85cb..a0ed4ac271 100644 --- a/src/timedate/test-timedate-sntp.c +++ b/src/timedate/test-timedate-sntp.c @@ -74,14 +74,16 @@ static void manager_free(Manager *m) { free(m); } +static void manager_report(usec_t poll_usec, double offset, double delay, double jitter, bool spike) { + log_info("%4llu %+10f %10f %10f%s", + poll_usec / USEC_PER_SEC, offset, delay, jitter, spike ? " spike" : ""); +} + int main(int argc, char *argv[]) { _cleanup_manager_free_ Manager *m = NULL; const char *server; int r; - if (argv[1]) - log_set_max_level(LOG_DEBUG); - r = manager_new(&m); if (r < 0) goto out; @@ -90,6 +92,11 @@ int main(int argc, char *argv[]) { if (r < 0) goto out; + if (argv[1]) + log_set_max_level(LOG_DEBUG); + else + sntp_report_register(m->sntp, manager_report); + //server = "216.239.32.15"; /* time1.google.com */ //server = "192.53.103.108"; /* ntp1.ptb.de */ server = "130.102.2.123"; /* 0.au.pool.ntp.org */ diff --git a/src/timedate/timedate-sntp.c b/src/timedate/timedate-sntp.c index 7e34e93ca6..36b2a1a1a5 100644 --- a/src/timedate/timedate-sntp.c +++ b/src/timedate/timedate-sntp.c @@ -118,6 +118,8 @@ struct ntp_msg { } _packed_; struct SNTPContext { + void (*report)(usec_t poll, double offset, double delay, double jitter, bool spike); + /* peer */ sd_event_source *event_receive; char *server; @@ -218,7 +220,7 @@ static int sntp_send_request(SNTPContext *sntp) { sntp->pending = true; log_debug("Sent NTP request to: %s", sntp->server); } else - log_info("Sending NTP request to %s failed: %m", sntp->server); + log_debug("Sending NTP request to %s failed: %m", sntp->server); /* re-arm timer with incresing timeout, in case the packets never arrive back */ if (sntp->retry_interval > 0) { @@ -626,9 +628,8 @@ static int sntp_receive_response(sd_event_source *source, int fd, uint32_t reven sntp->samples_jitter, spike ? " spike" : "", sntp->poll_interval_usec / USEC_PER_SEC); - log_info("%4llu %+10f %10f %10f%s", - sntp->poll_interval_usec / USEC_PER_SEC, offset, delay, - sntp->samples_jitter, spike ? " spike" : ""); + if (sntp->report) + sntp->report(sntp->poll_interval_usec, offset, delay, sntp->samples_jitter, spike); if (!spike) { r = sntp_adjust_clock(sntp, offset, leap_sec); @@ -723,6 +724,10 @@ static int sntp_listen_setup(SNTPContext *sntp, sd_event *e) { return 0; } +void sntp_report_register(SNTPContext *sntp, void (*report)(usec_t poll_usec, double offset, double delay, double jitter, bool spike)) { + sntp->report = report; +} + int sntp_new(SNTPContext **sntp, sd_event *e) { _cleanup_free_ SNTPContext *c; int r; diff --git a/src/timedate/timedate-sntp.h b/src/timedate/timedate-sntp.h index 09107c72cf..7f17390952 100644 --- a/src/timedate/timedate-sntp.h +++ b/src/timedate/timedate-sntp.h @@ -31,3 +31,4 @@ int sntp_new(SNTPContext **sntp, sd_event *e); SNTPContext *sntp_unref(SNTPContext *sntp); int sntp_server_connect(SNTPContext *sntp, const char *server); void sntp_server_disconnect(SNTPContext *sntp); +void sntp_report_register(SNTPContext *sntp, void (*report)(usec_t poll_usec, double offset, double delay, double jitter, bool spike)); -- cgit v1.2.3-54-g00ecf