Merge pull request #6348 from cole-h/fix-restoring-mount-namespace

libutil: Fix restoring mount namespace
This commit is contained in:
Eelco Dolstra 2022-04-07 18:15:33 +02:00 committed by GitHub
commit 8b1e328d5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1692,7 +1692,9 @@ void setStackSize(size_t stackSize)
#endif
}
#if __linux__
static AutoCloseFD fdSavedMountNamespace;
#endif
void saveMountNamespace()
{
@ -1711,8 +1713,13 @@ void restoreMountNamespace()
{
#if __linux__
try {
auto savedCwd = absPath(".");
if (fdSavedMountNamespace && setns(fdSavedMountNamespace.get(), CLONE_NEWNS) == -1)
throw SysError("restoring parent mount namespace");
if (chdir(savedCwd.c_str()) == -1) {
throw SysError("restoring cwd");
}
} catch (Error & e) {
debug(e.msg());
}