Skip to content

stty: support any baud on Linux, replace nix with rustix - #15299

Open
oech3 wants to merge 1 commit into
uutils:mainfrom
oech3:stty-unsafe
Open

oech3 wants to merge 1 commit into
uutils:mainfrom
oech3:stty-unsafe

Conversation

@oech3

@oech3 oech3 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 28.83%

2 warnings, 1 note

⚠️ 128 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 with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

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 regressed benchmark
✅ 414 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory timeout_enforced 88.8 KB 124.7 KB -28.83%

Tip

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


Comparing oech3:stty-unsafe (02e78c0) with main (73e526f)

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. ↩

Comment thread src/uu/stty/Cargo.toml Resolved
Comment thread src/uu/stty/src/stty.rs Resolved
Comment thread src/uu/stty/src/stty.rs Resolved
Comment thread src/uu/stty/src/stty.rs Resolved
@oech3
oech3 marked this pull request as draft October 13, 2026 16:36
Comment thread src/uu/stty/src/stty.rs Resolved
@oech3
oech3 force-pushed the stty-unsafe branch 5 times, most recently from 8c0b529 to 39bc936 Compare October 13, 2026 17:09
@oech3 oech3 changed the title stty: remove unsafe & cfg stty: replace nix with rustix Oct 13, 2026
@oech3 oech3 changed the title stty: replace nix with rustix stty: support any baud on Linux, replace nix with rustix Oct 13, 2026
@oech3
oech3 force-pushed the stty-unsafe branch 2 times, most recently from ff11e70 to f100d7d Compare October 13, 2026 17:47
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

@oech3
oech3 force-pushed the stty-unsafe branch 2 times, most recently from 9be3124 to d420658 Compare October 13, 2026 18:30
@oech3

This comment was marked as outdated.

@xtqqczze

Copy link
Copy Markdown
Collaborator

Would it be possible to separate the refactor replacing nix with rustix from the fix for #8719 into separate PRs?

@oech3

oech3 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

It is very difficult since rustix automatically supports any baud and nix and rustix cannot be mixed.

@oech3

This comment was marked as resolved.

@oech3

This comment was marked as outdated.

@oech3 oech3 mentioned this pull request Oct 21, 2026
@xtqqczze

Copy link
Copy Markdown
Collaborator

There will be follow-up work in any case for OUTPUT_FLAGS target cfg's, so fine for now.

@oech3

This comment was marked as duplicate.

@oech3

This comment was marked as resolved.

@xtqqczze

This comment was marked as resolved.

@oech3

This comment was marked as resolved.

@xtqqczze

This comment was marked as resolved.

@oech3

This comment was marked as duplicate.

@oech3

This comment was marked as resolved.

Comment thread src/uu/stty/src/stty.rs Resolved
Comment thread util/build-gnu.sh Resolved
@oech3

oech3 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@sylvestre Would you review (& merge) this? There is not part which can be separated to different PR.

@oech3

oech3 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

bad-speed hangs. But I think it is CI itself's issue which was masked by bypassing ioctl using injection previously.
Patch is correct.

@oech3

oech3 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

I worked around about hang. But it can be fixed at GNU side.

@oech3

This comment was marked as outdated.

@oech3

oech3 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

#16218 was unrelated and script workaround cannot be dropped. This PR is ready.

@oech3

oech3 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

It seems this was sometimes rebased by @sylvestre . Is this OK to merge?

@oech3

oech3 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Last nix dep is here: #15978

@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.49 MB (+104 KB, +0.07%)

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

1 similar comment
@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.49 MB (+104 KB, +0.07%)

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

@oech3

oech3 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Is this OK to merge?

@xtqqczze

This comment was marked as resolved.

@oech3

oech3 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

This PR is ready.

Comment thread src/uu/stty/src/flags.rs Resolved
Comment thread src/uu/stty/src/flags.rs
S::VERASE,
S::VWERASE,
S::VKILL,
S::VREPRINT,

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.

on BSD, c_cc slot 7 is a spare (VERASE2 on freebsd), so everything after VREPRINT is shifted by one in stty -g, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. But it is impossible to add unexposed const... I worked around at loop side instead.

This comment was marked as outdated.

@oech3 oech3 Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I placed a default value. By the way, termios header for apple says that using spare flags is UB. Thus, we should not use it anyway.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Slot 7 does not exist in the Apple headers:

~ $ cat $(xcrun --show-sdk-path)/usr/include/sys/termios.h | grep -B1 -A3 VREPRINT
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
#define VREPRINT        6       /* ICANON together with IEXTEN */
#endif
/*			7	   spare 1 */
#define VINTR           8       /* ISIG */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are talking about /* 7 spare 1 */ which exists on termios struct.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you can remove the comment, since it is not just that rustix doesn't expose it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By the way, @sylvestre 's draft PR has the code:

    // Print all special codes in save format by accessing the raw cc array
    // via a pointer cast, since rustix doesn't expose the inner array.
    let cc_ptr = (&raw const termios.special_codes).cast::<[libc::cc_t; libc::NCCS]>();
    // SAFETY: SpecialCodes is a transparent wrapper around [cc_t; NCCS]
    let cc_array = unsafe { &*cc_ptr };
    for cc in cc_array {
        print!(":{cc:x}");
    }
    println!();

Since we only need 1 unexposed flag, we can use it with debug_assert!(exposed, unexposed).
I don't think it is worth to do have that unsafe just for undefined flag which is essentially UB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I want to leave some comments since it is easy to miskake.

Comment thread src/uu/stty/src/stty.rs Resolved
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
@xtqqczze

xtqqczze commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Fuzzing / Fuzz (fuzz_echo) (pull_request) failure tracked by #17048.

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.

stty: support B460800 and B921600 baud rates stty: support arbitrary baudrate (at least on linux) as GNU coreutils 9.8

3 participants