chiark / gitweb /
timesyncd: add sockaddr_pretty wrapper
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 14 Jul 2014 22:29:27 +0000 (18:29 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Jul 2014 13:53:18 +0000 (09:53 -0400)
src/timesync/timesyncd.c
src/timesync/timesyncd.h

index e15588d..78ef5f7 100644 (file)
@@ -210,7 +210,7 @@ static int manager_timeout(sd_event_source *source, usec_t usec, void *userdata)
         assert(m->current_server_name);
         assert(m->current_server_address);
 
-        sockaddr_pretty(&m->current_server_address->sockaddr.sa, m->current_server_address->socklen, true, &pretty);
+        server_address_pretty(m->current_server_address, &pretty);
         log_info("Timed out waiting for reply from %s (%s).", strna(pretty), m->current_server_name->string);
 
         return manager_connect(m);
@@ -250,7 +250,7 @@ static int manager_send_request(Manager *m) {
         ntpmsg.trans_time.sec = htobe32(m->trans_time.tv_sec + OFFSET_1900_1970);
         ntpmsg.trans_time.frac = htobe32(m->trans_time.tv_nsec);
 
-        sockaddr_pretty(&m->current_server_address->sockaddr.sa, m->current_server_address->socklen, true, &pretty);
+        server_address_pretty(m->current_server_address, &pretty);
 
         len = sendto(m->server_socket, &ntpmsg, sizeof(ntpmsg), MSG_DONTWAIT, &m->current_server_address->sockaddr.sa, m->current_server_address->socklen);
         if (len == sizeof(ntpmsg)) {
@@ -782,7 +782,7 @@ static int manager_begin(Manager *m) {
 
         m->poll_interval_usec = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
 
-        sockaddr_pretty(&m->current_server_address->sockaddr.sa, m->current_server_address->socklen, true, &pretty);
+        server_address_pretty(m->current_server_address, &pretty);
         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);
 
index 4afe4b9..52cca6d 100644 (file)
@@ -42,6 +42,10 @@ struct ServerName {
         LIST_FIELDS(ServerName, names);
 };
 
+static inline int server_address_pretty(ServerAddress *a, char **pretty) {
+        return sockaddr_pretty(&a->sockaddr.sa, a->socklen, true, pretty);
+}
+
 struct Manager {
         sd_event *event;
         sd_resolve *resolve;