diff options
author | Sean Young <sean@mess.org> | 2014-11-26 09:33:30 +0000 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-11-27 00:24:52 -0500 |
commit | 7b6288914b3b57e1c33c740eb705c5a6dd2655ca (patch) | |
tree | c9951888e6ce6a4674da50f16b14cc6fceae9ebc /src/timesync/timesyncd-manager.c | |
parent | e8461023531de98ac6a49eff9d6ffeff6315249c (diff) |
timesyncd: do not keep listening socket open forever
This also makes the source port less predicatable.
Diffstat (limited to 'src/timesync/timesyncd-manager.c')
-rw-r--r-- | src/timesync/timesyncd-manager.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 3ae01eb8fc..03cfb248c0 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -132,6 +132,7 @@ struct ntp_msg { static int manager_arm_timer(Manager *m, usec_t next); static int manager_clock_watch_setup(Manager *m); +static int manager_listen_setup(Manager *m); static double ntp_ts_short_to_d(const struct ntp_ts_short *ts) { return be16toh(ts->sec) + (be16toh(ts->frac) / 65536.0); @@ -184,6 +185,14 @@ static int manager_send_request(Manager *m) { m->event_timeout = sd_event_source_unref(m->event_timeout); + if (m->server_socket < 0) { + r = manager_listen_setup(m); + if (r < 0) { + log_warning("Failed to setup connection socket: %s", strerror(-r)); + return r; + } + } + /* * Set transmit timestamp, remember it; the server will send that back * as the origin timestamp and we have an indication that this is the @@ -250,7 +259,6 @@ static int manager_arm_timer(Manager *m, usec_t next) { int r; assert(m); - assert(m->event_receive); if (next == 0) { m->event_timer = sd_event_source_unref(m->event_timer); @@ -610,6 +618,10 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re m->pending = false; m->retry_interval = 0; + /* Stop listening */ + m->event_receive = sd_event_source_unref(m->event_receive); + m->server_socket = safe_close(m->server_socket); + /* announce leap seconds */ if (NTP_FIELD_LEAP(ntpmsg.field) & NTP_LEAP_PLUSSEC) leap_sec = 1; @@ -741,12 +753,6 @@ static int manager_begin(Manager *m) { log_info("Using NTP server %s (%s).", strna(pretty), m->current_server_name->string); sd_notifyf(false, "STATUS=Using Time Server %s (%s).", strna(pretty), m->current_server_name->string); - r = manager_listen_setup(m); - if (r < 0) { - log_warning("Failed to setup connection socket: %s", strerror(-r)); - return r; - } - r = manager_clock_watch_setup(m); if (r < 0) return r; |