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
+7
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());
}