stty: do not write settings back for query-only arguments - #13950
Conversation
`stty size` is a query, but any invocation carrying settings arguments ended with an unconditional `tcsetattr`. POSIX requires the kernel to raise SIGTTOU on `tcsetattr` from a background process group, and its default disposition stops the process, so `stty size` run off the foreground hangs with no diagnostic and never reaps. Only call `tcsetattr` when at least one argument actually changes the terminal settings. `Print` arguments do not. Fixes uutils#13722 Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
|
Binary size comparison: |
|
Please also add a test in test_stty.rs |
Add a regression test for the SIGTTOU stop this change fixes. The test allocates a PTY, gives a helper its own session and controlling terminal, then runs `stty size` from a background process group with SIGTTOU restored to its default disposition and asserts it exits normally rather than being stopped. Verified against the fix: it passes with the patch, and reverting src/uu/stty/src/stty.rs to its pre-fix state makes it fail with "`stty size` was stopped by SIGTTOU in a background process group" (signal 22). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
GNU testsuite comparison: |
Merging this PR will degrade performance by 3.02%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | du_wide_tree[(5000, 500)] |
19.7 ms | 20.3 ms | -3.02% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing m0g3r:stty-no-tcsetattr-for-queries (93d7b2d) with main (5633f03)
Footnotes
-
50 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. ↩
Fixes #13722.
stty sizeonly reads the terminal, but every invocation carrying settings arguments finished with an unconditionaltcsetattr. From a background process group POSIX requires the kernel to raiseSIGTTOU, whose default disposition stops the process, sostty sizeoff the foreground hangs with no diagnostic and never reaps.tcsetattris now called only when at least one parsed argument actually changes the terminal settings.ArgOptions::Printdoes not, sostty sizetakes the same path it already took for printing and then stops.Test
A unit test covers the predicate directly, since reproducing
SIGTTOUneeds a controlling terminal and a background process group, which the test harness does not provide.Checked by hand against a pty that
sizestill reports dimensions, thatrows/columnsstill apply, and that-ais unaffected:cargo test -p uu_stty27 passed, thesttyintegration suite 53 passed / 33 ignored,cargo clippy -p uu_stty --all-targets -- -D warningsclean.Note this touches the same line as #13893. If that lands first the verification it adds should move inside this guard, since there is nothing to verify when the settings were never written.
Written with AI assistance. I have reviewed the diff and verified the behaviour against a pty myself.