diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 048d8dfe863..877c928b4ba 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -103,6 +103,15 @@ impl<'a> Options<'a> { all: matches.get_flag(options::ALL), save: matches.get_flag(options::SAVE), file: match matches.get_one::(options::FILE) { + // Two notes here: + // 1. O_NONBLOCK is needed because according to GNU docs, a + // POSIX tty can block waiting for carrier-detect if the + // "clocal" flag is not set. If your TTY is not connected + // to a modem, it is probably not relevant though. + // 2. We never close the FD that we open here, but the OS + // will clean up the FD for us on exit, so it doesn't + // matter. The alternative would be to have an enum of + // BorrowedFd/OwnedFd to handle both cases. Some(f) => std::fs::OpenOptions::new() .read(true) .custom_flags(libc::O_NONBLOCK)