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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-08-01 12:41:54 +02:00
parent fd373593ba
commit be19cdf31c
1 changed files with 3 additions and 7 deletions

View File

@ -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)