Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppoll: make sigmask parameter optional #1739

Merged
merged 1 commit into from
Jun 9, 2022
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Changes the type of the `priority` arguments to `i32`.
* Changes the return type of `aio_return` to `usize`.
(#[1713](https://github.com/nix-rust/nix/pull/1713))
- `nix::poll::ppoll`: `sigmask` parameter is now optional.
stefano-garzarella marked this conversation as resolved.
Show resolved Hide resolved
(#[1739](https://github.com/nix-rust/nix/pull/1739))

### Fixed

Expand Down
8 changes: 6 additions & 2 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,24 @@ feature! {
/// `ppoll` behaves like `poll`, but let you specify what signals may interrupt it
/// with the `sigmask` argument. If you want `ppoll` to block indefinitely,
/// specify `None` as `timeout` (it is like `timeout = -1` for `poll`).
/// If `sigmask` is `None`, then no signal mask manipulation is performed,
/// so in that case `ppoll` differs from `poll` only in the precision of the
/// timeout argument.
///
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
pub fn ppoll(
fds: &mut [PollFd],
timeout: Option<crate::sys::time::TimeSpec>,
sigmask: crate::sys::signal::SigSet
sigmask: Option<crate::sys::signal::SigSet>
) -> Result<libc::c_int>
{
let timeout = timeout.as_ref().map_or(core::ptr::null(), |r| r.as_ref());
let sigmask = sigmask.as_ref().map_or(core::ptr::null(), |r| r.as_ref());
let res = unsafe {
libc::ppoll(fds.as_mut_ptr() as *mut libc::pollfd,
fds.len() as libc::nfds_t,
timeout,
sigmask.as_ref())
sigmask)
};
Errno::result(res)
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ fn test_ppoll() {

// Poll an idle pipe. Should timeout
let sigset = SigSet::empty();
let nfds = loop_while_eintr!(ppoll(&mut fds, Some(timeout), sigset));
let nfds = loop_while_eintr!(ppoll(&mut fds, Some(timeout), Some(sigset)));
assert_eq!(nfds, 0);
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));

write(w, b".").unwrap();

// Poll a readable pipe. Should return an event.
let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap();
let nfds = ppoll(&mut fds, Some(timeout), None).unwrap();
assert_eq!(nfds, 1);
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
}
Expand Down