From be19cdf31c8665f149f34617cab7104832e3a9d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 1 Aug 2018 12:41:54 +0200 Subject: [PATCH] resolved: change error handling for manager_etc_hosts_read() The choice what errors to ignore is left to the caller, and the caller is changed to ignore all errors. On error, previously read data is kept. So if e.g. an oom error happens, we will continue to return slightly stale data instead of pretending we have no entries for the given address. I think that's better, for example when /etc/hosts contains some important overrides that external DNS should not be queried for. --- src/resolve/resolved-etc-hosts.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 2adee078897..5be62cc3a84 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -181,6 +181,7 @@ int etc_hosts_parse(EtcHosts *hosts, FILE *f) { return r; } + etc_hosts_free(hosts); *hosts = t; t = (EtcHosts) {}; /* prevent cleanup */ return 0; @@ -229,11 +230,8 @@ static int manager_etc_hosts_read(Manager *m) { if (r < 0) return log_error_errno(errno, "Failed to fstat() /etc/hosts: %m"); - manager_etc_hosts_flush(m); - r = etc_hosts_parse(&m->etc_hosts, f); - if (r == -ENOMEM) - /* On OOM we bail. All other errors we ignore and proceed. */ + if (r < 0) return r; m->etc_hosts_mtime = timespec_load(&st.st_mtim); @@ -258,9 +256,7 @@ int manager_etc_hosts_lookup(Manager *m, DnsQuestion* q, DnsAnswer **answer) { if (!m->read_etc_hosts) return 0; - r = manager_etc_hosts_read(m); - if (r < 0) - return r; + (void) manager_etc_hosts_read(m); name = dns_question_first_name(q); if (!name) -- 2.47.3