]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: change error handling for manager_etc_hosts_read() 9770/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 1 Aug 2018 10:41:54 +0000 (12:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 1 Aug 2018 10:45:54 +0000 (12:45 +0200)
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

index 2adee0788977d6e3166962d97e33276928ad3519..5be62cc3a84f2014dbf5a6b2468dab21d86a725c 100644 (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)