diff --git a/lix/libutil/args.cc b/lix/libutil/args.cc index f85975f41..e6f88f346 100644 --- a/lix/libutil/args.cc +++ b/lix/libutil/args.cc @@ -1,5 +1,6 @@ #include "lix/libutil/args.hh" #include "c-calls.hh" +#include "current-process.hh" #include "lix/libutil/args/root.hh" #include "lix/libutil/hash.hh" #include "lix/libutil/strings.hh" @@ -605,6 +606,7 @@ void ExternalCommand::run() { "running external command: %s", concatMapStringsSep(" ", externalArgv, shellEscape) ); + restoreProcessContext(); sys::execv(absoluteBinaryPath, externalArgv); throw SysError(errno, "failed to execute external command '%1%'", absoluteBinaryPath); diff --git a/tests/functional2/commands/test_custom_sub_commands.py b/tests/functional2/commands/test_custom_sub_commands.py index 6ac7ea3f8..349335f6f 100644 --- a/tests/functional2/commands/test_custom_sub_commands.py +++ b/tests/functional2/commands/test_custom_sub_commands.py @@ -1,6 +1,7 @@ import stat import sys import pytest +import signal from pathlib import Path from textwrap import dedent from functional2.testlib.fixtures.env import ManagedEnv @@ -127,3 +128,22 @@ def test_custom_sub_command_flag_handling(nix: Nix, tmp_path: Path): # `--` special flag # test positional arguments, but only `nix-copy-closure` implements some, and it's pesky to test here. ... + + +@pytest.mark.usefixtures("path") +def test_custom_sub_command_signals(nix: Nix, custom_sub_command_path: Path): + command = custom_sub_command_path / "lix-signals" + command.write_text( + dedent(f"""\ + #!{sys.executable} + import signal + print(signal.pthread_sigmask(signal.SIG_BLOCK, [])) + """) + ) + command.chmod(stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR) + + current_mask = signal.pthread_sigmask(signal.SIG_BLOCK, []) + nix.settings.feature("lix-custom-sub-commands") + result = nix.nix(["signals"], nix_exe="lix").run() + result.ok() + assert result.stdout_s.strip() == str(current_mask)