Skip to content

Commit

Permalink
Remove return value from pause
Browse files Browse the repository at this point in the history
`pause` will always return `-1` as a result and sets `errno` to
`EINTR`, which indicates that a signal was caught by the process. Since
this is the point of `pause` return an error here makes little sense.

Closes #827.
  • Loading branch information
Thomasdezeeuw committed Jan 11, 2018
1 parent 2478f0f commit 992c293
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Both `ip_mreq` and `ipv6_mreq` have been replaced with `IpMembershipRequest` and
`Ipv6MembershipRequest`.
([#814](https://github.com/nix-rust/nix/pull/814))

- Removed return type from `pause`.
([#829](https://github.com/nix-rust/nix/pull/829))

### Fixed
- Fix compilation and tests for OpenBSD targets
Expand Down
10 changes: 4 additions & 6 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,14 +1316,12 @@ pub fn initgroups(user: &CStr, group: Gid) -> Result<()> {
Errno::result(res).map(|_| ())
}

/// Suspend the thread until a signal is received
/// Suspend the thread until a signal is received.
///
/// See also [pause(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html)
/// See also [pause(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html).
#[inline]
pub fn pause() -> Result<()> {
let res = unsafe { libc::pause() };

Errno::result(res).map(drop)
pub fn pause() {
unsafe { libc::pause() };
}

/// Suspend execution for an interval of time
Expand Down
5 changes: 4 additions & 1 deletion test/sys/test_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ fn test_wait_signal() {

// Safe: The child only calls `pause` and/or `_exit`, which are async-signal-safe.
match fork().expect("Error: Fork Failed") {
Child => pause().unwrap_or_else(|_| unsafe { _exit(123) }),
Child => {
pause();
unsafe { _exit(123) }
},
Parent { child } => {
kill(child, Some(SIGKILL)).expect("Error: Kill Failed");
assert_eq!(waitpid(child, None), Ok(WaitStatus::Signaled(child, SIGKILL, false)));
Expand Down

0 comments on commit 992c293

Please sign in to comment.