1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-05-09 08:57:25 +00:00

agent: kill child process when console socket closed

when use debug console, the shell run in child process may not be
exited, in some scenes.
eg. directly Ctrl-C in the host to terminate the kata-runtime process,
that will block the task handling the console connection,while waiting
for the child to exit.

Signed-off-by: soulfy <liukai254@jd.com>
This commit is contained in:
soulfy 2024-08-09 14:20:24 +08:00 committed by liukai254
parent 43dca8deb4
commit 722b576eb3

View File

@ -11,7 +11,7 @@ use nix::libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
use nix::pty::{openpty, OpenptyResult};
use nix::sys::socket::{self, AddressFamily, SockFlag, SockType, VsockAddr};
use nix::sys::stat::Mode;
use nix::sys::wait;
use nix::sys::{signal, wait};
use nix::unistd::{self, close, dup2, fork, setsid, ForkResult, Pid};
use rustjail::pipestream::PipeStream;
use slog::Logger;
@ -178,6 +178,13 @@ async fn run_in_parent<T: AsyncRead + AsyncWrite>(
);
}
res = tokio::io::copy(&mut socket_reader, &mut master_writer) => {
// the shell run in child may not be exited, in some scenes
// eg. directly Ctrl-C in the host to terminate the kata-runtime process
// that will block this taskwhile waiting for the child to exit.
//
let _ = signal::kill(child_pid, Some(signal::Signal::SIGKILL))
.map_err(|e| warn!(logger, "kill child shell process {:?}", e));
info!(
logger,
"socket closed: {:?}", res