aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-04-07 18:15:33 +0200
committerGitHub <noreply@github.com>2022-04-07 18:15:33 +0200
commit8b1e328d5d0ae7d3a4a8f6012ec065b59674ed4a (patch)
tree278c6fc1b80ecf4df00600cdaa676271ff2277da /src
parentb53e0a6aa02f1719950bdb5d3da94e56ded8ce09 (diff)
parent56009b2639dc878be11f94d096fae56ac14dcd1d (diff)
Merge pull request #6348 from cole-h/fix-restoring-mount-namespace
libutil: Fix restoring mount namespace
Diffstat (limited to 'src')
-rw-r--r--src/libutil/util.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index bc24201d5..c075a14b4 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -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());
}