| 24 | #[cfg(feature = "pty")] |
| 25 | #[test] |
| 26 | fn pgrp_pseudoterminal() { |
| 27 | use rustix::pty::*; |
| 28 | use rustix::termios::*; |
| 29 | |
| 30 | let pty = match openpt(OpenptFlags::NOCTTY) { |
| 31 | Ok(pty) => pty, |
| 32 | Err(rustix::io::Errno::NOSYS) => return, |
| 33 | Err(err) => panic!("{:?}", err), |
| 34 | }; |
| 35 | |
| 36 | // Linux's `tcgetpgrp` returns 0 here, which is not documented, so rustix |
| 37 | // translates it into `OPNOTSUPP`. |
| 38 | #[cfg(linux_kernel)] |
| 39 | assert_eq!(tcgetpgrp(&pty), Err(rustix::io::Errno::OPNOTSUPP)); |
| 40 | |
| 41 | // FreeBSD's `tcgetpgrp` returns 100000 here, or presumably some other |
| 42 | // number if that number is already taken, which is documented behavior, |
| 43 | // but impossible to test for reliably. |
| 44 | #[cfg(not(linux_kernel))] |
| 45 | assert!(matches!(tcgetpgrp(&pty), Ok(_))); |
| 46 | |
| 47 | // We shouldn't be able to set the process group to [`Pid::INIT`]. |
| 48 | match tcsetpgrp(&pty, rustix::termios::Pid::INIT).unwrap_err() { |
| 49 | #[cfg(freebsdlike)] |
| 50 | rustix::io::Errno::PERM => {} |
| 51 | #[cfg(any(apple, linux_kernel))] |
| 52 | rustix::io::Errno::NOTTY => {} |
| 53 | err => panic!("{:?}", err), |
| 54 | } |
| 55 | } |