1
0
mirror of https://github.com/containers/youki synced 2024-11-23 09:21:57 +01:00

Add TestContainerKill required error message in kill command

This commit is contained in:
Yashodhan Joshi 2022-11-06 16:56:56 +05:30
parent 184c21b794
commit 2f8a153eb8

@ -4,11 +4,20 @@ use std::{convert::TryInto, path::PathBuf};
use anyhow::Result;
use crate::commands::load_container;
use libcontainer::signal::Signal;
use libcontainer::{container::ContainerStatus, signal::Signal};
use liboci_cli::Kill;
pub fn kill(args: Kill, root_path: PathBuf) -> Result<()> {
let mut container = load_container(root_path, &args.container_id)?;
let signal: Signal = args.signal.as_str().try_into()?;
container.kill(signal, args.all)
match container.kill(signal, args.all) {
Ok(_) => Ok(()),
Err(e) => {
// see https://github.com/containers/youki/issues/1314
if container.status() == ContainerStatus::Stopped {
return Err(e.context("container not running"));
}
Err(e)
}
}
}