#include <stdlib.h>
#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
#include <time.h>
#include <math.h>
-#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <sys/timerfd.h>
#include <sys/timex.h>
#include <sys/socket.h>
#include <resolv.h>
-#include <sys/prctl.h>
#include <sys/types.h>
-#include <grp.h>
#include "missing.h"
#include "util.h"
#include "list.h"
#include "ratelimit.h"
#include "strv.h"
-#include "conf-parser.h"
#include "sd-daemon.h"
-#include "event-util.h"
#include "network-util.h"
-#include "clock-util.h"
-#include "capability.h"
-#include "mkdir.h"
#include "timesyncd-conf.h"
#include "timesyncd-manager.h"
#include "time-util.h"
* "NTP timestamps are represented as a 64-bit unsigned fixed-point number,
* in seconds relative to 0h on 1 January 1900."
*/
-#define OFFSET_1900_1970 2208988800UL
+#define OFFSET_1900_1970 UINT64_C(2208988800)
#define RETRY_USEC (30*USEC_PER_SEC)
#define RATELIMIT_INTERVAL_USEC (10*USEC_PER_SEC)
return ts->tv_sec + (1.0e-9 * ts->tv_nsec);
}
-static double square(double d) {
- return d * d;
-}
-
static int manager_timeout(sd_event_source *source, usec_t usec, void *userdata) {
_cleanup_free_ char *pretty = NULL;
Manager *m = userdata;
}
/* resync */
- log_info("System time changed. Resyncing.");
+ log_debug("System time changed. Resyncing.");
m->poll_resync = true;
return manager_send_request(m);
j = 0;
for (i = 0; i < ELEMENTSOF(m->samples); i++)
- j += square(m->samples[i].offset - m->samples[idx_min].offset);
+ j += pow(m->samples[i].offset - m->samples[idx_min].offset, 2);
m->samples_jitter = sqrt(j / (ELEMENTSOF(m->samples) - 1));
/* ignore samples when resyncing */
return manager_connect(m);
}
- if (iov.iov_len < sizeof(struct ntp_msg)) {
+ /* Too short or too long packet? */
+ if (iov.iov_len < sizeof(struct ntp_msg) || (msghdr.msg_flags & MSG_TRUNC)) {
log_warning("Invalid response from server. Disconnecting.");
return manager_connect(m);
}
log_error_errno(errno, "Failed to call clock_adjtime(): %m");
}
- log_info("interval/delta/delay/jitter/drift " USEC_FMT "s/%+.3fs/%.3fs/%.3fs/%+ippm%s",
- m->poll_interval_usec / USEC_PER_SEC, offset, delay, m->samples_jitter, m->drift_ppm,
- spike ? " (ignored)" : "");
+ log_debug("interval/delta/delay/jitter/drift " USEC_FMT "s/%+.3fs/%.3fs/%.3fs/%+ippm%s",
+ m->poll_interval_usec / USEC_PER_SEC, offset, delay, m->samples_jitter, m->drift_ppm,
+ spike ? " (ignored)" : "");
r = manager_arm_timer(m, m->poll_interval_usec);
if (r < 0)
m->poll_interval_usec = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
server_address_pretty(m->current_server_address, &pretty);
- log_info("Using NTP server %s (%s).", strna(pretty), m->current_server_name->string);
+ log_debug("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_clock_watch_setup(m);