summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-resolv-conf.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 17:59:40 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-25 21:58:37 +0100
commit0eac462399c8e87bcce252cf058eba9f2678f2bd (patch)
tree31f3297ad47d256ebcc5dba55697e21431341174 /src/resolve/resolved-resolv-conf.c
parentf2f1dbe50fea13abadc9c1e845a29031b90b40f3 (diff)
resolved: rework dns server lifecycle logic
Previously, there was a chance of memory corruption, because when switching to the next DNS server we didn't care whether they linked list of DNS servers was still valid. Clean up lifecycle of the dns server logic: - When a DnsServer object is still in the linked list of DnsServers for a link or the manager, indicate so with a "linked" boolean field, and never follow the linked list if that boolean is not set. - When picking a DnsServer to use for a link ot manager, always explicitly take a reference. This also rearranges some logic, to make the tracking of dns servers by link and globally more alike.
Diffstat (limited to 'src/resolve/resolved-resolv-conf.c')
-rw-r--r--src/resolve/resolved-resolv-conf.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c
index 5a6e3812df..98c1720f0f 100644
--- a/src/resolve/resolved-resolv-conf.c
+++ b/src/resolve/resolved-resolv-conf.c
@@ -36,7 +36,6 @@ int manager_read_resolv_conf(Manager *m) {
_cleanup_fclose_ FILE *f = NULL;
struct stat st, own;
char line[LINE_MAX];
- DnsServer *s;
usec_t t;
int r;
@@ -53,7 +52,7 @@ int manager_read_resolv_conf(Manager *m) {
if (errno == ENOENT)
r = 0;
else
- r = log_warning_errno(errno, "Failed to open /etc/resolv.conf: %m");
+ r = log_warning_errno(errno, "Failed to stat /etc/resolv.conf: %m");
goto clear;
}
@@ -89,7 +88,6 @@ int manager_read_resolv_conf(Manager *m) {
manager_mark_dns_servers(m, DNS_SERVER_SYSTEM);
FOREACH_LINE(line, f, r = -errno; goto clear) {
- _cleanup_strv_free_ char **d = NULL;
const char *a;
char *l;
@@ -124,13 +122,7 @@ int manager_read_resolv_conf(Manager *m) {
return 0;
clear:
- while (m->dns_servers) {
- s = m->dns_servers;
-
- LIST_REMOVE(servers, m->dns_servers, s);
- dns_server_unref(s);
- }
-
+ manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
return r;
}