nix icon indicating copy to clipboard operation
nix copied to clipboard

Get original `i32` value instead of `Signal`

Open pxeger opened this issue 3 years ago • 0 comments
trafficstars

I have an API which requires a raw integer signal value, and that signal value comes from the return value of waitid. Currently it has to be manually mapped in my code using a horrible long match expression.

There is no way to convert a Signal into an i32, because their underlying values differ depending on platform. Perhaps there could be a function that returns an i32 which is not guaranteed to be constant? Although maybe this is not easily possible using libc and it would mean nix has to maintain its own mappings of signal values, which may be why a way doesn't exist already - I would understand this.

Another idea would be, for APIs such as WaitStatus, it would be nice to have an API that returns i32s instead of Signals in the first place. Perhaps the wait/waitpid/waitid functions, and the WaitStatus struct, could be generic over a trait called something like SignalLike, which would be implemented by Signal and i32. The same goes for other APIs which return Signals.

pxeger avatar Sep 21 '22 20:09 pxeger