mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-01 07:47:15 +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:
parent
43dca8deb4
commit
722b576eb3
@ -11,7 +11,7 @@ use nix::libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
|
|||||||
use nix::pty::{openpty, OpenptyResult};
|
use nix::pty::{openpty, OpenptyResult};
|
||||||
use nix::sys::socket::{self, AddressFamily, SockFlag, SockType, VsockAddr};
|
use nix::sys::socket::{self, AddressFamily, SockFlag, SockType, VsockAddr};
|
||||||
use nix::sys::stat::Mode;
|
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 nix::unistd::{self, close, dup2, fork, setsid, ForkResult, Pid};
|
||||||
use rustjail::pipestream::PipeStream;
|
use rustjail::pipestream::PipeStream;
|
||||||
use slog::Logger;
|
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) => {
|
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 task,while 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!(
|
info!(
|
||||||
logger,
|
logger,
|
||||||
"socket closed: {:?}", res
|
"socket closed: {:?}", res
|
||||||
|
Loading…
Reference in New Issue
Block a user