lix/src
aszlig 435848cef1 libutil: Fix restoring mount namespace
I regularly pass around simple scripts by using nix-shell as the script
interpreter, eg. like this:

    #!/usr/bin/env nix-shell
    #!nix-shell -p dd_rescue coreutils bash -i bash

While this works most of the time, I recently had one occasion where it
would not and the above would result in the following:

    $ sudo ./myscript.sh
    bash: ./myscript.sh: No such file or directory

Note the "sudo" here, because this error only occurs if we're root.

The reason for the latter is because running Nix as root means that we
can directly access the store, which makes sure we use a filesystem
namespace to make the store writable. XXX - REWORD!

So when stracing the process, I stumbled on the following sequence:

    openat(AT_FDCWD, "/proc/self/ns/mnt", O_RDONLY) = 3
    unshare(CLONE_NEWNS)                            = 0
    ... later ...
    getcwd("/the/real/cwd", 4096)                   = 14
    setns(3, CLONE_NEWNS)                           = 0
    getcwd("/", 4096)                               = 2

In the whole strace output there are no calls to chdir() whatsoever, so
I decided to look into the kernel source to see what else could change
directories and found this[1]:

    /* Update the pwd and root */
    set_fs_pwd(fs, &root);
    set_fs_root(fs, &root);

The set_fs_pwd() call is roughly equivalent to a chdir() syscall and
this is called when the setns() syscall is invoked[2].

[1]: b14ffae378/fs/namespace.c (L4659)
[2]: b14ffae378/kernel/nsproxy.c (L346)
2022-04-01 09:30:52 -07:00
..
build-remote Generalize DerivationType in preparation for impure derivations 2022-03-18 14:59:56 +00:00
libcmd nix profile install: Don't use queryDerivationOutputMap() 2022-03-28 14:23:39 +02:00
libexpr Fix handling of outputHash when outputHashAlgo is not specified 2022-04-01 12:40:49 +02:00
libfetchers Don't partial match sourcehut refs 2022-03-19 11:04:04 -03:00
libmain Factor out a GcStore interface 2022-03-03 19:01:25 +00:00
libstore Fix macOS build 2022-03-31 16:39:18 +02:00
libutil libutil: Fix restoring mount namespace 2022-04-01 09:30:52 -07:00
nix Merge pull request #6344 from flox/profile_url_uri 2022-04-01 14:38:32 +02:00
nix-build Desugar StorePathWithOutputs in nix-build implementation 2022-03-11 20:50:52 +00:00
nix-channel Fix segfault in headerCallback() 2022-03-03 11:11:16 +01:00
nix-collect-garbage Deduplicate the Store downcasting with a template 2022-03-11 13:32:33 +00:00
nix-copy-closure copyPaths: Pass store by reference 2021-07-22 09:59:51 +02:00
nix-env Don't hide repeated values while generating manifest.nix 2022-03-22 13:18:56 +01:00
nix-instantiate Add EvalState::coerceToStorePath() helper 2022-03-02 23:58:58 +01:00
nix-store Deduplicate the Store downcasting with a template 2022-03-11 13:32:33 +00:00
resolve-system-dependencies Fix macOS build 2022-02-21 17:14:22 +01:00
toml11 Replace cpptoml with toml11 2021-12-17 22:03:33 +01:00