diff --git a/src/tools/runk/src/commands/kill.rs b/src/tools/runk/src/commands/kill.rs index 0ae0d343dd..4526749da5 100644 --- a/src/tools/runk/src/commands/kill.rs +++ b/src/tools/runk/src/commands/kill.rs @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 // -use crate::Kill; use anyhow::Result; use libcontainer::container::Container; +use liboci_cli::Kill; use nix::sys::signal::Signal; use slog::{info, Logger}; use std::{convert::TryFrom, path::Path, str::FromStr}; @@ -15,9 +15,6 @@ pub fn run(opts: Kill, state_root: &Path, logger: &Logger) -> Result<()> { let container = Container::load(state_root, container_id)?; let sig = parse_signal(&opts.signal)?; - // TODO: liboci-cli does not support --all option for kill command. - // After liboci-cli supports the option, we will change the following code. - // as a workaround we use a custom Kill command. let all = opts.all; container.kill(sig, all)?; diff --git a/src/tools/runk/src/main.rs b/src/tools/runk/src/main.rs index 6b282ed0b4..c79746678e 100644 --- a/src/tools/runk/src/main.rs +++ b/src/tools/runk/src/main.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Result}; use clap::{crate_description, crate_name, Parser}; use liboci_cli::{CommonCmd, GlobalOpts}; -use liboci_cli::{Create, Delete, Start, State}; +use liboci_cli::{Create, Delete, Kill, Start, State}; use slog::{o, Logger}; use slog_async::AsyncGuard; use std::{ @@ -26,39 +26,20 @@ enum SubCommand { Standard(StandardCmd), #[clap(flatten)] Common(CommonCmd), - #[clap(flatten)] - Custom(CustomCmd), /// Launch an init process (do not call it outside of runk) Init {}, } // Copy from https://github.com/containers/youki/blob/v0.0.3/crates/liboci-cli/src/lib.rs#L38-L44 -// but without Kill command. #[derive(Parser, Debug)] pub enum StandardCmd { Create(Create), Start(Start), State(State), Delete(Delete), -} - -// as a workaround to support --all option for kill command, -// we use a custom implementation of Kill. -#[derive(Parser, Debug)] -pub enum CustomCmd { Kill(Kill), } -/// Send the specified signal to the container -#[derive(Parser, Debug)] -pub struct Kill { - #[clap(forbid_empty_values = true, required = true)] - pub container_id: String, - pub signal: String, - #[clap(short, long)] - pub all: bool, -} - #[derive(Parser, Debug)] #[clap(version, author, about = crate_description!())] struct Cli { @@ -75,6 +56,7 @@ async fn cmd_run(subcmd: SubCommand, root_path: &Path, logger: &Logger) -> Resul StandardCmd::Start(start) => commands::start::run(start, root_path, logger).await, StandardCmd::Delete(delete) => commands::delete::run(delete, root_path, logger).await, StandardCmd::State(state) => commands::state::run(state, root_path, logger), + StandardCmd::Kill(kill) => commands::kill::run(kill, root_path, logger), }, SubCommand::Common(cmd) => match cmd { CommonCmd::Run(run) => commands::run::run(run, root_path, logger).await, @@ -88,9 +70,6 @@ async fn cmd_run(subcmd: SubCommand, root_path: &Path, logger: &Logger) -> Resul return Err(anyhow!("command is not implemented yet")); } }, - SubCommand::Custom(cmd) => match cmd { - CustomCmd::Kill(kill) => commands::kill::run(kill, root_path, logger), - }, _ => unreachable!(), } }