chiark / gitweb /
tree-wide: Always use recvmsg with MSG_CMSG_CLOEXEC
[elogind.git] / src / resolve / resolved-manager.c
index 0594479787606127426a59e9b2a477f4352735e7..d5c1bf0fbda2c6dc695a890b6d3dc5c8cf1e3863 100644 (file)
@@ -196,7 +196,7 @@ static int manager_rtnl_listen(Manager *m) {
 
         assert(m);
 
-        /* First, subscibe to interfaces coming and going */
+        /* First, subscribe to interfaces coming and going */
         r = sd_rtnl_open(&m->rtnl, 3, RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR);
         if (r < 0)
                 return r;
@@ -667,6 +667,16 @@ int manager_read_resolv_conf(Manager *m) {
                 if (s->marked)
                         dns_server_free(s);
 
+        /* Whenever /etc/resolv.conf changes, start using the first
+         * DNS server of it. This is useful to deal with broken
+         * network managing implementations (like NetworkManager),
+         * that when connecting to a VPN place both the VPN DNS
+         * servers and the local ones in /etc/resolv.conf. Without
+         * resetting the DNS server to use back to the first entry we
+         * will continue to use the local one thus being unable to
+         * resolve VPN domains. */
+        manager_set_dns_server(m, m->dns_servers);
+
         return 0;
 
 clear:
@@ -882,7 +892,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
         mh.msg_control = &control;
         mh.msg_controllen = sizeof(control);
 
-        l = recvmsg(fd, &mh, 0);
+        l = recvmsg(fd, &mh, MSG_CMSG_CLOEXEC);
         if (l < 0) {
                 if (errno == EAGAIN || errno == EINTR)
                         return 0;