Skip to content

cksum, hashsum: error when stdin was closed at startup - #15267

Open
Franklin-Qi wants to merge 1 commit into
uutils:mainfrom
Franklin-Qi:fix/10153-cksum-closed-stdin
Open

Franklin-Qi wants to merge 1 commit into
uutils:mainfrom
Franklin-Qi:fix/10153-cksum-closed-stdin

Conversation

@Franklin-Qi

Copy link
Copy Markdown
Contributor

Rust remaps a closed stdin to /dev/null before main; use the startup capture so *sum rejects it with EBADF like GNU instead of hashing empty.

Closes: #10153

@oech3

oech3 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Please remove hashsum from title. We no longer have it.


/// Closed stdin must error with EBADF (GNU), not hash /dev/null as empty (#10153).
#[test]
#[cfg(unix)]

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.

Suggested change
#[cfg(unix)]
#[cfg(unix)]
#[cfg(not(wasi_runner))]

or this would fail (host of test binary is still Linux...).

.stdout_is_fixture("crc_stdin.expected");
}

/// Closed stdin must error with EBADF (GNU), not hash /dev/null as empty (#10153).

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.

Suggested change
/// Closed stdin must error with EBADF (GNU), not hash /dev/null as empty (#10153).

or remove issue hash at least for.

if filename == "-" {
// Rust reopens a closed stdin as /dev/null before main; detect the
// original closed state captured at process start (#10153 / #2873).
#[cfg(unix)]

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.

stdin_was_closed() already returns false on non-unix, is the cfg needed?

// Rust reopens a closed stdin as /dev/null before main; detect the
// original closed state captured at process start (#10153 / #2873).
#[cfg(unix)]
if crate::signals::stdin_was_closed() {

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.

what about cksum -c - with a closed stdin? it reads stdin in validate.rs

let ebadf =
|| io::Error::from_raw_os_error(rustix::io::Errno::BADF.raw_os_error());
show!(ebadf().map_err_context(|| locale_aware_shell_escape(filename)));
show!(ebadf().map_err_context(|| "standard input".into()));

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.

please use translate!() here
also, with cksum - - this will be printed twice, no?

"expected failure on closed stdin, got {:?}",
output.status
);
let stderr = String::from_utf8_lossy(&output.stderr);

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.

could you please check the exact stderr instead of two contains?

#[cfg(unix)]
if crate::signals::stdin_was_closed() {
let ebadf =
|| io::Error::from_raw_os_error(rustix::io::Errno::BADF.raw_os_error());

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.

tac just uses io::Error::from_raw_os_error(libc::EBADF), could we do the same and drop the closure?

@codspeed

codspeed Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 1 benchmark

⚠️ 119 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

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

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation factor_five_38_bit_primes 1.9 s 2.2 s -12.5%
⚡ Simulation factor_three_39_bit_primes 598.6 ms 412 ms +45.28%

Tip

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


Comparing Franklin-Qi:fix/10153-cksum-closed-stdin (f9b79bf) with main (175f6e1)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 (b8657e8) during the generation of this report, so 175f6e1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Rust remaps a closed stdin to /dev/null before main; use the startup
capture so *sum rejects it with EBADF like GNU instead of hashing empty.

Closes: uutils#10153
@Franklin-Qi
Franklin-Qi force-pushed the fix/10153-cksum-closed-stdin branch from 5b24db0 to f9b79bf Compare October 16, 2026 04:01
@sylvestre

Copy link
Copy Markdown
Contributor

hi, this one can't be merged as it is:

  • clippy or rustfmt complain
  • it needs a rebase
  • the 5 comments above are still open
    could you please have a look? otherwise, i will close it, thanks

@Franklin-Qi

Copy link
Copy Markdown
Contributor Author

hi, this one can't be merged as it is:

  • clippy or rustfmt complain
  • it needs a rebase
  • the 5 comments above are still open
    could you please have a look? otherwise, i will close it, thanks

@sylvestre Thanks for your review. I will handle it today.

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.

cksum family: *sum <&- should be error

3 participants