From 47612bf47c720456a3f3bf6ef84b963c8f97175c Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Thu, 17 Aug 2023 16:02:21 -0700 Subject: [PATCH] simplify more Signed-off-by: James Sturtevant --- .../containerd-shim-wasm/src/sandbox/oci.rs | 28 +++++++------------ .../containerd-shim-wasm/src/sandbox/shim.rs | 4 --- .../containerd-shim-wasmedge/src/executor.rs | 2 -- crates/containerd-shim-wasmedge/src/lib.rs | 5 +++- .../containerd-shim-wasmtime/src/executor.rs | 2 -- crates/containerd-shim-wasmtime/src/lib.rs | 4 ++- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/crates/containerd-shim-wasm/src/sandbox/oci.rs b/crates/containerd-shim-wasm/src/sandbox/oci.rs index 15e286f80..fb434b32f 100644 --- a/crates/containerd-shim-wasm/src/sandbox/oci.rs +++ b/crates/containerd-shim-wasm/src/sandbox/oci.rs @@ -105,20 +105,21 @@ pub fn setup_prestart_hooks(hooks: &Option) -> Result< log::debug!("run_hooks arg0: {:?}, args: {:?}", arg0, args); #[cfg(unix)] - hook_command.arg0(arg0).args(args); + { + hook_command.arg0(arg0).args(args); + } #[cfg(windows)] - if !&hook.path().ends_with(arg0) { - log::debug!("Running with arg0 as different name than executable is not supported on Windows due to rust std library process implementation."); - } else { + { + if !&hook.path().ends_with(arg0) { + return Err(crate::sandbox::Error::InvalidArgument("Running with arg0 as different name than executable is not supported on Windows due to rust std library process implementation.".to_string())); + } + hook_command.args(args); - }; + } } else { #[cfg(unix)] hook_command.arg0(&hook.path().display().to_string()); - - #[cfg(windows)] - log::debug!("Running with hook path as process"); }; let envs: HashMap = if let Some(env) = hook.env() { @@ -149,16 +150,7 @@ pub fn setup_prestart_hooks(hooks: &Option) -> Result< if e.kind() != ErrorKind::BrokenPipe { // Not a broken pipe. The hook command may be waiting // for us. - #[cfg(unix)] - { - let hook_process_pid = Pid::from_raw(hook_process.id() as i32); - let _ = signal::kill(hook_process_pid, signal::Signal::SIGKILL); - } - - #[cfg(windows)] - { - let _ = hook_process.kill(); - } + let _ = hook_process.kill(); } } } diff --git a/crates/containerd-shim-wasm/src/sandbox/shim.rs b/crates/containerd-shim-wasm/src/sandbox/shim.rs index 8ce9d816d..f93677037 100644 --- a/crates/containerd-shim-wasm/src/sandbox/shim.rs +++ b/crates/containerd-shim-wasm/src/sandbox/shim.rs @@ -1,7 +1,6 @@ //! The shim is the entrypoint for the containerd shim API. It is responsible //! for commmuincating with the containerd daemon and managing the lifecycle of //! the container/sandbox. -//! use std::collections::HashMap; use std::env::current_dir; @@ -866,13 +865,10 @@ impl Local { .as_ref() .ok_or_else(|| Error::InvalidArgument("rootfs is not set in runtime spec".to_string()))? .path(); - let mut mkdir = DirBuilder::new(); mkdir.recursive(true); - #[cfg(unix)] mkdir.mode(0o755); - if mkdir.create(rootfs).is_ok() { /* ignore */ } let rootfs_mounts = req.rootfs().to_vec(); diff --git a/crates/containerd-shim-wasmedge/src/executor.rs b/crates/containerd-shim-wasmedge/src/executor.rs index 073d5a5e8..4612a4313 100644 --- a/crates/containerd-shim-wasmedge/src/executor.rs +++ b/crates/containerd-shim-wasmedge/src/executor.rs @@ -1,5 +1,3 @@ -#![cfg(unix)] - use anyhow::Result; use containerd_shim_wasm::sandbox::oci; use nix::unistd::{dup, dup2}; diff --git a/crates/containerd-shim-wasmedge/src/lib.rs b/crates/containerd-shim-wasmedge/src/lib.rs index 76ff57f56..4247aa64c 100644 --- a/crates/containerd-shim-wasmedge/src/lib.rs +++ b/crates/containerd-shim-wasmedge/src/lib.rs @@ -1,8 +1,11 @@ pub mod error; -pub mod executor; + pub mod instance; pub mod oci_utils; +#[cfg(unix)] +pub mod executor; + #[cfg(unix)] #[cfg(test)] mod test { diff --git a/crates/containerd-shim-wasmtime/src/executor.rs b/crates/containerd-shim-wasmtime/src/executor.rs index 739b1f4a6..28df4e255 100644 --- a/crates/containerd-shim-wasmtime/src/executor.rs +++ b/crates/containerd-shim-wasmtime/src/executor.rs @@ -1,5 +1,3 @@ -#![cfg(unix)] - use nix::unistd::{dup, dup2}; use std::{fs::OpenOptions, os::fd::RawFd, path::PathBuf}; diff --git a/crates/containerd-shim-wasmtime/src/lib.rs b/crates/containerd-shim-wasmtime/src/lib.rs index 312731e44..6e9fec504 100644 --- a/crates/containerd-shim-wasmtime/src/lib.rs +++ b/crates/containerd-shim-wasmtime/src/lib.rs @@ -1,4 +1,6 @@ pub mod error; -pub mod executor; pub mod instance; pub mod oci_wasmtime; + +#[cfg(unix)] +pub mod executor;