From: Zbigniew Jędrzejewski-Szmek Date: Wed, 1 Aug 2018 10:41:54 +0000 (+0200) Subject: resolved: change error handling for manager_etc_hosts_read() X-Git-Tag: v240~874^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9770%2Fhead;p=thirdparty%2Fsystemd.git 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. --- 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)