Skip to content

Commit 7bd781d

Browse files
committed
Follow the trail when resolv.conf ain't home
When /etc is mounted as a whole directory, /etc/resolv.conf may be a symlink (e.g., to /run/systemd/resolve/stub-resolv.conf). Resolve the symlink and mount the slirp DNS config at the real target path, creating the parent directory if needed.
1 parent 504a398 commit 7bd781d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/bwrap.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,19 @@ run_in_bwrap() {
6464
done
6565

6666
# Override resolv.conf for slirp4netns network namespace (DNS at 10.0.2.3)
67+
# When /etc is mounted as a whole directory, /etc/resolv.conf may be a symlink
68+
# (e.g., → /run/systemd/resolve/stub-resolv.conf). We resolve the symlink and
69+
# mount at the real target so bwrap doesn't fail following a dangling symlink.
6770
if [ "${SLIRP_NETWORK:-}" = "1" ]; then
6871
local slirp_resolv
6972
slirp_resolv=$(mktemp)
7073
echo "nameserver 10.0.2.3" > "$slirp_resolv"
71-
bwrap_args+=(--ro-bind "$slirp_resolv" /etc/resolv.conf)
74+
local resolv_real
75+
resolv_real=$(realpath /etc/resolv.conf 2>/dev/null) || resolv_real="/etc/resolv.conf"
76+
if [ "$resolv_real" != "/etc/resolv.conf" ]; then
77+
bwrap_args+=(--dir "$(dirname "$resolv_real")")
78+
fi
79+
bwrap_args+=(--ro-bind "$slirp_resolv" "$resolv_real")
7280
fi
7381

7482
# Mask sensitive paths from config (dirs → tmpfs, files → /dev/null)

0 commit comments

Comments
 (0)