Skip to content

env: support real-time signals and drop the nix dependency - #13006

Open
sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:env-impro
Open

sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:env-impro

Conversation

@sylvestre

@sylvestre sylvestre commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

should fix env/env-signal-handler.sh

The uucore process helpers rejected real-time signals (timeout --signal=RTMIN failed with EINVAL). This switches the signal code in uucore from nix to libc, so libc becomes a required unix dependency of uucore and nix is optional again.

Should land after #16821 (the timeout own-group signal fix that was split out of this PR).

@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/env/env-signal-handler is no longer failing!
Congrats! The gnu test tests/wc/wc is no longer failing!

Comment thread src/uucore/src/lib/features/signals.rs Outdated
Comment on lines +490 to +495
if let Some((rtmin, rtmax)) = realtime_signal_bounds() {
if (rtmin..=rtmax).contains(&(raw as usize)) {
return Some(raw);
}
}
None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A functional approach might be cleaner. And instead of casting raw as usize you can use signal as it is already usize. Something like:

Suggested change
if let Some((rtmin, rtmax)) = realtime_signal_bounds() {
if (rtmin..=rtmax).contains(&(raw as usize)) {
return Some(raw);
}
}
None
realtime_signal_bounds().and_then(|(rtmin, rtmax)| {
(rtmin..=rtmax).contains(&signal).then_some(raw)
})

Comment thread src/uucore/src/lib/features/process.rs Outdated
/// `geteuid()` returns the effective user ID of the calling process.
pub fn geteuid() -> uid_t {
nix::unistd::geteuid().as_raw()
rustix::process::geteuid().as_raw()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codspeed

codspeed Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 8.72%

1 warning, 1 note

⚠️ 124 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
❌ 3 regressed benchmarks
✅ 397 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation true_consecutive_calls 294.7 ns 350.2 ns -15.86%
❌ CPU Simulation false_consecutive_calls 294.7 ns 350.2 ns -15.86%
❌ CPU Simulation du_wide_tree[(5000, 500)] 15.3 ms 16.2 ms -5.12%
⚡ CPU Simulation echo_consecutive_calls 251.2 µs 243.1 µs +3.35%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing sylvestre:env-impro (dc7054c) with main (6bfb142)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (31a1b0e) during the generation of this report, so 6bfb142 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Copilot AI lite review requested due to automatic review settings August 28, 2026 21:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 28, 2026 21:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 28, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 28, 2026 22:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@xtqqczze

Copy link
Copy Markdown
Collaborator

Conflicts (from #11158) must be resolved.

Copilot AI review requested due to automatic review settings September 26, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open issues

Review effort: Lite

Comment on lines +682 to +683
realtime_signal_bounds()
.and_then(|(rtmin, rtmax)| (rtmin..=rtmax).contains(&signal).then_some(raw))
Comment thread src/uu/env/src/env.rs Resolved
Comment thread src/uu/env/src/env.rs Resolved
Comment on lines +134 to +135
unsafe { libc::sigaction(sig_raw, &raw const old, std::ptr::null_mut()) };
res.map_err(io::Error::from)
Comment thread src/uucore/src/lib/lib.rs
Comment on lines +193 to 209
pub fn disable_rust_signal_handlers() -> std::io::Result<()> {
// rustix leaves signal dispositions to libc (see its `not_implemented::libc_internals`),
// so this goes straight to libc.
// SAFETY: the action is fully initialized below, and SIG_DFL is a valid disposition
// for both signals.
unsafe {
sigaction(
SIGBUS,
&SigAction::new(SigDfl, SaFlags::empty(), SigSet::all()),
)
}?;
let mut action: libc::sigaction = std::mem::zeroed();
action.sa_sigaction = libc::SIG_DFL;
libc::sigfillset(&raw mut action.sa_mask);
for signal in [libc::SIGSEGV, libc::SIGBUS] {
if libc::sigaction(signal, &raw const action, std::ptr::null_mut()) == -1 {
return Err(std::io::Error::last_os_error());
}
}
}
Ok(())
}
@sylvestre

Copy link
Copy Markdown
Contributor Author

sorry but it needs to be rebased

nix's Signal cannot represent real-time signals, so uucore's process
helpers rejected them with EINVAL (timeout --signal=RTMIN could not signal
its child) and env had to special-case them around nix. Move the signal
and process handling in uucore from nix to rustix and libc, so real-time
signals can be validated, sent, ignored, reset and blocked, and drop env's
nix dependency.

Signal dispositions go through one libc sigaction helper in uucore (rustix
does not wrap sigaction), which env, the signals feature and
send_signal_group share. uucore no longer needs nix in its core, so nix is
optional again and libc is required on unix instead.

Should fix tests/env/env-signal-handler.sh (together with the timeout
process-group fix).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The refactor changes low-level signal and process handling across multiple Unix targets, requiring cross-platform ABI/runtime validation and the pending prerequisite PR #16821 before its process-group behavior can be assessed confidently.

3 open issues
2 resolved since last review

Review effort: Lite

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants