chiark / gitweb /
fsckd: the error code is actually returned in 'fd'
[elogind.git] / src / timesync / timesyncd-manager.c
index 117ea8c98d83c495edb043e566951a5a7f25603f..a9e91c4d60645fa6d1e59fab2b68fb9db15f7b68 100644 (file)
 
 #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"
@@ -98,7 +87,7 @@
  * "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)
@@ -285,7 +274,7 @@ static int manager_clock_watch(sd_event_source *source, int fd, uint32_t revents
         }
 
         /* resync */
-        log_info("System time changed. Resyncing.");
+        log_debug("System time changed. Resyncing.");
         m->poll_resync = true;
 
         return manager_send_request(m);
@@ -525,7 +514,8 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
                 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);
         }
@@ -675,9 +665,9 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
                         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)
@@ -739,7 +729,7 @@ static int manager_begin(Manager *m) {
                 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);