nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.57k stars 650 forks source link

Realtime signals #495

Open SdNssr opened 7 years ago

SdNssr commented 7 years ago

Realtime signals seem to be missing from nix::sys::signal::Signal, and quite a few functions seem to panic on receiving realtime signals:

So is this something that won't be supported, or is it just incomplete?

fiveop commented 7 years ago

It is just incomplete. Feel free to add them. You might need to add the constants to libc first.

Susurrus commented 7 years ago

@SdNssr Any interest in filing a PR for this functionality?

SdNssr commented 6 years ago

No, not really.

ObsidianMinor commented 8 months ago

I want to take a shot at this. Only thing I see being an issue is how much of the existing API we want to keep.

If we want to keep the existing Signal type (because conversions to and from strings is nice), then I'd propose new types RtSignal and Signum.

RtSignal would be used to define new real-time signal values, with the function RtSignal::new(i32) being used to create the values, offset from SIGRTMIN. So RtSignal::new(0) would be the minimum value, RtSignal::new(1) would be SIGRTMIN() + 1, etc. This would return an optional value and can't be converted to a string except via debug impl.

Signum would take the place of most usage of Signal, it being a less typed variant that can represent a RtSignal or Signal value. SigSet's API would be based on Signum, accepting and returning instances of the type. You can attempt to unwrap an RtSignal or a Signal value from a Signum, for instance, for converting to a string, but functions wouldn't be defined on it.

Because Signum would be the primary type being used by SigSet, it would have it's own set of associated constants that correspond to the libc constants. These would be re-exported in place of the Signal enumerants. This is because I'm assuming that most people are using the Signal re-exported values for pattern matching on the result of SigSet::wait, so this would be the last painful upgrade path.

Alternatively, we rewrite the whole Signal type. We keep FromStr, but nothing can be converted into a real-time signal. as_str becomes something like try_as_str, which returns an optional value, none when a real-time signal is the value. AsRef<str> is removed, fmt::Display is removed, and SignalIterator is adjusted to iterate all valid real-time signal values as well.

Thoughts?