Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use `weakcall` for `eventfd` on FreeBSD. `eventfd` was introduced in FreeBSD 13, so it isn't in FreeBSD 12. Use `weakcall` to call it on FreeBSD so that we don't have a link-time dependency on it. Fixes #716. * Re-introduce FreeBSD 12 in the Cirrus CI config. FreeBSD 12 was origally removed in #517 due to problems with `curl`, however those were fixed by removing the `pkg install -y curl` in #643, so we can now re-enable FreeBSD 12 testing. * Use `weakcall!` for `ptsname_r` on FreeBSD too. FreeBSD 12 lacks `ptsname_r`. * Relax a test to accept `NOSYS` from `eventfd` on FreeBSD. * Relax some `procctl` tests on FreeBSD too. * Fix the `openpty` tests for FreeBSD 12.
- Loading branch information
1 parent
e4a3a43
commit ced01a5
Showing
6 changed files
with
85 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,76 @@ | ||
use rustix::fs::{cwd, openat, Mode, OFlags}; | ||
use rustix::pty::*; | ||
use std::fs::File; | ||
use std::io; | ||
use std::io::{Read, Write}; | ||
|
||
#[test] | ||
fn openpty_basic() -> io::Result<()> { | ||
fn openpty_basic() { | ||
// Use `CLOEXEC` if we can. | ||
#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "netbsd"))] | ||
let flags = OpenptFlags::RDWR | OpenptFlags::NOCTTY | OpenptFlags::CLOEXEC; | ||
#[cfg(not(any(linux_kernel, target_os = "freebsd", target_os = "netbsd")))] | ||
let flags = OpenptFlags::RDWR | OpenptFlags::NOCTTY; | ||
|
||
let controller = openpt(flags)?; | ||
let controller = openpt(flags).unwrap(); | ||
|
||
grantpt(&controller)?; | ||
unlockpt(&controller)?; | ||
grantpt(&controller).unwrap(); | ||
unlockpt(&controller).unwrap(); | ||
|
||
let name = ptsname(&controller, Vec::new())?; | ||
let name = match ptsname(&controller, Vec::new()) { | ||
Ok(name) => name, | ||
#[cfg(target_os = "freebsd")] | ||
Err(rustix::io::Errno::NOSYS) => return, // FreeBSD 12 doesn't support this | ||
Err(err) => Err(err).unwrap(), | ||
}; | ||
let user = openat( | ||
cwd(), | ||
name, | ||
OFlags::RDWR | OFlags::NOCTTY | OFlags::CLOEXEC, | ||
Mode::empty(), | ||
)?; | ||
) | ||
.unwrap(); | ||
|
||
let mut controller = File::from(controller); | ||
let mut user = File::from(user); | ||
|
||
// The '\x04' is Ctrl-D, the default EOF control code. | ||
controller.write_all(b"Hello, world!\n\x04")?; | ||
controller.write_all(b"Hello, world!\n\x04").unwrap(); | ||
|
||
let mut s = String::new(); | ||
user.read_to_string(&mut s)?; | ||
user.read_to_string(&mut s).unwrap(); | ||
|
||
assert_eq!(s, "Hello, world!\n"); | ||
Ok(()) | ||
} | ||
|
||
// Like `openpty_basic` but use `ioctl_tiocgptpeer` instead of `ptsname`. | ||
#[cfg(target_os = "linux")] | ||
#[test] | ||
fn openpty_get_peer() -> io::Result<()> { | ||
fn openpty_get_peer() { | ||
// Use `CLOEXEC` if we can. | ||
#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "netbsd"))] | ||
let flags = OpenptFlags::RDWR | OpenptFlags::NOCTTY | OpenptFlags::CLOEXEC; | ||
#[cfg(not(any(linux_kernel, target_os = "freebsd", target_os = "netbsd")))] | ||
let flags = OpenptFlags::RDWR | OpenptFlags::NOCTTY; | ||
|
||
let controller = openpt(flags)?; | ||
let controller = openpt(flags).unwrap(); | ||
|
||
grantpt(&controller)?; | ||
unlockpt(&controller)?; | ||
grantpt(&controller).unwrap(); | ||
unlockpt(&controller).unwrap(); | ||
|
||
let user = ioctl_tiocgptpeer( | ||
&controller, | ||
OpenptFlags::RDWR | OpenptFlags::NOCTTY | OpenptFlags::CLOEXEC, | ||
)?; | ||
) | ||
.unwrap(); | ||
|
||
let mut controller = File::from(controller); | ||
let mut user = File::from(user); | ||
|
||
// The '\x04' is Ctrl-D, the default EOF control code. | ||
controller.write_all(b"Hello, world!\n\x04")?; | ||
controller.write_all(b"Hello, world!\n\x04").unwrap(); | ||
|
||
let mut s = String::new(); | ||
user.read_to_string(&mut s)?; | ||
user.read_to_string(&mut s).unwrap(); | ||
|
||
assert_eq!(s, "Hello, world!\n"); | ||
Ok(()) | ||
} |