libutil: restore process context before subcommand exec

fixes #1028

Change-Id: Ic50b9cc0c65607cd96dd81fd770cda34b4caf9d5
This commit is contained in:
eldritch horrors
2025-11-05 13:56:09 +00:00
parent 0d24aee673
commit 24054c1107
2 changed files with 22 additions and 0 deletions
+2
View File
@@ -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);
@@ -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)