aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorCole Helbling <cole.e.helbling@outlook.com>2022-04-04 10:21:56 -0700
committerCole Helbling <cole.e.helbling@outlook.com>2022-04-04 10:28:08 -0700
commit56009b2639dc878be11f94d096fae56ac14dcd1d (patch)
treeb53b80b1b0e03161902493c8710736969a7d56d0 /src/libutil
parent10b9c1b2b269b96dcb8b3d298491fa143d1663e8 (diff)
libutil: don't save cwd fd, use path instead
Saving the cwd fd didn't actually work well -- prior to this commit, the following would happen: : ~/w/vc/nix ; doas outputs/out/bin/nix --experimental-features 'nix-command flakes' run nixpkgs#coreutils -- --coreutils-prog=pwd pwd: couldn't find directory entry in ‘../../../..’ with matching i-node : ~/w/vc/nix ; doas outputs/out/bin/nix --experimental-features 'nix-command flakes' develop -c pwd pwd: couldn't find directory entry in ‘../../../..’ with matching i-node
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 701545589..3132e7161 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1709,13 +1709,11 @@ void restoreMountNamespace()
{
#if __linux__
try {
- AutoCloseFD fdSavedCwd = open("/proc/self/cwd", O_RDONLY);
- if (!fdSavedCwd) {
- throw SysError("saving cwd");
- }
+ auto savedCwd = absPath(".");
+
if (fdSavedMountNamespace && setns(fdSavedMountNamespace.get(), CLONE_NEWNS) == -1)
throw SysError("restoring parent mount namespace");
- if (fdSavedCwd && fchdir(fdSavedCwd.get()) == -1) {
+ if (chdir(savedCwd.c_str()) == -1) {
throw SysError("restoring cwd");
}
} catch (Error & e) {