Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/backend/libc/termios/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> {
unsafe {
let pid = ret_pid_t(c::tcgetpgrp(borrowed_fd(fd)))?;

// This doesn't appear to be documented, but on Linux, it appears
// `tcsetpgrp` can succeed and set the pid to 0 if we pass it a
// pseudo-terminal device fd. For now, translate it into `OPNOTSUPP`.
#[cfg(linux_kernel)]
// On some platforms, a pseudo-terminal without a foreground process
// group returns 0, which `Pid` cannot represent. Translate this into
// `OPNOTSUPP`, as in the linux_raw backend.
if pid == 0 {
return Err(io::Errno::OPNOTSUPP);
}
Expand Down
2 changes: 1 addition & 1 deletion src/termios/tc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn tcgetwinsize<Fd: AsFd>(fd: Fd) -> io::Result<Winsize> {
///
/// Also known as the `TIOCGPGRP` operation with `ioctl`.
///
/// On Linux, if `fd` is a pseudo-terminal, the underlying system call here can
/// If `fd` is a pseudo-terminal, the underlying system call here can
/// return a pid of 0, which rustix's `Pid` type doesn't support. So rustix
/// instead handles this case by failing with [`io::Errno::OPNOTSUPP`] if the
/// pid is 0.
Expand Down
8 changes: 4 additions & 4 deletions tests/termios/pgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ fn pgrp_pseudoterminal() {
Err(err) => panic!("{:?}", err),
};

// Linux's `tcgetpgrp` returns 0 here, which is not documented, so rustix
// translates it into `OPNOTSUPP`.
#[cfg(linux_kernel)]
// Linux's and Apple's `tcgetpgrp` return 0 here, which is not documented,
// so rustix translates it into `OPNOTSUPP`.
#[cfg(any(linux_kernel, apple))]
assert_eq!(tcgetpgrp(&pty), Err(rustix::io::Errno::OPNOTSUPP));

// FreeBSD's `tcgetpgrp` returns 100000 here, or presumably some other
// number if that number is already taken, which is documented behavior,
// but impossible to test for reliably.
#[cfg(not(linux_kernel))]
#[cfg(not(any(linux_kernel, apple)))]
assert!(matches!(tcgetpgrp(&pty), Ok(_)));

// We shouldn't be able to set the process group to [`Pid::INIT`].
Expand Down
Loading