#include <netinet/ip.h>
#include <resolv.h>
#include <stdlib.h>
-#include <sys/socket.h>
#include <sys/timerfd.h>
#include <sys/timex.h>
#include <sys/types.h>
-#include <time.h>
#include "sd-daemon.h"
#include "alloc-util.h"
#include "dns-domain.h"
#include "fd-util.h"
+#include "format-util.h"
#include "fs-util.h"
#include "list.h"
#include "log.h"
-#include "missing.h"
#include "network-util.h"
#include "ratelimit.h"
#include "resolve-private.h"
r = manager_listen_setup(m);
if (r < 0)
- return log_warning_errno(r, "Failed to setup connection socket: %m");
+ return log_warning_errno(r, "Failed to set up connection socket: %m");
/*
* Set transmit timestamp, remember it; the server will send that back
}
/* re-arm timer with increasing timeout, in case the packets never arrive back */
- if (m->retry_interval > 0) {
- if (m->retry_interval < m->poll_interval_max_usec)
- m->retry_interval *= 2;
- } else
- m->retry_interval = m->poll_interval_min_usec;
+ if (m->retry_interval == 0)
+ m->retry_interval = NTP_RETRY_INTERVAL_MIN_USEC;
+ else
+ m->retry_interval = MIN(m->retry_interval * 4/3, NTP_RETRY_INTERVAL_MAX_USEC);
r = manager_arm_timer(m, m->retry_interval);
if (r < 0)
.iov_base = &ntpmsg,
.iov_len = sizeof(ntpmsg),
};
- union {
- struct cmsghdr cmsghdr;
- uint8_t buf[CMSG_SPACE(sizeof(struct timeval))];
- } control;
+ CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct timeval))) control;
union sockaddr_union server_addr;
struct msghdr msghdr = {
.msg_iov = &iov,
return manager_connect(m);
}
- len = recvmsg(fd, &msghdr, MSG_DONTWAIT);
+ len = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT);
+ if (len == -EAGAIN)
+ return 0;
if (len < 0) {
- if (errno == EAGAIN)
- return 0;
-
- log_warning("Error receiving message. Disconnecting.");
+ log_warning_errno(len, "Error receiving message, disconnecting: %m");
return manager_connect(m);
}
root_distance = ntp_ts_short_to_d(&ntpmsg.root_delay) / 2 + ntp_ts_short_to_d(&ntpmsg.root_dispersion);
if (root_distance > (double) m->max_root_distance_usec / (double) USEC_PER_SEC) {
- log_debug("Server has too large root distance. Disconnecting.");
+ log_info("Server has too large root distance. Disconnecting.");
return manager_connect(m);
}
m->good = true;
server_address_pretty(m->current_server_address, &pretty);
- log_info("Synchronized to time server %s (%s).", strna(pretty), m->current_server_name->string);
- sd_notifyf(false, "STATUS=Synchronized to time server %s (%s).", strna(pretty), m->current_server_name->string);
+ /* "Initial", as further successful syncs will not be logged. */
+ log_info("Initial synchronization to time server %s (%s).", strna(pretty), m->current_server_name->string);
+ sd_notifyf(false, "STATUS=Initial synchronization to time server %s (%s).", strna(pretty), m->current_server_name->string);
}
r = manager_arm_timer(m, m->poll_interval_usec);
sd_resolve_unref(m->resolve);
sd_event_unref(m->event);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
free(m);
}
sd_network_monitor_flush(m->network_monitor);
/* When manager_network_read_link_servers() failed, we assume that the servers are changed. */
- changed = !!manager_network_read_link_servers(m);
+ changed = manager_network_read_link_servers(m);
/* check if the machine is online */
online = network_is_online();
m->server_socket = m->clock_watch_fd = -1;
- RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST);
+ m->ratelimit = (RateLimit) { RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST };
r = sd_event_default(&m->event);
if (r < 0)