Support passing `SIGINT` to scripts that are running via `devbox run`
What problem are you trying to solve?
Scripts run via devbox run cannot be cancelled with SIGINT.
What solution would you like?
Handle the SIGINT signal and pass it to the script being execute by devbox run.
Alternatives you've considered
Not running scripts via devbox. That is not desirable as the scripts defined in devbox.json provide a great way to catalog functionality.
It does seem to be working some of the time. I've yet to determine why is it not working all the time. Some scripts correctly respond to SIGINT when run but they don't when run via devbox run.
This seems similar to the issues that this PR fixed in dagger: https://github.com/dagger/dagger/pull/5712
Their change is essentially doing the following to nix/run.go:
cmd := exec.CommandContext(ctx, shPath, "-c", cmdWithArgs)
cmd.Env = envPairs
cmd.Dir = projectDir
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Cancel = func() error {
return syscall.Kill(cmd.Process.Pid, syscall.SIGTERM)
}
With my limited testing, this seems to fix the issue.
Thanks for the submitting a PR with your fix. I'd still like to understand a bit more why this is happening. Could you provide a few more details?
- What's the exact script that's not responding to SIGINT?
- What shell are you using (for running devbox and the script)?
- Are you sending SIGINT by pressing ctrl-c in the shell? Or are you signaling the devbox process directly?
- Is this happening on macOS or Linux?
When I try to repro using this config:
{
"shell": {
"scripts": {
"zzz": "/bin/sleep 5"
}
}
}
and run devbox run zzz followed by ctrl-c, the sleep process exits. This is what I'd expect because the shell should be signaling the entire process group.
@gcurtis Here is some more info:
- I'm trying to identify the actual cause. It is intermittent...
- zsh
- SIGINT is sent by pressing CTRL-C in the shell that is executing via
devbox run... - MacOS
I'm seeing this too. I can reliably reproduce on devbox 0.13.5 with the simple ruby script:
sleep
Here is a screen recording:
https://github.com/user-attachments/assets/a3d6eee2-0ea6-480e-9cf1-4a91abd6e426