diff --git a/src/runtime-rs/crates/service/src/event.rs b/src/runtime-rs/crates/service/src/event.rs index 79cf711027..fc5868f3a8 100644 --- a/src/runtime-rs/crates/service/src/event.rs +++ b/src/runtime-rs/crates/service/src/event.rs @@ -38,12 +38,14 @@ pub(crate) trait Forwarder { /// `TTRPC_ADDRESS` existing. Otherwise, fall back to `LogForwarder`. pub(crate) async fn new_event_publisher(namespace: &str) -> Result> { let fwd: Box = match env::var(TTRPC_ADDRESS_ENV) { - Ok(address) => Box::new( + Ok(address) if !address.is_empty() => Box::new( ContainerdForwarder::new(namespace, &address) .await .context("new containerd forwarder")?, ), - Err(_) => Box::new( + // an empty address doesn't match the arm above so catch it here + // and handle it the same way as if it's missing altogether + Ok(_) | Err(_) => Box::new( LogForwarder::new(namespace) .await .context("new log forwarder")?, diff --git a/src/runtime-rs/crates/shim/src/args.rs b/src/runtime-rs/crates/shim/src/args.rs index 1ab5b8afab..9027678a0e 100644 --- a/src/runtime-rs/crates/shim/src/args.rs +++ b/src/runtime-rs/crates/shim/src/args.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::{os::unix::fs::FileTypeExt, path::PathBuf}; +use std::path::PathBuf; use anyhow::{anyhow, Context, Result}; use kata_sys_util::validate; @@ -38,11 +38,7 @@ impl Args { /// The id, namespace, address and publish_binary are mandatory for START, RUN and DELETE. /// And bundle is mandatory for DELETE. pub fn validate(&mut self, should_check_bundle: bool) -> Result<()> { - if self.id.is_empty() - || self.namespace.is_empty() - || self.address.is_empty() - || self.publish_binary.is_empty() - { + if self.id.is_empty() || self.namespace.is_empty() || self.publish_binary.is_empty() { return Err(anyhow!(Error::ArgumentIsEmpty(format!( "id: {} namespace: {} address: {} publish_binary: {}", &self.id, &self.namespace, &self.address, &self.publish_binary @@ -52,21 +48,6 @@ impl Args { validate::verify_id(&self.id).context("verify container id")?; validate::verify_id(&self.namespace).context("verify namespace")?; - // Ensure `address` is a valid path. - let path = PathBuf::from(self.address.clone()) - .canonicalize() - .context(Error::InvalidPath(self.address.clone()))?; - let md = path - .metadata() - .context(Error::FileGetMetadata(format!("{:?}", path)))?; - if !md.file_type().is_socket() { - return Err(Error::InvalidArgument).context("address is not socket"); - } - self.address = path - .to_str() - .map(|v| v.to_owned()) - .ok_or(Error::InvalidArgument)?; - // Ensure `bundle` is a valid path. if should_check_bundle { if self.bundle.is_empty() { @@ -182,10 +163,7 @@ mod tests { arg.clone() }, should_check_bundle: false, - result: Err(anyhow!(Error::ArgumentIsEmpty(format!( - "id: {} namespace: {} address: {} publish_binary: {}", - &arg.id, &arg.namespace, &arg.address, &arg.publish_binary - )))), + result: Ok(()), }, TestData { arg: { @@ -276,22 +254,6 @@ mod tests { should_check_bundle: true, result: Ok(()), }, - TestData { - arg: { - arg.address = default_address.clone() + "/.."; - arg.clone() - }, - should_check_bundle: true, - result: Err(anyhow!(Error::InvalidPath(arg.address.clone()))), - }, - TestData { - arg: { - arg.address = default_address.clone() + "/.."; - arg.clone() - }, - should_check_bundle: true, - result: Err(anyhow!(Error::InvalidPath(arg.address.clone()))), - }, TestData { arg: { arg.address = default_address; diff --git a/src/runtime-rs/crates/shim/src/shim_start.rs b/src/runtime-rs/crates/shim/src/shim_start.rs index 06a7f3ae5f..72e4870661 100644 --- a/src/runtime-rs/crates/shim/src/shim_start.rs +++ b/src/runtime-rs/crates/shim/src/shim_start.rs @@ -61,7 +61,6 @@ impl ShimExecutor { fn new_command(&self) -> Result { if self.args.id.is_empty() || self.args.namespace.is_empty() - || self.args.address.is_empty() || self.args.publish_binary.is_empty() { return Err(anyhow!("invalid param"));