]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/resolved-manager.c
resolved: rework parsing of /etc/hosts
[thirdparty/systemd.git] / src / resolve / resolved-manager.c
index 8e564216ed26f9376e51cf0442a2d3cec302360b..2174d660ff0e781f97d014ae1a0074b521907ffa 100644 (file)
@@ -14,7 +14,7 @@
 #include "dirent-util.h"
 #include "dns-domain.h"
 #include "fd-util.h"
-#include "fileio-label.h"
+#include "fileio.h"
 #include "hostname-util.h"
 #include "io-util.h"
 #include "netlink-util.h"
@@ -24,8 +24,8 @@
 #include "random-util.h"
 #include "resolved-bus.h"
 #include "resolved-conf.h"
-#include "resolved-dnssd.h"
 #include "resolved-dns-stub.h"
+#include "resolved-dnssd.h"
 #include "resolved-etc-hosts.h"
 #include "resolved-llmnr.h"
 #include "resolved-manager.h"
@@ -336,10 +336,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
         r = dns_label_unescape(&p, label, sizeof label);
         if (r < 0)
                 return log_error_errno(r, "Failed to unescape host name: %m");
-        if (r == 0) {
-                log_error("Couldn't find a single label in hostname.");
-                return -EINVAL;
-        }
+        if (r == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Couldn't find a single label in hostname.");
 
 #if HAVE_LIBIDN2
         r = idn2_to_unicode_8z8z(label, &utf8, 0);
@@ -356,10 +355,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
         if (k > 0)
                 r = k;
 
-        if (!utf8_is_valid(label)) {
-                log_error("System hostname is not UTF-8 clean.");
-                return -EINVAL;
-        }
+        if (!utf8_is_valid(label))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "System hostname is not UTF-8 clean.");
         decoded = label;
 #else
         decoded = label; /* no decoding */
@@ -369,10 +367,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
         if (r < 0)
                 return log_error_errno(r, "Failed to escape host name: %m");
 
-        if (is_localhost(n)) {
-                log_debug("System hostname is 'localhost', ignoring.");
-                return -EINVAL;
-        }
+        if (is_localhost(n))
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "System hostname is 'localhost', ignoring.");
 
         r = dns_name_concat(n, "local", mdns_hostname);
         if (r < 0)
@@ -755,20 +752,17 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
         if (r < 0)
                 return r;
 
-        iov = (struct iovec) {
-                .iov_base = DNS_PACKET_DATA(p),
-                iov.iov_len = p->allocated,
-        };
+        iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->allocated);
 
         l = recvmsg(fd, &mh, 0);
-        if (l == 0)
-                return 0;
         if (l < 0) {
                 if (IN_SET(errno, EAGAIN, EINTR))
                         return 0;
 
                 return -errno;
         }
+        if (l == 0)
+                return 0;
 
         assert(!(mh.msg_flags & MSG_CTRUNC));
         assert(!(mh.msg_flags & MSG_TRUNC));
@@ -937,10 +931,7 @@ static int manager_ipv4_send(
         assert(port > 0);
         assert(p);
 
-        iov = (struct iovec) {
-                .iov_base = DNS_PACKET_DATA(p),
-                .iov_len = p->size,
-        };
+        iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->size);
 
         sa = (union sockaddr_union) {
                 .in.sin_family = AF_INET,
@@ -998,10 +989,7 @@ static int manager_ipv6_send(
         assert(port > 0);
         assert(p);
 
-        iov = (struct iovec) {
-                .iov_base = DNS_PACKET_DATA(p),
-                .iov_len = p->size,
-        };
+        iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->size);
 
         sa = (union sockaddr_union) {
                 .in6.sin6_family = AF_INET6,