Merge pull request #5556 from ManaSugi/runk/fix-kill-behavior

runk: Ignore an error when calling kill cmd with --all option
This commit is contained in:
Bin Liu 2022-11-04 08:42:27 +08:00 committed by GitHub
commit b0c7bcce7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -83,14 +83,6 @@ impl Container {
}
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 {
let pids = self.processes()?;
for pid in pids {
@ -100,6 +92,16 @@ impl Container {
kill(pid, signal)?;
}
} 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);
if status::is_process_running(pid)? {
kill(pid, signal)?;

View File

@ -141,7 +141,7 @@ pub fn is_process_running(pid: Pid) -> Result<bool> {
match kill(pid, None) {
Err(errno) => {
if errno != Errno::ESRCH {
return Err(anyhow!("no such process"));
return Err(anyhow!("failed to kill process {}: {:?}", pid, errno));
}
Ok(false)
}