From 4f811d27d6d9324e65ce628fa20ac1761ef98de0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 29 May 2018 12:55:33 +0200 Subject: time-util: introduce common implementation of TFD_TIMER_CANCEL_ON_SET client code We now use pretty much the same code at three places, let's unify that. --- src/time-wait-sync/time-wait-sync.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/time-wait-sync/time-wait-sync.c') diff --git a/src/time-wait-sync/time-wait-sync.c b/src/time-wait-sync/time-wait-sync.c index 198c055650..37b032b39e 100644 --- a/src/time-wait-sync/time-wait-sync.c +++ b/src/time-wait-sync/time-wait-sync.c @@ -115,16 +115,15 @@ static int inotify_handler(sd_event_source *s, return 0; } -static int clock_state_update(ClockState *sp, - sd_event *event) { - static const struct itimerspec its = { - .it_value.tv_sec = TIME_T_MAX, - }; - int r; - struct timex tx = {}; +static int clock_state_update( + ClockState *sp, + sd_event *event) { + char buf[MAX((size_t)FORMAT_TIMESTAMP_MAX, STRLEN("unrepresentable"))]; - usec_t t; + struct timex tx = {}; const char * ts; + usec_t t; + int r; clock_state_release_timerfd(sp); @@ -151,18 +150,13 @@ static int clock_state_update(ClockState *sp, * it synchronized. When an NTP source is selected it sets the clock again with clock_adjtime(2) which marks it * synchronized and also touches /run/systemd/timesync/synchronized which covers the case when the clock wasn't * "set". */ - r = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC); - if (r < 0) { - log_error_errno(errno, "Failed to create timerfd: %m"); - goto finish; - } - sp->timerfd_fd = r; - r = timerfd_settime(sp->timerfd_fd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &its, NULL); + r = time_change_fd(); if (r < 0) { - log_error_errno(errno, "Failed to set timerfd conditions: %m"); + log_error_errno(r, "Failed to create timerfd: %m"); goto finish; } + sp->timerfd_fd = r; r = adjtimex(&tx); if (r < 0) { -- cgit v1.2.3