From aba572e01df4e49d882226a3034eac2e8c8a3b45 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Tue, 30 Nov 2021 13:24:04 +0000 Subject: [PATCH] rustjail: Wrap remaining nix errors with anyhow Replace `Result` values that use a "bare" `nix` `Error` like this: ```rust return Err(nix::Error::EINVAL.into()); ``` ... to the following which wraps the nix` error in an `anyhow` call for consistency with the other errors returned by `rustjail`: ```rust return Err(anyhow!(nix::Error::EINVAL)); ``` Signed-off-by: James O. D. Hunt --- src/agent/rustjail/src/cgroups/fs/mod.rs | 2 +- src/agent/rustjail/src/container.rs | 4 ++-- src/agent/rustjail/src/mount.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs index 9ae5fff61d..b4cf73e31a 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -174,7 +174,7 @@ impl CgroupManager for Manager { freezer_controller.freeze()?; } _ => { - return Err(nix::Error::EINVAL.into()); + return Err(anyhow!(nix::Error::EINVAL)); } } diff --git a/src/agent/rustjail/src/container.rs b/src/agent/rustjail/src/container.rs index 04c2861289..e4ac711e7d 100644 --- a/src/agent/rustjail/src/container.rs +++ b/src/agent/rustjail/src/container.rs @@ -1388,13 +1388,13 @@ impl LinuxContainer { .context(format!("cannot change onwer of container {} root", id))?; if config.spec.is_none() { - return Err(nix::Error::EINVAL.into()); + return Err(anyhow!(nix::Error::EINVAL)); } let spec = config.spec.as_ref().unwrap(); if spec.linux.is_none() { - return Err(nix::Error::EINVAL.into()); + return Err(anyhow!(nix::Error::EINVAL)); } let linux = spec.linux.as_ref().unwrap(); diff --git a/src/agent/rustjail/src/mount.rs b/src/agent/rustjail/src/mount.rs index 53a3f34b3e..d9bc5d0198 100644 --- a/src/agent/rustjail/src/mount.rs +++ b/src/agent/rustjail/src/mount.rs @@ -999,7 +999,7 @@ pub fn finish_rootfs(cfd_log: RawFd, spec: &Spec, process: &Process) -> Result<( fn mask_path(path: &str) -> Result<()> { if !path.starts_with('/') || path.contains("..") { - return Err(nix::Error::EINVAL.into()); + return Err(anyhow!(nix::Error::EINVAL)); } match mount( @@ -1019,7 +1019,7 @@ fn mask_path(path: &str) -> Result<()> { fn readonly_path(path: &str) -> Result<()> { if !path.starts_with('/') || path.contains("..") { - return Err(nix::Error::EINVAL.into()); + return Err(anyhow!(nix::Error::EINVAL)); } if let Err(e) = mount(