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
This commit is contained in:
parent
10b9c1b2b2
commit
56009b2639
1 changed files with 3 additions and 5 deletions
|
@ -1709,13 +1709,11 @@ void restoreMountNamespace()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#if __linux__
|
||||||
try {
|
try {
|
||||||
AutoCloseFD fdSavedCwd = open("/proc/self/cwd", O_RDONLY);
|
auto savedCwd = absPath(".");
|
||||||
if (!fdSavedCwd) {
|
|
||||||
throw SysError("saving cwd");
|
|
||||||
}
|
|
||||||
if (fdSavedMountNamespace && setns(fdSavedMountNamespace.get(), CLONE_NEWNS) == -1)
|
if (fdSavedMountNamespace && setns(fdSavedMountNamespace.get(), CLONE_NEWNS) == -1)
|
||||||
throw SysError("restoring parent mount namespace");
|
throw SysError("restoring parent mount namespace");
|
||||||
if (fdSavedCwd && fchdir(fdSavedCwd.get()) == -1) {
|
if (chdir(savedCwd.c_str()) == -1) {
|
||||||
throw SysError("restoring cwd");
|
throw SysError("restoring cwd");
|
||||||
}
|
}
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|
Loading…
Reference in a new issue