diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-05-29 12:55:33 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-06-06 10:55:45 +0200 |
commit | 4f811d27d6d9324e65ce628fa20ac1761ef98de0 (patch) | |
tree | b2673f25c2e521455ec92a2440cf1e86370ca1df /src/time-wait-sync/time-wait-sync.c | |
parent | core: subscribe to /etc/localtime timezone changes and update timer elapsatio... (diff) | |
download | systemd-4f811d27d6d9324e65ce628fa20ac1761ef98de0.tar.xz systemd-4f811d27d6d9324e65ce628fa20ac1761ef98de0.zip |
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.
Diffstat (limited to 'src/time-wait-sync/time-wait-sync.c')
-rw-r--r-- | src/time-wait-sync/time-wait-sync.c | 26 |
1 files changed, 10 insertions, 16 deletions
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) { |