Skip to content

Conversation

@NiltonVolpato
Copy link

This adds EINVAL to the error codes that trigger fallback from TCGETS2/TCSETS2 to the legacy TCGETS/TCSETS ioctls.

Motivation

Some emulated and virtualized environments don't implement TCGETS2/TCSETS2 and return EINVAL rather than ENOTTY or EACCES. This includes CheerpX/WebVM (x86-to-WebAssembly virtualization in the browser).

The fallback logic already exists for ENOTTY and EACCES. This change simply adds EINVAL as another trigger.

Reproducing

use rustix::pty::*;
use rustix::termios::*;

fn main() {
    let pty = openpt(OpenptFlags::empty()).expect("openpt failed");
    println!("tcgetattr: {:?}", tcgetattr(&pty));
}

cargo build --target i686-unknown-linux-musl --release -F termios,pty

Running on https://webvm.io/ outputs:

tcgetattr: Err(Os { code: 22, kind: InvalidInput, message: "Invalid argument" })

With this change, the fallback to TCGETS succeeds.

Changes

  • tcgetattr: add Errno::INVAL to fallback match arm
  • tcsetattr: add Errno::INVAL to fallback match arm

@sunfishcode
Copy link
Member

Could this be considered a bug in CheerpX/WebVM? Either for lacking TCGETS2. or for having an unrecognize ioctl fail with EINVAL instead of ENOTTY, which is what actual Linux does for unrecognized ioctl codes?

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.

2 participants