Merge "Allow enabling core dumps from builds for nix & child processes" into main
This commit is contained in:
commit
005ee33a9a
8 changed files with 69 additions and 1 deletions
|
@ -61,3 +61,8 @@ edolstra:
|
||||||
roberth:
|
roberth:
|
||||||
display_name: Robert Hensing
|
display_name: Robert Hensing
|
||||||
github: roberth
|
github: roberth
|
||||||
|
|
||||||
|
midnightveil:
|
||||||
|
display_name: julia
|
||||||
|
forgejo: midnightveil
|
||||||
|
github: midnightveil
|
||||||
|
|
13
doc/manual/rl-next/enable-coredumps.md
Normal file
13
doc/manual/rl-next/enable-coredumps.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
synopsis: "Add an option `enable-core-dumps` that enables core dumps from builds"
|
||||||
|
cls: 1088
|
||||||
|
credits: midnightveil
|
||||||
|
category: Features
|
||||||
|
---
|
||||||
|
|
||||||
|
In the past, Lix disabled core dumps by setting the soft `RLIMIT_CORE` to 0
|
||||||
|
unconditionally. Although this rlimit could be altered from the builder since
|
||||||
|
it is just the soft limit, this was kind of annoying to do. By passing
|
||||||
|
`--option enable-core-dumps true` to an offending build, one can now cause the
|
||||||
|
core dumps to be handled by the system in the normal way (winding up in
|
||||||
|
`coredumpctl`, say, on Linux).
|
|
@ -1977,6 +1977,9 @@ void LocalDerivationGoal::runChild()
|
||||||
|
|
||||||
/* Disable core dumps by default. */
|
/* Disable core dumps by default. */
|
||||||
struct rlimit limit = { 0, RLIM_INFINITY };
|
struct rlimit limit = { 0, RLIM_INFINITY };
|
||||||
|
if (settings.enableCoreDumps) {
|
||||||
|
limit.rlim_cur = RLIM_INFINITY;
|
||||||
|
}
|
||||||
setrlimit(RLIMIT_CORE, &limit);
|
setrlimit(RLIMIT_CORE, &limit);
|
||||||
|
|
||||||
// FIXME: set other limits to deterministic values?
|
// FIXME: set other limits to deterministic values?
|
||||||
|
|
|
@ -290,6 +290,15 @@ public:
|
||||||
Setting<off_t> reservedSize{this, 8 * 1024 * 1024, "gc-reserved-space",
|
Setting<off_t> reservedSize{this, 8 * 1024 * 1024, "gc-reserved-space",
|
||||||
"Amount of reserved disk space for the garbage collector."};
|
"Amount of reserved disk space for the garbage collector."};
|
||||||
|
|
||||||
|
Setting<bool> enableCoreDumps{
|
||||||
|
this, false, "enable-core-dumps",
|
||||||
|
R"(
|
||||||
|
If set to `false` (the default), `RLIMIT_CORE` has a soft limit of zero.
|
||||||
|
If set to `true`, the soft limit is infinite.
|
||||||
|
|
||||||
|
The hard limit is always infinite.
|
||||||
|
)"};
|
||||||
|
|
||||||
Setting<bool> fsyncMetadata{
|
Setting<bool> fsyncMetadata{
|
||||||
this, true, "fsync-metadata",
|
this, true, "fsync-metadata",
|
||||||
R"(
|
R"(
|
||||||
|
|
15
tests/nixos/coredumps/default.nix
Normal file
15
tests/nixos/coredumps/default.nix
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
let
|
||||||
|
inherit (import ../util.nix) mkNixBuildTest;
|
||||||
|
in mkNixBuildTest rec {
|
||||||
|
name = "coredumps";
|
||||||
|
extraMachineConfig = { pkgs, ... }: {
|
||||||
|
boot.kernel.sysctl."kernel.core_pattern" = "core";
|
||||||
|
};
|
||||||
|
|
||||||
|
expressionFile = ./package.nix;
|
||||||
|
|
||||||
|
testScriptPost = ''
|
||||||
|
# do a test, but this time with coredumps enabled.
|
||||||
|
machine.succeed('nix-build --option enable-core-dumps true --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} { shouldBePresent = true; }"')
|
||||||
|
'';
|
||||||
|
}
|
16
tests/nixos/coredumps/package.nix
Normal file
16
tests/nixos/coredumps/package.nix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{ lib, runCommand, shouldBePresent ? false }:
|
||||||
|
|
||||||
|
runCommand "core-dump-now" { } ''
|
||||||
|
set -m
|
||||||
|
sleep infinity &
|
||||||
|
|
||||||
|
# make a coredump
|
||||||
|
kill -SIGSEGV %1
|
||||||
|
|
||||||
|
if ${lib.optionalString (shouldBePresent) "!"} test -n "$(find . -maxdepth 1 -name 'core*' -print -quit)"; then
|
||||||
|
echo "core file was in wrong presence state, expected: ${if shouldBePresent then "present" else "missing"}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch $out
|
||||||
|
''
|
|
@ -166,4 +166,6 @@ in
|
||||||
rootInSandbox = runNixOSTestFor "x86_64-linux" ./root-in-sandbox;
|
rootInSandbox = runNixOSTestFor "x86_64-linux" ./root-in-sandbox;
|
||||||
|
|
||||||
broken-userns = runNixOSTestFor "x86_64-linux" ./broken-userns.nix;
|
broken-userns = runNixOSTestFor "x86_64-linux" ./broken-userns.nix;
|
||||||
|
|
||||||
|
coredumps = runNixOSTestFor "x86_64-linux" ./coredumps;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
mkNixBuildTest = { name, expressionFile, extraMachineConfig ? {} }:
|
mkNixBuildTest =
|
||||||
|
{ name, expressionFile, extraMachineConfig ? {}, testScriptPre ? "", testScriptPost ? "" }:
|
||||||
{ lib, pkgs, ... }:
|
{ lib, pkgs, ... }:
|
||||||
{
|
{
|
||||||
inherit name;
|
inherit name;
|
||||||
|
@ -17,7 +18,11 @@
|
||||||
testScript = { nodes }: ''
|
testScript = { nodes }: ''
|
||||||
start_all()
|
start_all()
|
||||||
|
|
||||||
|
${testScriptPre}
|
||||||
|
|
||||||
machine.succeed('nix-build --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} {}"')
|
machine.succeed('nix-build --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} {}"')
|
||||||
|
|
||||||
|
${testScriptPost}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue