Skip to content

yes: catch EBADF with >&- - #16299

Open
oech3 wants to merge 1 commit into
uutils:mainfrom
oech3:read-only-stdout
Open

oech3 wants to merge 1 commit into
uutils:mainfrom
oech3:read-only-stdout

Conversation

@oech3

@oech3 oech3 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Deprecate stdout_was_closed and re-open closed stdout as read-only. Then RawWriter raises EBADF automatically.
(We need to fix read-only stdout case too someday anyway)
Closes #11090 Closes #12160

@oech3
oech3 force-pushed the read-only-stdout branch 5 times, most recently from 37f7004 to 4a47c1a Compare November 9, 2026 05:11
@oech3

oech3 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

I'll drop other std*_was_closed later. But it needs large diff.

@oech3
oech3 force-pushed the read-only-stdout branch 6 times, most recently from c9ca672 to 6e7b06f Compare November 9, 2026 08:21
@oech3

oech3 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@anastygnome We can ask std to open pipe reader when stdout was closed.

@codspeed

codspeed Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 3.75%

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

❌ 15 regressed benchmarks
✅ 398 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 sort_numeric[500000] 2.4 s 2.6 s -5%
❌ CPU Simulation sort_ascii_utf8_locale 2.7 s 2.8 s -3.96%
❌ CPU Simulation sort_reverse_utf8_locale 79.2 ms 82.4 ms -3.93%
❌ CPU Simulation sort_mixed_utf8_locale 79.4 ms 82.7 ms -3.92%
❌ CPU Simulation sort_german_c_locale 80 ms 83.3 ms -3.92%
❌ CPU Simulation sort_mixed_c_locale 80.3 ms 83.5 ms -3.89%
❌ CPU Simulation sort_ascii_c_locale 3.6 s 3.8 s -3.87%
❌ CPU Simulation sort_case_insensitive[500000] 475.2 ms 494.2 ms -3.85%
❌ CPU Simulation sort_unique_locale[500000] 995.4 ms 1,033.2 ms -3.66%
❌ CPU Simulation sort_ascii_only[500000] 701 ms 726.2 ms -3.48%
❌ CPU Simulation sort_reverse_locale[500000] 728.6 ms 754.7 ms -3.46%
❌ CPU Simulation sort_mixed_data[500000] 650.7 ms 674 ms -3.45%
❌ CPU Simulation sort_accented_data[500000] 728.7 ms 754.6 ms -3.44%
❌ CPU Simulation sort_unique_utf8_locale 82.3 ms 85.1 ms -3.22%
❌ CPU Simulation sort_spill_to_tmp_files_utf8_locale 321.5 ms 332.1 ms -3.19%

Tip

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


Comparing oech3:read-only-stdout (88587a4) with main (0df6594)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 (85dd1ff) during the generation of this report, so 0df6594 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread src/uu/yes/src/platform/portable.rs Resolved
@anastygnome

anastygnome commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

@anastygnome We can ask std to open pipe reader when stdout was closed.

Oh you mean in the responsive PR, yes, we have such code in the std-detection code, called before the stdlib init right?.
By the way, Such code needs a refactor to call pollfd, you can go from 3 syscalls to 1

Comment thread src/uucore/src/lib/features/signals.rs Resolved
@oech3
oech3 force-pushed the read-only-stdout branch 4 times, most recently from 581d8f3 to 632c22e Compare November 9, 2026 11:03
@oech3

oech3 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

By the way, pipe pair is pain to maintain. Can we fail to open / instead under some specific situation?

@oech3
oech3 force-pushed the read-only-stdout branch 7 times, most recently from 10a320b to 33ec713 Compare November 9, 2026 16:41
@oech3

oech3 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@anastygnome rust-lang/rust#47271 (comment)

We can drop std*_was_closed() in the future at least for.

@oech3

oech3 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Do we really need to handle stderr at many utils? GNU does not report write error for stderr at most cases.
stderr_was_closed is used only on dd currently, but I don't know why it is used.

@oech3

oech3 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Oh OK. I unserstood. But dd status=progress 2>&- should not catch EBADF before typing something.
This PR should help fixing it.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.52 MB (+136 KB, +0.09%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@oech3

oech3 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Rust std (main branch) started catching EBADF: rust-lang/rust#166117 .

@oech3

oech3 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@anastygnome Can we use rustix under .init_array to remove unsafe blocks if we don't use any API depending on std?

@anastygnome

anastygnome commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

I don't think so, and
I'm not sure I see a point to that, init array is by definition unsafe

@oech3

oech3 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Is this OK to merge? I want to strat gedding rid out std*_was_closed based on this.

@anastygnome

Copy link
Copy Markdown
Contributor

Lgtm

@oech3
oech3 force-pushed the read-only-stdout branch 2 times, most recently from 412c436 to f4536a7 Compare November 23, 2026 03:44
@oech3

This comment was marked as resolved.

@oech3

oech3 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

It seems dup2 fails on FreeBSD in .init_array. I'll use /dev/null on FreeBSD.
Hopefully, FreeBSD system without mounting /dev is very rare...

@oech3
oech3 force-pushed the read-only-stdout branch 5 times, most recently from c4b2676 to 88587a4 Compare November 23, 2026 22:55

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.

all: closed std{out,err} causes SIGABRT if /dev is masked yes >&- does not stop

3 participants