diff options
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-conf.c | 16 | ||||
-rw-r--r-- | src/resolve/resolved-dns-server.c | 12 | ||||
-rw-r--r-- | src/resolve/resolved-dns-server.h | 6 | ||||
-rw-r--r-- | src/resolve/resolved-manager.c | 18 | ||||
-rw-r--r-- | src/resolve/resolved-manager.h | 2 |
5 files changed, 28 insertions, 26 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index ae3773f4f7..63e87f8df5 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -81,7 +81,6 @@ int config_parse_dnsv( void *userdata) { Manager *m = userdata; - DnsServer **l; int r; assert(filename); @@ -89,19 +88,10 @@ int config_parse_dnsv( assert(rvalue); assert(m); - if (ltype == DNS_SERVER_FALLBACK) - l = &m->fallback_dns_servers; - else - l = &m->dns_servers; - - if (isempty(rvalue)) { - + if (isempty(rvalue)) /* Empty assignment means clear the list */ - while (*l) - dns_server_free(*l); - - } else { - + manager_flush_dns_servers(m, ltype); + else { /* Otherwise add to the list */ r = manager_parse_dns_server(m, ltype, rvalue); if (r < 0) { diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c index 043f6b637d..c99768be4f 100644 --- a/src/resolve/resolved-dns-server.c +++ b/src/resolve/resolved-dns-server.c @@ -64,9 +64,9 @@ int dns_server_new( * we used so far was a fallback one? Then let's try to pick * the new one */ if (type != DNS_SERVER_FALLBACK && - s->manager->current_dns_server && - s->manager->current_dns_server->type == DNS_SERVER_FALLBACK) - manager_set_dns_server(s->manager, NULL); + m->current_dns_server && + m->current_dns_server->type == DNS_SERVER_FALLBACK) + manager_set_dns_server(m, NULL); if (ret) *ret = s; @@ -87,14 +87,14 @@ DnsServer* dns_server_free(DnsServer *s) { LIST_REMOVE(servers, s->manager->fallback_dns_servers, s); else assert_not_reached("Unknown server type"); + + if (s->manager->current_dns_server == s) + manager_set_dns_server(s->manager, NULL); } if (s->link && s->link->current_dns_server == s) link_set_dns_server(s->link, NULL); - if (s->manager && s->manager->current_dns_server == s) - manager_set_dns_server(s->manager, NULL); - free(s); return NULL; diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h index 5178a6be7e..f2361a8385 100644 --- a/src/resolve/resolved-dns-server.h +++ b/src/resolve/resolved-dns-server.h @@ -26,15 +26,15 @@ typedef struct DnsServer DnsServer; typedef enum DnsServerSource DnsServerSource; -#include "resolved-manager.h" -#include "resolved-link.h" - typedef enum DnsServerType { DNS_SERVER_SYSTEM, DNS_SERVER_FALLBACK, DNS_SERVER_LINK, } DnsServerType; +#include "resolved-manager.h" +#include "resolved-link.h" + struct DnsServer { Manager *manager; diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 6bb089451f..a2de2edb48 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -536,10 +536,8 @@ Manager *manager_free(Manager *m) { dns_scope_free(m->unicast_scope); - while (m->dns_servers) - dns_server_free(m->dns_servers); - while (m->fallback_dns_servers) - dns_server_free(m->fallback_dns_servers); + manager_flush_dns_servers(m, DNS_SERVER_SYSTEM); + manager_flush_dns_servers(m, DNS_SERVER_FALLBACK); hashmap_free(m->links); hashmap_free(m->dns_transactions); @@ -1771,6 +1769,18 @@ void manager_verify_all(Manager *m) { dns_zone_verify_all(&s->zone); } +void manager_flush_dns_servers(Manager *m, DnsServerType t) { + assert(m); + + if (t == DNS_SERVER_SYSTEM) + while (m->dns_servers) + dns_server_free(m->dns_servers); + + if (t == DNS_SERVER_FALLBACK) + while (m->fallback_dns_servers) + dns_server_free(m->fallback_dns_servers); +} + static const char* const support_table[_SUPPORT_MAX] = { [SUPPORT_NO] = "no", [SUPPORT_YES] = "yes", diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h index f8cb91c330..78cbfc0b03 100644 --- a/src/resolve/resolved-manager.h +++ b/src/resolve/resolved-manager.h @@ -151,6 +151,8 @@ DnsScope* manager_find_scope(Manager *m, DnsPacket *p); void manager_verify_all(Manager *m); +void manager_flush_dns_servers(Manager *m, DnsServerType t); + DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); #define EXTRA_CMSG_SPACE 1024 |