summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml3
-rw-r--r--src/env.rs5
-rw-r--r--src/sys/memfd.rs28
-rw-r--r--src/sys/mman.rs61
-rw-r--r--src/sys/mod.rs1
-rw-r--r--src/sys/signal.rs4
-rw-r--r--src/unistd.rs8
-rw-r--r--test/sys/test_aio.rs4
-rw-r--r--test/sys/test_ptrace.rs6
-rw-r--r--test/sys/test_select.rs4
-rw-r--r--test/sys/test_signal.rs8
-rw-r--r--test/sys/test_signalfd.rs2
-rw-r--r--test/sys/test_termios.rs6
-rw-r--r--test/sys/test_uio.rs2
-rw-r--r--test/sys/test_wait.rs8
-rw-r--r--test/test.rs5
-rw-r--r--test/test_kmod/mod.rs32
-rw-r--r--test/test_pty.rs18
-rw-r--r--test/test_unistd.rs30
19 files changed, 141 insertions, 94 deletions
diff --git a/Cargo.toml b/Cargo.toml
index c2688304..f5c7a565 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,7 +7,7 @@ authors = ["The nix-rust Project Developers"]
repository = "https://github.com/nix-rust/nix"
license = "MIT"
categories = ["os::unix-apis"]
-include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md"]
+include = ["src/**/*", "test/**/*", "LICENSE", "README.md", "CHANGELOG.md"]
[package.metadata.docs.rs]
targets = [
@@ -38,6 +38,7 @@ cc = "1"
[dev-dependencies]
assert-impl = "0.1"
lazy_static = "1.2"
+parking_lot = "0.11.2"
rand = "0.8"
tempfile = "3.2.0"
semver = "1.0.0"
diff --git a/src/env.rs b/src/env.rs
index 54d75959..bcae2871 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -39,7 +39,6 @@ impl std::error::Error for ClearEnvError {}
/// environment access in the program is via `std::env`, but the requirement on
/// thread safety must still be upheld.
pub unsafe fn clearenv() -> std::result::Result<(), ClearEnvError> {
- let ret;
cfg_if! {
if #[cfg(any(target_os = "fuchsia",
target_os = "wasi",
@@ -48,13 +47,13 @@ pub unsafe fn clearenv() -> std::result::Result<(), ClearEnvError> {
target_os = "linux",
target_os = "android",
target_os = "emscripten"))] {
- ret = libc::clearenv();
+ let ret = libc::clearenv();
} else {
use std::env;
for (name, _) in env::vars_os() {
env::remove_var(name);
}
- ret = 0;
+ let ret = 0;
}
}
diff --git a/src/sys/memfd.rs b/src/sys/memfd.rs
index 0236eef6..642676b4 100644
--- a/src/sys/memfd.rs
+++ b/src/sys/memfd.rs
@@ -1,15 +1,43 @@
+//! Interfaces for managing memory-backed files.
+
use std::os::unix::io::RawFd;
use crate::Result;
use crate::errno::Errno;
use std::ffi::CStr;
libc_bitflags!(
+ /// Options that change the behavior of [`memfd_create`].
pub struct MemFdCreateFlag: libc::c_uint {
+ /// Set the close-on-exec ([`FD_CLOEXEC`]) flag on the new file descriptor.
+ ///
+ /// By default, the new file descriptor is set to remain open across an [`execve`]
+ /// (the `FD_CLOEXEC` flag is initially disabled). This flag can be used to change
+ /// this default. The file offset is set to the beginning of the file (see [`lseek`]).
+ ///
+ /// See also the description of the `O_CLOEXEC` flag in [`open(2)`].
+ ///
+ /// [`execve`]: crate::unistd::execve
+ /// [`lseek`]: crate::unistd::lseek
+ /// [`FD_CLOEXEC`]: crate::fcntl::FdFlag::FD_CLOEXEC
+ /// [`open(2)`]: https://man7.org/linux/man-pages/man2/open.2.html
MFD_CLOEXEC;
+ /// Allow sealing operations on this file.
+ ///
+ /// See also the file sealing notes given in [`memfd_create(2)`].
+ ///
+ /// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
MFD_ALLOW_SEALING;
}
);
+/// Creates an anonymous file that lives in memory, and return a file-descriptor to it.
+///
+/// The file behaves like a regular file, and so can be modified, truncated, memory-mapped, and so on.
+/// However, unlike a regular file, it lives in RAM and has a volatile backing storage.
+///
+/// For more information, see [`memfd_create(2)`].
+///
+/// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<RawFd> {
let res = unsafe {
libc::syscall(libc::SYS_memfd_create, name.as_ptr(), flags.bits())
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 882a2b94..0ef1ca8a 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -1,3 +1,5 @@
+//! Memory management declarations.
+
use crate::Result;
#[cfg(not(target_os = "android"))]
use crate::NixPath;
@@ -30,7 +32,7 @@ libc_bitflags!{
}
libc_bitflags!{
- /// Additional parameters for `mmap()`.
+ /// Additional parameters for [`mmap`].
pub struct MapFlags: c_int {
/// Compatibility flag. Ignored.
MAP_FILE;
@@ -141,7 +143,7 @@ libc_bitflags!{
#[cfg(any(target_os = "ios", target_os = "macos"))]
MAP_JIT;
/// Allows to use large pages, underlying alignment based on size.
- #[cfg(target_os = "freesd")]
+ #[cfg(target_os = "freebsd")]
MAP_ALIGNED_SUPER;
/// Pages will be discarded in the core dumps.
#[cfg(target_os = "openbsd")]
@@ -151,7 +153,7 @@ libc_bitflags!{
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
libc_bitflags!{
- /// Options for `mremap()`.
+ /// Options for [`mremap`].
pub struct MRemapFlags: c_int {
/// Permit the kernel to relocate the mapping to a new virtual address, if necessary.
#[cfg(target_os = "linux")]
@@ -171,7 +173,7 @@ libc_bitflags!{
libc_enum!{
/// Usage information for a range of memory to allow for performance optimizations by the kernel.
///
- /// Used by [`madvise`](./fn.madvise.html).
+ /// Used by [`madvise`].
#[repr(i32)]
#[non_exhaustive]
pub enum MmapAdvise {
@@ -264,7 +266,7 @@ libc_enum!{
}
libc_bitflags!{
- /// Configuration flags for `msync`.
+ /// Configuration flags for [`msync`].
pub struct MsFlags: c_int {
/// Schedule an update but return immediately.
MS_ASYNC;
@@ -282,7 +284,7 @@ libc_bitflags!{
}
libc_bitflags!{
- /// Flags for `mlockall`.
+ /// Flags for [`mlockall`].
pub struct MlockAllFlags: c_int {
/// Lock pages that are currently mapped into the address space of the process.
MCL_CURRENT;
@@ -298,7 +300,9 @@ libc_bitflags!{
///
/// # Safety
///
-/// `addr` must meet all the requirements described in the `mlock(2)` man page.
+/// `addr` must meet all the requirements described in the [`mlock(2)`] man page.
+///
+/// [`mlock(2)`]: https://man7.org/linux/man-pages/man2/mlock.2.html
pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> {
Errno::result(libc::mlock(addr, length)).map(drop)
}
@@ -308,25 +312,28 @@ pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> {
///
/// # Safety
///
-/// `addr` must meet all the requirements described in the `munlock(2)` man
+/// `addr` must meet all the requirements described in the [`munlock(2)`] man
/// page.
+///
+/// [`munlock(2)`]: https://man7.org/linux/man-pages/man2/munlock.2.html
pub unsafe fn munlock(addr: *const c_void, length: size_t) -> Result<()> {
Errno::result(libc::munlock(addr, length)).map(drop)
}
/// Locks all memory pages mapped into this process' address space.
///
-/// Locked pages never move to the swap area.
+/// Locked pages never move to the swap area. For more information, see [`mlockall(2)`].
///
-/// # Safety
-///
-/// `addr` must meet all the requirements described in the `mlockall(2)` man
-/// page.
+/// [`mlockall(2)`]: https://man7.org/linux/man-pages/man2/mlockall.2.html
pub fn mlockall(flags: MlockAllFlags) -> Result<()> {
unsafe { Errno::result(libc::mlockall(flags.bits())) }.map(drop)
}
/// Unlocks all memory pages mapped into this process' address space.
+///
+/// For more information, see [`munlockall(2)`].
+///
+/// [`munlockall(2)`]: https://man7.org/linux/man-pages/man2/munlockall.2.html
pub fn munlockall() -> Result<()> {
unsafe { Errno::result(libc::munlockall()) }.map(drop)
}
@@ -335,7 +342,9 @@ pub fn munlockall() -> Result<()> {
///
/// # Safety
///
-/// See the `mmap(2)` man page for detailed requirements.
+/// See the [`mmap(2)`] man page for detailed requirements.
+///
+/// [`mmap(2)`]: https://man7.org/linux/man-pages/man2/mmap.2.html
pub unsafe fn mmap(addr: *mut c_void, length: size_t, prot: ProtFlags, flags: MapFlags, fd: RawFd, offset: off_t) -> Result<*mut c_void> {
let ret = libc::mmap(addr, length, prot.bits(), flags.bits(), fd, offset);
@@ -383,8 +392,10 @@ pub unsafe fn mremap(
///
/// # Safety
///
-/// `addr` must meet all the requirements described in the `munmap(2)` man
+/// `addr` must meet all the requirements described in the [`munmap(2)`] man
/// page.
+///
+/// [`munmap(2)`]: https://man7.org/linux/man-pages/man2/munmap.2.html
pub unsafe fn munmap(addr: *mut c_void, len: size_t) -> Result<()> {
Errno::result(libc::munmap(addr, len)).map(drop)
}
@@ -393,8 +404,10 @@ pub unsafe fn munmap(addr: *mut c_void, len: size_t) -> Result<()> {
///
/// # Safety
///
-/// See the `madvise(2)` man page. Take special care when using
-/// `MmapAdvise::MADV_FREE`.
+/// See the [`madvise(2)`] man page. Take special care when using
+/// [`MmapAdvise::MADV_FREE`].
+///
+/// [`madvise(2)`]: https://man7.org/linux/man-pages/man2/madvise.2.html
pub unsafe fn madvise(addr: *mut c_void, length: size_t, advise: MmapAdvise) -> Result<()> {
Errno::result(libc::madvise(addr, length, advise as i32)).map(drop)
}
@@ -432,12 +445,19 @@ pub unsafe fn mprotect(addr: *mut c_void, length: size_t, prot: ProtFlags) -> Re
///
/// # Safety
///
-/// `addr` must meet all the requirements described in the `msync(2)` man
+/// `addr` must meet all the requirements described in the [`msync(2)`] man
/// page.
+///
+/// [`msync(2)`]: https://man7.org/linux/man-pages/man2/msync.2.html
pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result<()> {
Errno::result(libc::msync(addr, length, flags.bits())).map(drop)
}
+/// Creates and opens a new, or opens an existing, POSIX shared memory object.
+///
+/// For more information, see [`shm_open(3)`].
+///
+/// [`shm_open(3)`]: https://man7.org/linux/man-pages/man3/shm_open.3.html
#[cfg(not(target_os = "android"))]
pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<RawFd> {
let ret = name.with_nix_path(|cstr| {
@@ -454,6 +474,11 @@ pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Resul
Errno::result(ret)
}
+/// Performs the converse of [`shm_open`], removing an object previously created.
+///
+/// For more information, see [`shm_unlink(3)`].
+///
+/// [`shm_unlink(3)`]: https://man7.org/linux/man-pages/man3/shm_unlink.3.html
#[cfg(not(target_os = "android"))]
pub fn shm_unlink<P: ?Sized + NixPath>(name: &P) -> Result<()> {
let ret = name.with_nix_path(|cstr| {
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index a87de55b..156b0d9d 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -38,7 +38,6 @@ pub mod eventfd;
pub mod ioctl;
#[cfg(target_os = "linux")]
-#[allow(missing_docs)]
pub mod memfd;
#[cfg(not(target_os = "redox"))]
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index e8c79d33..61bdc74a 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -868,8 +868,8 @@ pub fn sigprocmask(how: SigmaskHow, set: Option<&SigSet>, oldset: Option<&mut Si
/// is sent to all processes exclusing system processes.
/// - If less than `-1`, the signal is sent to all processes whose
/// process group ID is equal to the absolute value of `pid`.
-/// * `signal` - Signal to send. If 0, error checking if performed but no
-/// signal is actually sent.
+/// * `signal` - Signal to send. If `None`, error checking is performed
+/// but no signal is actually sent.
///
/// See Also
/// [`kill(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html)
diff --git a/src/unistd.rs b/src/unistd.rs
index a9862d37..2c89d772 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1075,10 +1075,10 @@ pub fn pipe() -> std::result::Result<(RawFd, RawFd), Error> {
/// The following flags are supported, and will be set atomically as the pipe is
/// created:
///
-/// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
-#[cfg_attr(target_os = "linux", doc = "`O_DIRECT`: Create a pipe that performs I/O in \"packet\" mode. ")]
-#[cfg_attr(target_os = "netbsd", doc = "`O_NOSIGPIPE`: Return `EPIPE` instead of raising `SIGPIPE`. ")]
-/// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
+/// - `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
+#[cfg_attr(target_os = "linux", doc = "- `O_DIRECT`: Create a pipe that performs I/O in \"packet\" mode.")]
+#[cfg_attr(target_os = "netbsd", doc = "- `O_NOSIGPIPE`: Return `EPIPE` instead of raising `SIGPIPE`.")]
+/// - `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
///
/// See also [pipe(2)](https://man7.org/linux/man-pages/man2/pipe.2.html)
#[cfg(any(target_os = "android",
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs
index b4eb3129..80cd053f 100644
--- a/test/sys/test_aio.rs
+++ b/test/sys/test_aio.rs
@@ -406,7 +406,7 @@ extern fn sigfunc(_: c_int) {
#[test]
#[cfg_attr(any(all(target_env = "musl", target_arch = "x86_64"), target_arch = "mips", target_arch = "mips64"), ignore)]
fn test_write_sigev_signal() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
let sa = SigAction::new(SigHandler::Handler(sigfunc),
SaFlags::SA_RESETHAND,
SigSet::empty());
@@ -544,7 +544,7 @@ fn test_liocb_listio_nowait() {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
#[cfg_attr(any(target_arch = "mips", target_arch = "mips64", target_env = "musl"), ignore)]
fn test_liocb_listio_signal() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
const INITIAL: &[u8] = b"abcdef123456";
const WBUF: &[u8] = b"CDEF";
let mut rbuf = vec![0; 4];
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index 1c72e7c2..83fff9a5 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -69,7 +69,7 @@ fn test_ptrace_cont() {
require_capability!("test_ptrace_cont", CAP_SYS_PTRACE);
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
// FIXME: qemu-user doesn't implement ptrace on all architectures
// and retunrs ENOSYS in this case.
@@ -127,7 +127,7 @@ fn test_ptrace_interrupt() {
require_capability!("test_ptrace_interrupt", CAP_SYS_PTRACE);
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
match unsafe{fork()}.expect("Error: Fork Failed") {
Child => {
@@ -173,7 +173,7 @@ fn test_ptrace_syscall() {
require_capability!("test_ptrace_syscall", CAP_SYS_PTRACE);
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
match unsafe{fork()}.expect("Error: Fork Failed") {
Child => {
diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs
index db079456..2f7396b1 100644
--- a/test/sys/test_select.rs
+++ b/test/sys/test_select.rs
@@ -5,9 +5,7 @@ use nix::sys::time::{TimeSpec, TimeValLike};
#[test]
pub fn test_pselect() {
- let _mtx = crate::SIGNAL_MTX
- .lock()
- .expect("Mutex got poisoned by another test");
+ let _mtx = crate::SIGNAL_MTX.lock();
let (r1, w1) = pipe().unwrap();
write(w1, b"hi!").unwrap();
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
index 1b89af57..fdd2568d 100644
--- a/test/sys/test_signal.rs
+++ b/test/sys/test_signal.rs
@@ -19,7 +19,7 @@ fn test_killpg_none() {
#[test]
fn test_old_sigaction_flags() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
extern "C" fn handler(_: ::libc::c_int) {}
let act = SigAction::new(
@@ -41,7 +41,7 @@ fn test_sigprocmask_noop() {
#[test]
fn test_sigprocmask() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
// This needs to be a signal that rust doesn't use in the test harness.
const SIGNAL: Signal = Signal::SIGCHLD;
@@ -89,7 +89,7 @@ extern fn test_sigaction_action(_: libc::c_int, _: *mut libc::siginfo_t, _: *mut
#[test]
#[cfg(not(target_os = "redox"))]
fn test_signal_sigaction() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
let action_handler = SigHandler::SigAction(test_sigaction_action);
assert_eq!(unsafe { signal(Signal::SIGINT, action_handler) }.unwrap_err(), Errno::ENOTSUP);
@@ -97,7 +97,7 @@ fn test_signal_sigaction() {
#[test]
fn test_signal() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
unsafe { signal(Signal::SIGINT, SigHandler::SigIgn) }.unwrap();
raise(Signal::SIGINT).unwrap();
diff --git a/test/sys/test_signalfd.rs b/test/sys/test_signalfd.rs
index af04c222..b6f748b4 100644
--- a/test/sys/test_signalfd.rs
+++ b/test/sys/test_signalfd.rs
@@ -6,7 +6,7 @@ fn test_signalfd() {
use nix::sys::signal::{self, raise, Signal, SigSet};
// Grab the mutex for altering signals so we don't interfere with other tests.
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
// Block the SIGUSR1 signal from automatic processing for this thread
let mut mask = SigSet::empty();
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index 63d6a51f..4a861543 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -19,7 +19,7 @@ fn write_all(f: RawFd, buf: &[u8]) {
#[test]
fn test_tcgetattr_pty() {
// openpty uses ptname(3) internally
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
let pty = openpty(None, None).expect("openpty failed");
assert!(termios::tcgetattr(pty.slave).is_ok());
@@ -46,7 +46,7 @@ fn test_tcgetattr_ebadf() {
#[test]
fn test_output_flags() {
// openpty uses ptname(3) internally
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open one pty to get attributes for the second one
let mut termios = {
@@ -88,7 +88,7 @@ fn test_output_flags() {
#[test]
fn test_local_flags() {
// openpty uses ptname(3) internally
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open one pty to get attributes for the second one
let mut termios = {
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index 8f8ba5e4..408537c8 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -214,7 +214,7 @@ fn test_process_vm_readv() {
use crate::*;
require_capability!("test_process_vm_readv", CAP_SYS_PTRACE);
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
// Pre-allocate memory in the child, since allocation isn't safe
// post-fork (~= async-signal-safe)
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 4a5b9661..afe4f42b 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -8,7 +8,7 @@ use libc::_exit;
#[test]
#[cfg(not(target_os = "redox"))]
fn test_wait_signal() {
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
// Safe: The child only calls `pause` and/or `_exit`, which are async-signal-safe.
match unsafe{fork()}.expect("Error: Fork Failed") {
@@ -25,7 +25,7 @@ fn test_wait_signal() {
#[test]
fn test_wait_exit() {
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
// Safe: Child only calls `_exit`, which is async-signal-safe.
match unsafe{fork()}.expect("Error: Fork Failed") {
@@ -46,7 +46,7 @@ fn test_waitstatus_from_raw() {
#[test]
fn test_waitstatus_pid() {
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
match unsafe{fork()}.unwrap() {
Child => unsafe { _exit(0) },
@@ -97,7 +97,7 @@ mod ptrace {
#[test]
fn test_wait_ptrace() {
require_capability!("test_wait_ptrace", CAP_SYS_PTRACE);
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
match unsafe{fork()}.expect("Error: Fork Failed") {
Child => ptrace_child(),
diff --git a/test/test.rs b/test/test.rs
index b882d174..aade937a 100644
--- a/test/test.rs
+++ b/test/test.rs
@@ -43,7 +43,7 @@ mod test_unistd;
use std::os::unix::io::RawFd;
use std::path::PathBuf;
-use std::sync::{Mutex, RwLock, RwLockWriteGuard};
+use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
use nix::unistd::{chdir, getcwd, read};
@@ -84,8 +84,7 @@ struct DirRestore<'a> {
impl<'a> DirRestore<'a> {
fn new() -> Self {
- let guard = crate::CWD_LOCK.write()
- .expect("Lock got poisoned by another test");
+ let guard = crate::CWD_LOCK.write();
DirRestore{
_g: guard,
d: getcwd().unwrap(),
diff --git a/test/test_kmod/mod.rs b/test/test_kmod/mod.rs
index 0f7fc48e..8eef5384 100644
--- a/test/test_kmod/mod.rs
+++ b/test/test_kmod/mod.rs
@@ -5,9 +5,7 @@ use tempfile::{tempdir, TempDir};
use crate::*;
fn compile_kernel_module() -> (PathBuf, String, TempDir) {
- let _m = crate::FORK_MTX
- .lock()
- .expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
let tmp_dir = tempdir().expect("unable to create temporary build directory");
@@ -41,8 +39,8 @@ use std::io::Read;
#[test]
fn test_finit_and_delete_module() {
require_capability!("test_finit_and_delete_module", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -59,8 +57,8 @@ fn test_finit_and_delete_module() {
#[test]
fn test_finit_and_delete_module_with_params() {
require_capability!("test_finit_and_delete_module_with_params", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -80,8 +78,8 @@ fn test_finit_and_delete_module_with_params() {
#[test]
fn test_init_and_delete_module() {
require_capability!("test_init_and_delete_module", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -100,8 +98,8 @@ fn test_init_and_delete_module() {
#[test]
fn test_init_and_delete_module_with_params() {
require_capability!("test_init_and_delete_module_with_params", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -121,8 +119,8 @@ fn test_init_and_delete_module_with_params() {
#[test]
fn test_finit_module_invalid() {
require_capability!("test_finit_module_invalid", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let kmod_path = "/dev/zero";
@@ -135,8 +133,8 @@ fn test_finit_module_invalid() {
#[test]
fn test_finit_module_twice_and_delete_module() {
require_capability!("test_finit_module_twice_and_delete_module", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -157,8 +155,8 @@ fn test_finit_module_twice_and_delete_module() {
#[test]
fn test_delete_module_not_loaded() {
require_capability!("test_delete_module_not_loaded", CAP_SYS_MODULE);
- let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
- let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m0 = crate::KMOD_MTX.lock();
+ let _m1 = crate::CWD_LOCK.read();
let result = delete_module(&CString::new("hello").unwrap(), DeleteModuleFlags::empty());
diff --git a/test/test_pty.rs b/test/test_pty.rs
index 57874de3..71932f2d 100644
--- a/test/test_pty.rs
+++ b/test/test_pty.rs
@@ -29,7 +29,7 @@ fn test_explicit_close() {
#[test]
#[cfg(any(target_os = "android", target_os = "linux"))]
fn test_ptsname_equivalence() {
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open a new PTTY master
let master_fd = posix_openpt(OFlag::O_RDWR).unwrap();
@@ -46,7 +46,7 @@ fn test_ptsname_equivalence() {
#[test]
#[cfg(any(target_os = "android", target_os = "linux"))]
fn test_ptsname_copy() {
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open a new PTTY master
let master_fd = posix_openpt(OFlag::O_RDWR).unwrap();
@@ -80,7 +80,7 @@ fn test_ptsname_r_copy() {
#[test]
#[cfg(any(target_os = "android", target_os = "linux"))]
fn test_ptsname_unique() {
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open a new PTTY master
let master1_fd = posix_openpt(OFlag::O_RDWR).unwrap();
@@ -98,7 +98,7 @@ fn test_ptsname_unique() {
/// Common setup for testing PTTY pairs
fn open_ptty_pair() -> (PtyMaster, File) {
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open a new PTTY master
let master = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed");
@@ -114,7 +114,7 @@ fn open_ptty_pair() -> (PtyMaster, File) {
let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty()).unwrap();
#[cfg(target_os = "illumos")]
- // TODO: rewrite using ioctl!
+ // TODO: rewrite using ioctl!
#[allow(clippy::comparison_chain)]
{
use libc::{ioctl, I_FIND, I_PUSH};
@@ -187,7 +187,7 @@ fn test_write_ptty_pair() {
#[test]
fn test_openpty() {
// openpty uses ptname(3) internally
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
let pty = openpty(None, None).unwrap();
assert!(pty.master > 0);
@@ -222,7 +222,7 @@ fn test_openpty() {
#[test]
fn test_openpty_with_termios() {
// openpty uses ptname(3) internally
- let _m = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::PTSNAME_MTX.lock();
// Open one pty to get attributes for the second one
let mut termios = {
@@ -273,9 +273,9 @@ fn test_forkpty() {
use nix::sys::signal::*;
use nix::sys::wait::wait;
// forkpty calls openpty which uses ptname(3) internally.
- let _m0 = crate::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m0 = crate::PTSNAME_MTX.lock();
// forkpty spawns a child process
- let _m1 = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = crate::FORK_MTX.lock();
let string = "naninani\n";
let echoed_string = "naninani\r\n";
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 3a3d49dd..61062ad2 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -28,7 +28,7 @@ use crate::*;
#[test]
#[cfg(not(any(target_os = "netbsd")))]
fn test_fork_and_waitpid() {
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
// Safe: Child only calls `_exit`, which is signal-safe
match unsafe{fork()}.expect("Error: Fork Failed") {
@@ -56,7 +56,7 @@ fn test_fork_and_waitpid() {
#[test]
fn test_wait() {
// Grab FORK_MTX so wait doesn't reap a different test's child process
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
// Safe: Child only calls `_exit`, which is signal-safe
match unsafe{fork()}.expect("Error: Fork Failed") {
@@ -116,7 +116,7 @@ fn test_mkfifo_directory() {
target_os = "macos", target_os = "ios",
target_os = "android", target_os = "redox")))]
fn test_mkfifoat_none() {
- let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m = crate::CWD_LOCK.read();
let tempdir = tempdir().unwrap();
let mkfifoat_fifo = tempdir.path().join("mkfifoat_fifo");
@@ -151,10 +151,10 @@ fn test_mkfifoat() {
target_os = "macos", target_os = "ios",
target_os = "android", target_os = "redox")))]
fn test_mkfifoat_directory_none() {
- let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m = crate::CWD_LOCK.read();
// mkfifoat should fail if a directory is given
- assert!(!mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_ok());
+ assert!(mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_err());
}
#[test]
@@ -168,7 +168,7 @@ fn test_mkfifoat_directory() {
let mkfifoat_dir = "mkfifoat_dir";
stat::mkdirat(dirfd, mkfifoat_dir, Mode::S_IRUSR).unwrap();
- assert!(!mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).is_ok());
+ assert!(mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).is_err());
}
#[test]
@@ -206,7 +206,7 @@ fn test_setgroups() {
// Skip this test when not run as root as `setgroups()` requires root.
skip_if_not_root!("test_setgroups");
- let _m = crate::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::GROUPS_MTX.lock();
// Save the existing groups
let old_groups = getgroups().unwrap();
@@ -234,7 +234,7 @@ fn test_initgroups() {
// require root.
skip_if_not_root!("test_initgroups");
- let _m = crate::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::GROUPS_MTX.lock();
// Save the existing groups
let old_groups = getgroups().unwrap();
@@ -304,7 +304,7 @@ macro_rules! execve_test_factory(
skip_if_seccomp!($test_name);
}
- let m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let m = crate::FORK_MTX.lock();
// The `exec`d process will write to `writer`, and we'll read that
// data from `reader`.
let (reader, writer) = pipe().unwrap();
@@ -575,7 +575,7 @@ fn test_acct() {
use std::process::Command;
use std::{thread, time};
- let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock();
require_acct!();
let file = NamedTempFile::new().unwrap();
@@ -735,7 +735,7 @@ fn test_alarm() {
};
// Maybe other tests that fork interfere with this one?
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
let handler = SigHandler::Handler(alarm_signal_handler);
let signal_action = SigAction::new(handler, SaFlags::SA_RESTART, SigSet::empty());
@@ -773,7 +773,7 @@ fn test_alarm() {
#[test]
#[cfg(not(target_os = "redox"))]
fn test_canceling_alarm() {
- let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::SIGNAL_MTX.lock();
assert_eq!(alarm::cancel(), None);
@@ -784,7 +784,7 @@ fn test_canceling_alarm() {
#[test]
#[cfg(not(target_os = "redox"))]
fn test_symlinkat() {
- let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m = crate::CWD_LOCK.read();
let tempdir = tempdir().unwrap();
@@ -883,7 +883,7 @@ fn test_linkat_newdirfd_none() {
#[test]
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))]
fn test_linkat_no_follow_symlink() {
- let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m = crate::CWD_LOCK.read();
let tempdir = tempdir().unwrap();
let oldfilename = "foo.txt";
@@ -920,7 +920,7 @@ fn test_linkat_no_follow_symlink() {
#[test]
#[cfg(not(target_os = "redox"))]
fn test_linkat_follow_symlink() {
- let _m = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
+ let _m = crate::CWD_LOCK.read();
let tempdir = tempdir().unwrap();
let oldfilename = "foo.txt";