-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
stty: verify tcsetattr applied all settings #10569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
stty: verify tcsetattr applied all settings #10569
Conversation
POSIX allows tcsetattr() to return success while only partially applying the requested settings. This change adds verification by reading back the terminal settings after tcsetattr() and comparing them with the requested configuration. If the settings don't match, stty now exits with an error message: "<device>: unable to perform all requested operations" This matches GNU stty behavior, which uses tcgetattr() after setting and compares with eq_mode() to detect partial application. Fixes uutils#10324
|
Just for doing some local tests to validate, do you have some testing commands that you used to compare the gnu behavior? Would it be possible to add an integration test for this as well? |
|
GNU testsuite comparison: |
Adds test_multiple_settings_verified to verify that when multiple terminal settings are applied at once, they are all correctly set. This tests the tcsetattr verification logic in the normal success path.
|
Thanks for the review! I've added an integration test in the latest commit. Testing Commands (GNU vs uutils comparison)The issue is that POSIX allows # GNU stty - after tcsetattr, it reads back and compares with eq_mode()
# If settings don't match, exits with: "<device>: unable to perform all requested operations"
# Test setting multiple values at once:
stty -F /dev/pts/0 intr ^A quit ^B erase ^H
stty -F /dev/pts/0 # Verify all three are setAbout the integration testI added
This tests the normal success path of the verification logic. Note: Triggering an actual partial |
|
GNU testsuite comparison: |
tcsetattr is a POSIX function for setting terminal attributes, used in the stty implementation.
The previous implementation compared ALL termios fields after tcsetattr, which would fail if any field differed - even ones the user didn't change. On some platforms (like musl with PTYs), unrelated fields may have different values after tcsetattr even though the requested changes were applied correctly. This fix: 1. Saves the original termios before applying changes 2. After tcsetattr, compares only the fields that were actually changed (where requested != original) 3. Only fails if a specifically requested change wasn't applied This properly detects partial application per POSIX while avoiding false positives from unrelated field differences.
26e9c96 to
f5ba572
Compare
|
GNU testsuite comparison: |
|
A bunch of tests are failing |
Summary
Fixes #10324
POSIX allows
tcsetattr()to return success while only partially applying the requested settings:This PR adds verification by reading back terminal settings after
tcsetattr()and comparing them with the requested configuration.Changes
termios_eq()function to compare twoTermiosstructs (flags, control characters, and baud rates)tcsetattr(), calltcgetattr()and verify settings matchTesting
All existing tests pass (
cargo test -p uu_stty).This matches GNU stty behavior, which performs
tcgetattr()after setting and useseq_mode()to detect partial application.