Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ crossbeam-channel = "0.5.14"
csv = "1.3.1"
ctrlc = "3.4.5"
dashmap = "6.1.0"
deno_task_shell = "0.26.0"
deno_task_shell = { git = "https://github.com/wolfv/deno_task_shell", branch = "process-signaler" }
derive_more = "2.0.1"
dialoguer = "0.11.0"
digest = "0.10"
Expand Down
46 changes: 25 additions & 21 deletions crates/pixi_cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use std::{
string::String,
};

#[cfg(unix)]
use std::io::IsTerminal;

use clap::Parser;
use deno_task_shell::KillSignal;
use dialoguer::theme::ColorfulTheme;
Expand Down Expand Up @@ -403,6 +400,7 @@ async fn execute_task(
return Ok(());
};
let cwd = task.working_directory()?;

let execute_future = deno_task_shell::execute(
script,
command_env.clone(),
Expand Down Expand Up @@ -520,33 +518,31 @@ async fn listen_ctrl_c_windows() {
while let Ok(()) = tokio::signal::ctrl_c().await {}
}

/// Listens to all incoming signals and forwards all of them, except
/// some cases.
/// Listens to all incoming signals and forwards them to the child process.
///
/// Note that we don't handle `SIGINT` correctly, if the subprocess changes
/// its PGID, then the system won't forward CTRL+C automatically.
/// However, we should do that to ensure consistent behaviour.
/// Signal forwarding follows UV's approach:
/// - SIGINT in interactive mode: Include PGID so deno_task_shell can skip
/// forwarding if the child is in the same PGID (terminal already sent it).
/// - All other signals: Always forward unconditionally.
///
/// To resolve this we should patch `deno_task_shell` to return PID
/// from which we could get PGID and do things right.
///
/// Resulting approach should mimic
/// https://github.com/astral-sh/uv/blob/9d17dfa3537312b928f94479f632891f918c4760/crates/uv/src/child.rs#L156C21-L168C77.
/// Trade-off: `kill -INT <pixi>` won't work in interactive mode when the child
/// is in the same PGID. Use CTRL+C instead, or `kill -TERM` which always forwards.
#[cfg(unix)]
async fn listen_and_forward_all_signals(kill_signal: KillSignal) {
use futures::FutureExt;
use std::io::IsTerminal;

use futures::FutureExt;
use pixi_core::signals::SIGNALS;

let is_interactive = std::io::stdin().is_terminal();
let our_pgid = unsafe { libc::getpgid(0) };

// listen and forward every signal we support
let mut futures = Vec::with_capacity(SIGNALS.len());
let is_interactive = std::io::stdin().is_terminal();
for signo in SIGNALS.iter().copied() {
if signo == libc::SIGKILL
|| signo == libc::SIGSTOP
|| (signo == libc::SIGINT && is_interactive)
{
continue; // skip, can't listen to these
// SIGKILL and SIGSTOP cannot be caught or blocked
if signo == libc::SIGKILL || signo == libc::SIGSTOP {
continue;
}

let kill_signal = kill_signal.clone();
Expand All @@ -557,7 +553,15 @@ async fn listen_and_forward_all_signals(kill_signal: KillSignal) {
};
let signal_kind = signo.into();
while let Some(()) = stream.recv().await {
kill_signal.send(signal_kind);
// Only SIGINT gets PGID-aware handling in interactive mode.
// The terminal driver sends SIGINT to the process group on Ctrl+C,
// so we skip forwarding if the child is in the same PGID.
// All other signals are forwarded unconditionally.
if is_interactive && signo == libc::SIGINT {
kill_signal.send_from_pgid(signal_kind, our_pgid);
} else {
kill_signal.send(signal_kind);
}
}
}
.boxed_local(),
Expand Down
Loading