aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorCole Helbling <cole.e.helbling@outlook.com>2022-04-04 08:32:45 -0700
committerCole Helbling <cole.e.helbling@outlook.com>2022-04-04 08:32:45 -0700
commite135d223f66f77f2b03a11b979d714e582364013 (patch)
tree755f73c88897a75669a9573f4680f736a87121c7 /src/libutil
parente5b70d47aa656833e4609106f9f1ef48b67664cc (diff)
libutil: save fd to cwd instead of cwd itself
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 9b34d5d72..a00a03978 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1690,7 +1690,7 @@ void setStackSize(size_t stackSize)
#if __linux__
static AutoCloseFD fdSavedMountNamespace;
-std::optional<Path> savedCwd;
+static AutoCloseFD fdSavedCwd;
#endif
void saveMountNamespace()
@@ -1698,11 +1698,15 @@ void saveMountNamespace()
#if __linux__
static std::once_flag done;
std::call_once(done, []() {
- savedCwd = absPath(".");
AutoCloseFD fd = open("/proc/self/ns/mnt", O_RDONLY);
if (!fd)
throw SysError("saving parent mount namespace");
fdSavedMountNamespace = std::move(fd);
+
+ fd = open("/proc/self/cwd", O_RDONLY);
+ if (!fd)
+ throw SysError("saving cwd");
+ fdSavedCwd = std::move(fd);
});
#endif
}
@@ -1716,7 +1720,7 @@ void restoreMountNamespace()
} catch (Error & e) {
debug(e.msg());
}
- if (savedCwd && chdir(savedCwd->c_str()) == -1) {
+ if (fdSavedCwd && fchdir(fdSavedCwd.get()) == -1) {
throw SysError("restoring cwd");
}
#endif