X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fresolve%2Fresolved-manager.c;h=167bea39b372849c07ea76666134f87c32b87b9d;hp=c4a5b08773995b26b7c123f66f40fc703b52f6e5;hb=2eec67acbb00593e414549a7e5b35eb7dd776b1b;hpb=a5f035960006556beab51c42e6948985635e261a diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index c4a5b0877..167bea39b 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -19,18 +19,13 @@ along with systemd; If not, see . ***/ -#include #include -#include #include -#include +#include #include #include "rtnl-util.h" -#include "event-util.h" -#include "network-util.h" #include "network-internal.h" -#include "conf-parser.h" #include "socket-util.h" #include "af-list.h" #include "utf8.h" @@ -100,7 +95,7 @@ static int manager_process_link(sd_rtnl *rtnl, sd_rtnl_message *mm, void *userda return 0; fail: - log_warning("Failed to process RTNL link message: %s", strerror(-r)); + log_warning_errno(r, "Failed to process RTNL link message: %m"); return 0; } @@ -185,7 +180,7 @@ static int manager_process_address(sd_rtnl *rtnl, sd_rtnl_message *mm, void *use return 0; fail: - log_warning("Failed to process RTNL address message: %s", strerror(-r)); + log_warning_errno(r, "Failed to process RTNL address message: %m"); return 0; } @@ -196,7 +191,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; @@ -278,12 +273,12 @@ static int on_network_event(sd_event_source *s, int fd, uint32_t revents, void * HASHMAP_FOREACH(l, m->links, i) { r = link_update_monitor(l); if (r < 0) - log_warning("Failed to update monitor information for %i: %s", l->ifindex, strerror(-r)); + log_warning_errno(r, "Failed to update monitor information for %i: %m", l->ifindex); } r = manager_write_resolv_conf(m); if (r < 0) - log_warning("Could not update resolv.conf: %s", strerror(-r)); + log_warning_errno(r, "Could not update resolv.conf: %m"); return 0; } @@ -370,7 +365,7 @@ static int manager_watch_hostname(Manager *m) { m->hostname_fd = open("/proc/sys/kernel/hostname", O_RDONLY|O_CLOEXEC|O_NDELAY|O_NOCTTY); if (m->hostname_fd < 0) { - log_warning("Failed to watch hostname: %m"); + log_warning_errno(errno, "Failed to watch hostname: %m"); return 0; } @@ -379,10 +374,8 @@ static int manager_watch_hostname(Manager *m) { if (r == -EPERM) /* kernels prior to 3.2 don't support polling this file. Ignore the failure. */ m->hostname_fd = safe_close(m->hostname_fd); - else { - log_error("Failed to add hostname event source: %s", strerror(-r)); - return r; - } + else + return log_error_errno(r, "Failed to add hostname event source: %m"); } r = determine_hostname(&m->hostname); @@ -593,7 +586,7 @@ int manager_read_resolv_conf(Manager *m) { r = stat("/etc/resolv.conf", &st); if (r < 0) { if (errno != ENOENT) - log_warning("Failed to open /etc/resolv.conf: %m"); + log_warning_errno(errno, "Failed to open /etc/resolv.conf: %m"); r = -errno; goto clear; } @@ -616,13 +609,13 @@ int manager_read_resolv_conf(Manager *m) { f = fopen("/etc/resolv.conf", "re"); if (!f) { if (errno != ENOENT) - log_warning("Failed to open /etc/resolv.conf: %m"); + log_warning_errno(errno, "Failed to open /etc/resolv.conf: %m"); r = -errno; goto clear; } if (fstat(fileno(f), &st) < 0) { - log_error("Failed to stat open file: %m"); + log_error_errno(errno, "Failed to stat open file: %m"); r = -errno; goto clear; } @@ -669,6 +662,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: @@ -688,7 +691,7 @@ static void write_resolv_conf_server(DnsServer *s, FILE *f, unsigned *count) { r = in_addr_to_string(s->family, &s->address, &t); if (r < 0) { - log_warning("Invalid DNS address. Ignoring: %s", strerror(-r)); + log_warning_errno(r, "Invalid DNS address. Ignoring: %m"); return; }