Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save cwd fd instead of path #6386

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/libutil/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1801,11 +1801,13 @@ void restoreMountNamespace()
{
#if __linux__
try {
auto savedCwd = absPath(".");

AutoCloseFD fdSavedCwd = open("/proc/self/cwd", O_RDONLY);
if (!fdSavedCwd) {
throw SysError("saving cwd");
}
if (fdSavedMountNamespace && setns(fdSavedMountNamespace.get(), CLONE_NEWNS) == -1)
throw SysError("restoring parent mount namespace");
if (chdir(savedCwd.c_str()) == -1) {
if (fdSavedCwd && fchdir(fdSavedCwd.get()) == -1) {
throw SysError("restoring cwd");
}
} catch (Error & e) {
Expand Down