chore(ops/posix_mq.rs): upgrade to nix 0.23
The previous version had a CVE. As part of this upgrade, the handling of errors inside of the Nix crate changed, which we now accommodate. Change-Id: Iad9a473c1782e0d79919cb5dc3f76316852d8a16 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5226 Tested-by: BuildkiteCI Autosubmit: tazjin <tazjin@tvl.su> Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
a2ecd53f58
commit
91ef2b671e
3 changed files with 50 additions and 49 deletions
|
|
@ -47,7 +47,7 @@ pub enum Error {
|
|||
|
||||
// Some other unexpected / unknown error occured. This is probably an error from
|
||||
// the nix crate. Bug reports also welcome for this!
|
||||
UnknownInternalError(Option<nix::Error>),
|
||||
UnknownInternalError(),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
|
|
@ -74,7 +74,7 @@ impl fmt::Display for Error {
|
|||
"maximum number of system file descriptors reached"
|
||||
}
|
||||
UnknownForeignError(_) => "unknown foreign error occured: please report a bug!",
|
||||
UnknownInternalError(_) => "unknown internal error occured: please report a bug!",
|
||||
UnknownInternalError() => "unknown internal error occured: please report a bug!",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -91,11 +91,20 @@ impl error::Error for Error {
|
|||
|
||||
/// This from implementation is used to translate errors from the lower-level
|
||||
/// C-calls into sensible Rust errors.
|
||||
impl From<nix::Error> for Error {
|
||||
fn from(e: nix::Error) -> Self {
|
||||
match e {
|
||||
nix::Error::Sys(e) => match_errno(e),
|
||||
_ => Error::UnknownInternalError(Some(e)),
|
||||
impl From<nix::errno::Errno> for Error {
|
||||
fn from(err: nix::Error) -> Self {
|
||||
use nix::errno::Errno::*;
|
||||
match err {
|
||||
EACCES => Error::PermissionDenied(),
|
||||
EBADF => Error::InvalidQueueDescriptor(),
|
||||
EINTR => Error::QueueCallInterrupted(),
|
||||
EEXIST => Error::QueueAlreadyExists(),
|
||||
EMFILE => Error::ProcessFileDescriptorLimitReached(),
|
||||
ENFILE => Error::SystemFileDescriptorLimitReached(),
|
||||
ENOENT => Error::QueueNotFound(),
|
||||
ENOMEM => Error::InsufficientMemory(),
|
||||
ENOSPC => Error::InsufficientSpace(),
|
||||
_ => Error::UnknownForeignError(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -111,23 +120,6 @@ impl From<io::Error> for Error {
|
|||
// here because the system is probably seriously broken if those files don't contain numbers.
|
||||
impl From<num::ParseIntError> for Error {
|
||||
fn from(_: num::ParseIntError) -> Self {
|
||||
Error::UnknownInternalError(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn match_errno(err: nix::errno::Errno) -> Error {
|
||||
use nix::errno::Errno::*;
|
||||
|
||||
match err {
|
||||
EACCES => Error::PermissionDenied(),
|
||||
EBADF => Error::InvalidQueueDescriptor(),
|
||||
EINTR => Error::QueueCallInterrupted(),
|
||||
EEXIST => Error::QueueAlreadyExists(),
|
||||
EMFILE => Error::ProcessFileDescriptorLimitReached(),
|
||||
ENFILE => Error::SystemFileDescriptorLimitReached(),
|
||||
ENOENT => Error::QueueNotFound(),
|
||||
ENOMEM => Error::InsufficientMemory(),
|
||||
ENOSPC => Error::InsufficientSpace(),
|
||||
_ => Error::UnknownForeignError(err),
|
||||
Error::UnknownInternalError()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue