Skip to content

Commit

Permalink
Only unshare FS state if we've saved the mount namespace
Browse files Browse the repository at this point in the history
Attempted fix for NixOS#5777.
  • Loading branch information
edolstra committed Dec 16, 2021
1 parent 7caf9f3 commit 5f1daf6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions doc/manual/src/installation/installing-docker.md
Expand Up @@ -16,7 +16,7 @@ nix (Nix) 2.3.12
35ca4ada6e96:/# exit
```

# What is included in Nix' Docker image?
# What is included in Nix's Docker image?

The official Docker image is created using `pkgs.dockerTools.buildLayeredImage`
(and not with `Dockerfile` as it is usual with Docker images). You can still
Expand Down Expand Up @@ -54,6 +54,6 @@ You can also build a Docker image from source yourself:

```console
$ nix build ./\#hydraJobs.dockerImage.x86_64-linux
$ docker load -i ./result
$ docker load -i ./result/image.tar.gz
$ docker run -ti nix:2.5pre20211105
```
8 changes: 1 addition & 7 deletions src/libstore/filetransfer.cc
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/libutil/util.cc
Expand Up @@ -1660,6 +1660,14 @@ void restoreMountNamespace()
#endif
}

void unshareFilesystem()
{
#ifdef __linux__
if (fdSavedMountNamespace && unshare(CLONE_FS) != 0)
throw SysError("unsharing filesystem state in download thread");
#endif
}

void restoreProcessContext(bool restoreMounts)
{
restoreSignals();
Expand Down
5 changes: 5 additions & 0 deletions src/libutil/util.hh
Expand Up @@ -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
{
Expand Down

0 comments on commit 5f1daf6

Please sign in to comment.