]> git.ipfire.org Git - thirdparty/systemd.git/commit
resolve: reload /etc/hosts on inode change
authorGiedrius Statkevičius <giedriuswork@gmail.com>
Sun, 22 Mar 2020 20:40:18 +0000 (22:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Apr 2020 15:34:10 +0000 (17:34 +0200)
commitaa5408e2e8a66b71f38531f1dcb91252c586a23c
treed8a03ef2c97b56f36f2d70cea9bf349b4497f745
parent50f5e2e2817d3435a1d6c0ce0d434efe5dcc2748
resolve: reload /etc/hosts on inode change

On certain distributions such as NixOS the mtime of `/etc/hosts` is
locked to a fixed value. In such cases, only checking the last mtime of
`/etc/hosts` is not enough - we also need to check if the st_ino/st_dev
match up. Thus, let's make sure make sure that systemd-resolved also
rereads `/etc/hosts` if the inode or the device containing `/etc/hosts` changes.

Test script:

```bash
hosts="/etc/hosts"
echo "127.0.0.1 testpr" > "hosts_new"
mv "hosts_new" "$hosts"
resolvectl query testpr || exit 1
mtime="$(stat -c %y "$hosts")"
echo "127.0.0.1 newhost" > "hosts_tmp"
touch -d "$mtime" "hosts_tmp"
install -p "hosts_tmp" "$hosts"
sleep 10
resolvectl query newhost || exit 1
rm -f "hosts_tmp"
```

Closes #14456.
src/resolve/resolved-etc-hosts.c
src/resolve/resolved-manager.c
src/resolve/resolved-manager.h