Skip to content

Commit 01a5927

Browse files
Merge #1739
1739: ppoll: make sigmask parameter optional r=rtzoeller a=stefano-garzarella ppoll(2) supports 'sigmask' as NULL. In that case no signal mask manipulation is performed. Let's make `sigmask` parameter of `nix::poll::ppoll` optional to allow that behaviour. Signed-off-by: Stefano Garzarella <[email protected]> Co-authored-by: Stefano Garzarella <[email protected]>
2 parents b3ba2b5 + c3081e4 commit 01a5927

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2828
* Changes the type of the `priority` arguments to `i32`.
2929
* Changes the return type of `aio_return` to `usize`.
3030
(#[1713](https://github.com/nix-rust/nix/pull/1713))
31+
- `nix::poll::ppoll`: `sigmask` parameter is now optional.
32+
(#[1739](https://github.com/nix-rust/nix/pull/1739))
3133

3234
### Fixed
3335

src/poll.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,24 @@ feature! {
151151
/// `ppoll` behaves like `poll`, but let you specify what signals may interrupt it
152152
/// with the `sigmask` argument. If you want `ppoll` to block indefinitely,
153153
/// specify `None` as `timeout` (it is like `timeout = -1` for `poll`).
154+
/// If `sigmask` is `None`, then no signal mask manipulation is performed,
155+
/// so in that case `ppoll` differs from `poll` only in the precision of the
156+
/// timeout argument.
154157
///
155158
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
156159
pub fn ppoll(
157160
fds: &mut [PollFd],
158161
timeout: Option<crate::sys::time::TimeSpec>,
159-
sigmask: crate::sys::signal::SigSet
162+
sigmask: Option<crate::sys::signal::SigSet>
160163
) -> Result<libc::c_int>
161164
{
162165
let timeout = timeout.as_ref().map_or(core::ptr::null(), |r| r.as_ref());
166+
let sigmask = sigmask.as_ref().map_or(core::ptr::null(), |r| r.as_ref());
163167
let res = unsafe {
164168
libc::ppoll(fds.as_mut_ptr() as *mut libc::pollfd,
165169
fds.len() as libc::nfds_t,
166170
timeout,
167-
sigmask.as_ref())
171+
sigmask)
168172
};
169173
Errno::result(res)
170174
}

test/test_poll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ fn test_ppoll() {
5353

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

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

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

0 commit comments

Comments
 (0)