aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-12-17 12:00:09 +0100
committerGitHub <noreply@github.com>2021-12-17 12:00:09 +0100
commit6e6e998930f0d7361d64644eb37d9134e74e8501 (patch)
tree16fe1dfff96b86df62b83e5fd57b9af21865172e
parent23ea1e46cc4831dd13915a2d7acd9f04696b6dcc (diff)
parentec8f24ed3a3115cba85f908515c423112e5b13e0 (diff)
Merge pull request #5787 from edolstra/unshare-fs
Ignore EPERM when unsharing FS state
-rw-r--r--src/libstore/filetransfer.cc8
-rw-r--r--src/libutil/util.cc8
-rw-r--r--src/libutil/util.hh5
3 files changed, 14 insertions, 7 deletions
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc
index 4621a8217..17980ab22 100644
--- a/src/libstore/filetransfer.cc
+++ b/src/libstore/filetransfer.cc
@@ -544,13 +544,7 @@ struct curlFileTransfer : public FileTransfer
stopWorkerThread();
});
-#ifdef __linux__
- /* Cause this thread to not share any FS attributes with the main thread,
- because this causes setns() in restoreMountNamespace() to fail.
- Ideally, this would happen in the std::thread() constructor. */
- if (unshare(CLONE_FS) != 0)
- throw SysError("unsharing filesystem state in download thread");
-#endif
+ unshareFilesystem();
std::map<CURL *, std::shared_ptr<TransferItem>> items;
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 1b6467eb2..43fea1b1e 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1660,6 +1660,14 @@ void restoreMountNamespace()
#endif
}
+void unshareFilesystem()
+{
+#ifdef __linux__
+ if (unshare(CLONE_FS) != 0 && errno != EPERM)
+ throw SysError("unsharing filesystem state in download thread");
+#endif
+}
+
void restoreProcessContext(bool restoreMounts)
{
restoreSignals();
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index bc96bfed1..4cc043a84 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -311,6 +311,11 @@ void saveMountNamespace();
if saveMountNamespace() was never called. */
void restoreMountNamespace();
+/* Cause this thread to not share any FS attributes with the main
+ thread, because this causes setns() in restoreMountNamespace() to
+ fail. */
+void unshareFilesystem();
+
class ExecError : public Error
{