mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
runk: Ignore an error when calling kill cmd with --all option
Ignore an error handling that is triggered when the kill command is called with `--all option` to the stopped container. High-level container runtimes such as containerd call the kill command with `--all` option in order to terminate all processes inside the container even if the container already is stopped. Hence, a low-level runtime should allow `kill --all` regardless of the container state like runc. This commit reverts to the previous behavior. Fixes: #5555 Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
This commit is contained in:
parent
288e337a6f
commit
16dca4ecd4
@ -83,14 +83,6 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn kill(&self, signal: Signal, all: bool) -> Result<()> {
|
pub fn kill(&self, signal: Signal, all: bool) -> Result<()> {
|
||||||
if self.state == ContainerState::Stopped {
|
|
||||||
return Err(anyhow!(
|
|
||||||
"container {} can't be killed because it is {:?}",
|
|
||||||
self.status.id,
|
|
||||||
self.state
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if all {
|
if all {
|
||||||
let pids = self.processes()?;
|
let pids = self.processes()?;
|
||||||
for pid in pids {
|
for pid in pids {
|
||||||
@ -100,6 +92,16 @@ impl Container {
|
|||||||
kill(pid, signal)?;
|
kill(pid, signal)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// If --all option is not specified and the container is stopped,
|
||||||
|
// kill operation generates an error in accordance with the OCI runtime spec.
|
||||||
|
if self.state == ContainerState::Stopped {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"container {} can't be killed because it is {:?}",
|
||||||
|
self.status.id,
|
||||||
|
self.state
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let pid = Pid::from_raw(self.status.pid);
|
let pid = Pid::from_raw(self.status.pid);
|
||||||
if status::is_process_running(pid)? {
|
if status::is_process_running(pid)? {
|
||||||
kill(pid, signal)?;
|
kill(pid, signal)?;
|
||||||
|
@ -141,7 +141,7 @@ pub fn is_process_running(pid: Pid) -> Result<bool> {
|
|||||||
match kill(pid, None) {
|
match kill(pid, None) {
|
||||||
Err(errno) => {
|
Err(errno) => {
|
||||||
if errno != Errno::ESRCH {
|
if errno != Errno::ESRCH {
|
||||||
return Err(anyhow!("no such process"));
|
return Err(anyhow!("failed to kill process {}: {:?}", pid, errno));
|
||||||
}
|
}
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user