Théophane Hufschmitt
150f3bb5ea
nix-find-roots: Cleanup
...
Based on an offline review by @mopleen (thanks!)
2023-06-26 10:41:08 +02:00
Théophane Hufschmitt
c4ca0d45cb
nix-find-roots: Don't assume that argv[0] exists
2023-06-26 10:41:08 +02:00
Théophane Hufschmitt
65387ad3ea
Remove the NIX_GC_SOCKET_PATH environment variable
...
Not really needed since it's configurable from the config (and people
can always use `$NIX_CONFIG` if they really need to configure it from
the CLI)
2023-06-26 10:41:06 +02:00
Théophane Hufschmitt
19d7d7ac42
switch nixpkgs to nixos-22.05
2022-07-01 10:59:46 +02:00
Théophane Hufschmitt
060bfe5084
Add a missing optional include
...
Fix the build with GCC 11.3.0
2022-07-01 09:46:31 +02:00
Théophane Hufschmitt
7299ad523b
nix-find-roots: Properly fail if the socket filename is too long
...
Otherwise we get a buffer overflow, and bad things can happen
2022-06-23 11:19:45 +02:00
Théophane Hufschmitt
2d651ad2d0
Always throw the right exception in connect
...
When `nix::connect` is called with a socket path that's too long, it
forks a process that will `chdir` to the directory of the socket path
and call `::connect` with the relative path (which is hopefully
short-enough).
That works fairly well, except that an exception raised in this
subprocess won't be forwarded to the parent process. Instead the logic
will just notice that the subprocess exited with a non-zero error code,
and throw a generic `Error`. In particular, any failure in the
`::connect` call should throw a `SysError` with the correct error code,
but that's not the case.
Some places try to catch this `SysError` and look at its error code (to
potentially restart for example). But this doesn't work since the
actual error that gets thrown isn't a `SysError`.
Fix that by forwarding the `errno` in case something gets wrong (by
setting the subprocess exit code to it), and throwing a `SysError` with
the right error code in the parent process.
2022-06-15 18:07:13 +02:00
Théophane Hufschmitt
6c0e7450de
Allow the gc roots daemon to use a long socket path
...
`chdir` to the directory of the socket and only use a relative path to
it to bypass the socket path length limit (like it's done in
`nix::bind`, except that there's no need to fork here since we can
afford changing the directory of the process)
2022-06-14 16:49:12 +02:00
Théophane Hufschmitt
5c6b9bc361
Use the Nix wrappers to connect to the gc socket
...
These have a nice mechanism to bypass the absurdly low OSX socket path
length limit (needed for the CI to pass)
2022-04-13 10:25:20 +02:00
Théophane Hufschmitt
40e95a2e30
Fix the build on darwin
...
`MSG_NOSIGNAL` doesn’t exist on darwin, so globally ignore the `SIGPIPE`
signal instead.
2022-04-13 10:25:20 +02:00
Théophane Hufschmitt
988c51de7f
tests: Make clearStore more resilient
...
Let it work if `$NIX_STORE_DIR` doesn’t exist
2022-04-13 10:25:20 +02:00
Théophane Hufschmitt
ef644ec753
nix-find-roots: Ignore SIGPIPEs
...
Prevent the daemon from crashing if the client stops receiving in the
middle of the transmission.
Also fix a potential off-by-a-few error
2022-04-13 10:25:20 +02:00
Théophane Hufschmitt
aa97c4f9f2
find-roots: Fix --help and invalid cli flags
...
- Make `--help` and `-h` valid cli flags that show the (short) help
- Prevent the program from segfaulting when an invalid option is passed
2022-04-13 10:25:20 +02:00
Théophane Hufschmitt
beac0b49e4
Correctly handle multiple traps in the tests
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
1cd308194f
Remove the -all_load flag on darwin
...
Seems to be useless (🤞 ), and breaks `-lc++fs`
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
e58c47cc1a
Fix the std::filesystem linking on darwin
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
48b8de73f0
Typo
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
83365a79bc
Also build the findroots library for darwin
...
Might fail at link time, but not building it will fail anyways, so…
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
d4bbb1dec7
Escape the file paths before sending them
...
Make sure that a file-path containing a `\t` or a `\n` doesn’t mess with
everything
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
cd7e22e4e0
Fix the external-gc-daemon test
...
Don’t run the auxiliary tests in a new shell, as that would trigger the
`EXIT` trap, causing the daemon to die early
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
8de54ed4e1
Gate the external gc behind an xp feature flag
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
240f1614d8
Add a proper nix option for the external GC
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
f76bfbfbd6
Remove the dependency to which in the tests
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
d97b9f138c
nix-find-roots: Support systemd socket activation
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
f6a30993f0
Rename the find-roots library
...
Give it a name more in line with the rest
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
072f420260
Remove the old gc methods from LocalStore
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
2c47b08e17
Use the standalone gc lib in the default gc
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
fbec849281
Split the root finding in a separate library
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
bbde40af3e
Make it easy to build a static nix-find-roots from this source tree
...
Just `nix build .#nix-find-roots` (or `nix-build -A nix-find-roots`)
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
80bb58b186
Properly get the temp roots when using the external gc daemon
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
2575dd4f19
Add some tests for the external gc daemon
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
dadc4a42c6
Make the gc socket path configurable
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
1d5d30b12f
Make the root-tracer directly listen on a socket
...
Complicates the code quite a bit (compared to letting systemd handle
that for us), but makes things much easier to test
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
e1df6c220a
Censor the gc roots that aren’t under stateDir
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
8f622ff71b
Don’t fail when the store contains some invalid paths
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
f3b9d3fd88
Add a message if the external tracer isn’t available
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
9a3c3cb748
Make nix-collect-garbage use the trace socket
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
63159dd672
nix-find-roots: Fully disable on darwin
...
Until I can understand why it’s not working
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
4d9ca6d09e
Fallback to the old mechanism if the gc socket isn’t found
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
26c802d18c
Communicate with the gc daemon via a socket
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
aadf585ea3
Fix build on darwin
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
35c7d5d2f1
gc: Only track sensible paths from maps file
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
3839eb15d6
Also check the NixOS specific files
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
61c35a810b
gc: Use the trace helper
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
93739ce006
Dump the whole file when scaning its content
...
Dumping the fstream to a string just dumps a certain number of bits of
it, causing some references to be missed
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
5d47c37cbc
Track the runtime roots
...
Everything that’s potentially accessed by a running program (its own
path, its environment, mmapped files, etc..)
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
2e7f1d24a1
gc: Also track the original roots
...
Will be required by `--print-roots` and friends
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
c788718de1
Specialise for searching under $stateDir/{profiles,gcroots}
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
b4ab02ef13
Add an external executable to trace the gc roots back to the store
2022-04-13 10:24:53 +02:00
Théophane Hufschmitt
2253b9044c
Merge branch 'client-side-profiles'
2022-04-13 10:24:50 +02:00