diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-11-06 14:56:16 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-12-08 18:08:31 +0100 |
commit | a2a88a4e510029a72ee826082811c90a625606c3 (patch) | |
tree | 3d02a2c762fda8c8f7a0fda0fcd51aa76a2fc819 | |
parent | c846d1fb0d2a297a25102b6b2ace31494db9a8fd (diff) | |
download | systemd-a2a88a4e510029a72ee826082811c90a625606c3.tar.gz |
resolved: use stat_inode_unmodified() to detect /etc/hosts changes
(cherry picked from commit 36d892b7e6753dfc67110b57c55864647a04c5cb)
-rw-r--r-- | src/resolve/resolved-etc-hosts.c | 14 | ||||
-rw-r--r-- | src/resolve/resolved-manager.c | 3 | ||||
-rw-r--r-- | src/resolve/resolved-manager.h | 5 |
3 files changed, 7 insertions, 15 deletions
diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 6a7f749957..9ce6277295 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -10,6 +10,7 @@ #include "resolved-dns-synthesize.h" #include "resolved-etc-hosts.h" #include "socket-netlink.h" +#include "stat-util.h" #include "string-util.h" #include "strv.h" #include "time-util.h" @@ -36,9 +37,7 @@ void etc_hosts_free(EtcHosts *hosts) { void manager_etc_hosts_flush(Manager *m) { etc_hosts_free(&m->etc_hosts); - m->etc_hosts_mtime = USEC_INFINITY; - m->etc_hosts_ino = 0; - m->etc_hosts_dev = 0; + m->etc_hosts_stat = (struct stat) {}; } static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) { @@ -212,7 +211,7 @@ static int manager_etc_hosts_read(Manager *m) { m->etc_hosts_last = ts; - if (m->etc_hosts_mtime != USEC_INFINITY) { + if (m->etc_hosts_stat.st_mode != 0) { if (stat("/etc/hosts", &st) < 0) { if (errno != ENOENT) return log_error_errno(errno, "Failed to stat /etc/hosts: %m"); @@ -222,8 +221,7 @@ static int manager_etc_hosts_read(Manager *m) { } /* Did the mtime or ino/dev change? If not, there's no point in re-reading the file. */ - if (timespec_load(&st.st_mtim) == m->etc_hosts_mtime && - st.st_ino == m->etc_hosts_ino && st.st_dev == m->etc_hosts_dev) + if (stat_inode_unmodified(&m->etc_hosts_stat, &st)) return 0; } @@ -246,9 +244,7 @@ static int manager_etc_hosts_read(Manager *m) { if (r < 0) return r; - m->etc_hosts_mtime = timespec_load(&st.st_mtim); - m->etc_hosts_ino = st.st_ino; - m->etc_hosts_dev = st.st_dev; + m->etc_hosts_stat = st; m->etc_hosts_last = ts; return 1; diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index c2cf2b7b84..09eb6adfce 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -591,9 +591,6 @@ int manager_new(Manager **ret) { .read_resolv_conf = true, .need_builtin_fallbacks = true, .etc_hosts_last = USEC_INFINITY, - .etc_hosts_mtime = USEC_INFINITY, - .etc_hosts_ino = 0, - .etc_hosts_dev = 0, .read_etc_hosts = true, }; diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h index 59944df746..b7bdcaa399 100644 --- a/src/resolve/resolved-manager.h +++ b/src/resolve/resolved-manager.h @@ -127,9 +127,8 @@ struct Manager { /* Data from /etc/hosts */ EtcHosts etc_hosts; - usec_t etc_hosts_last, etc_hosts_mtime; - ino_t etc_hosts_ino; - dev_t etc_hosts_dev; + usec_t etc_hosts_last; + struct stat etc_hosts_stat; bool read_etc_hosts; /* Local DNS stub on 127.0.0.53:53 */ |