capsicum-rs
capsicum-rs copied to clipboard
Replace the Fcntl enum with values from libc
Replace Fcntl::GetFL with libc::F_GETFL, etc.
We have a decision to make here. The tradeoff is type safety vs future proofing. The most future-proof way to do this would be to accept any u32
in FcntlsBuilder::add
. That's similar to what IoctlsBuilder
does. But it isn't type-safe, which is unfortunate. A safer option would be to create an enum of allowed values. We could even create it automatically by copying Nix's libc_enum! macro. But that isn't future-proof, because if FreeBSD adds a new fnctl value, capsicum-rs would need to be updated before our users could make use.
A compromise might be to define Fcntl values as consts, like this:
struct Fcntl(u32);
impl Fcntl {
const F_GETFL = Fcntl(libc::F_GETFL);
...
}
Or something along those lines. What do you think?
The same argument applies to IoctlsBuilder
. However, allowed ioctl values are much more numerous, and they may not all be defined in libc. Plus, users may even have custom ioctls that come from out-of-tree (or even proprietary) kernel modules. So for IoctlsBuilder
, future-proofing is much more important.
Depends on https://github.com/rust-lang/libc/pull/3628