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

Sigset conveniance #1959

Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- Fixed the function signature of `recvmmsg`, potentially causing UB
([#2119](https://github.com/nix-rust/nix/issues/2119))
### Added

- Added `impl From<Signal> for SigSet`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what happened here, but this sure is a riotous merge error. Could you fix it please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

### Addded has already been added:

### Added
- Added `impl From<Signal> for SigSet`.
  ([#1959](https://github.com/nix-rust/nix/pull/1959))
- ...

### Changed
- ...

### Added
- Added `Icmp` and `IcmpV6` to `SockProtocol`.
  (#[2103](https://github.com/nix-rust/nix/pull/2103))

There are now two ### Added sections in this file, we need to merge them

([#1959](https://github.com/nix-rust/nix/pull/1959))
- Added `impl std::ops::BitOr for SigSet`.
([#1959](https://github.com/nix-rust/nix/pull/1959))
- Added `impl std::ops::BitOr for Signal`.
([#1959](https://github.com/nix-rust/nix/pull/1959))
- Added `impl std::ops::BitOr<Signal> for SigSet`
([#1959](https://github.com/nix-rust/nix/pull/1959))

### Changed

Expand Down
37 changes: 37 additions & 0 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cfg_if::cfg_if;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::BitOr;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
use std::os::unix::io::RawFd;
use std::ptr;
Expand Down Expand Up @@ -604,6 +605,42 @@ impl SigSet {
}
}

impl From<Signal> for SigSet {
fn from(signal: Signal) -> SigSet {
let mut sigset = SigSet::empty();
sigset.add(signal);
sigset
}
}

impl BitOr for Signal {
type Output = SigSet;

fn bitor(self, rhs: Self) -> Self::Output {
let mut sigset = SigSet::empty();
sigset.add(self);
sigset.add(rhs);
sigset
}
}

impl BitOr<Signal> for SigSet {
type Output = SigSet;

fn bitor(mut self, rhs: Signal) -> Self::Output {
self.add(rhs);
self
}
}

impl BitOr for SigSet {
type Output = Self;

fn bitor(self, rhs: Self) -> Self::Output {
self.iter().chain(rhs.iter()).collect()
}
}

impl AsRef<libc::sigset_t> for SigSet {
fn as_ref(&self) -> &libc::sigset_t {
&self.sigset
Expand Down