From 7aebe9181068d7313a4b10f56df00adad2b0e924 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 8 Apr 2022 08:25:10 -0700 Subject: [PATCH] Revert "libutil: don't save cwd fd, use path instead" This reverts commit 56009b2639dc878be11f94d096fae56ac14dcd1d. --- src/libutil/util.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 885bae69c9b..dcbe92ebce7 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -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) {