This also makes the source port less predicatable.
static int manager_arm_timer(Manager *m, usec_t next);
static int manager_clock_watch_setup(Manager *m);
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);
static double ntp_ts_short_to_d(const struct ntp_ts_short *ts) {
return be16toh(ts->sec) + (be16toh(ts->frac) / 65536.0);
m->event_timeout = sd_event_source_unref(m->event_timeout);
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
/*
* Set transmit timestamp, remember it; the server will send that back
* as the origin timestamp and we have an indication that this is the
- assert(m->event_receive);
if (next == 0) {
m->event_timer = sd_event_source_unref(m->event_timer);
if (next == 0) {
m->event_timer = sd_event_source_unref(m->event_timer);
m->pending = false;
m->retry_interval = 0;
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;
/* announce leap seconds */
if (NTP_FIELD_LEAP(ntpmsg.field) & NTP_LEAP_PLUSSEC)
leap_sec = 1;
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);
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;
r = manager_clock_watch_setup(m);
if (r < 0)
return r;