diff options
author | Alan Somers <asomers@gmail.com> | 2017-10-08 11:05:01 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2017-12-07 21:07:53 -0700 |
commit | 6c939fb3aa91c56f65fc6cd5feef1c84c8456f33 (patch) | |
tree | 3bae0c9255d6e3da40b1105e2c86ad8e186ce3f4 /test | |
parent | 86ebf7b0eac4cd0d092b816060042c55ca8871c5 (diff) | |
download | nix-6c939fb3aa91c56f65fc6cd5feef1c84c8456f33.zip |
Use the real pipe2(2) on all BSD targets.
All supported non-Apple platforms now use the native syscall. Only ios
and macos lack it. Deprecate pipe2 on those platforms, because it's
impossible to guarantee atomicity with a userland implementation. It
was added in:
* DragonflyBSD 4.2
* FreeBSD 10.0
* NetBSD 6.0
* OpenBSD 5.7
Diffstat (limited to 'test')
-rw-r--r-- | test/test_unistd.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs index b29ece3e..3fe123f0 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1,5 +1,6 @@ extern crate tempdir; +use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag}; use nix::unistd::*; use nix::unistd::ForkResult::*; use nix::sys::wait::*; @@ -380,3 +381,26 @@ fn test_sysconf_unsupported() { let open_max = sysconf(SysconfVar::_XOPEN_CRYPT); assert!(open_max.expect("sysconf failed").is_none()) } + +// Test that we can create a pair of pipes. No need to verify that they pass +// data; that's the domain of the OS, not nix. +#[test] +fn test_pipe() { + let (fd0, fd1) = pipe().unwrap(); + let m0 = stat::SFlag::from_bits_truncate(stat::fstat(fd0).unwrap().st_mode); + // S_IFIFO means it's a pipe + assert_eq!(m0, SFlag::S_IFIFO); + let m1 = stat::SFlag::from_bits_truncate(stat::fstat(fd1).unwrap().st_mode); + assert_eq!(m1, SFlag::S_IFIFO); +} + +// pipe2(2) is the same as pipe(2), except it allows setting some flags. Check +// that we can set a flag. +#[test] +fn test_pipe2() { + let (fd0, fd1) = pipe2(OFlag::O_CLOEXEC).unwrap(); + let f0 = FdFlag::from_bits_truncate(fcntl(fd0, FcntlArg::F_GETFD).unwrap()); + assert!(f0.contains(FdFlag::FD_CLOEXEC)); + let f1 = FdFlag::from_bits_truncate(fcntl(fd1, FcntlArg::F_GETFD).unwrap()); + assert!(f1.contains(FdFlag::FD_CLOEXEC)); +} |