From 5903815746d304d360129890961d07c1b0fc6ce1 Mon Sep 17 00:00:00 2001 From: Manabu Sugimoto Date: Fri, 27 May 2022 15:50:02 +0900 Subject: [PATCH] agent: Pass standard I/O to container launched by runk The `kata-agent` passes its standard I/O file descriptors through to the container process that will be launched by `runk` without manipulation or modification in order to allow the container process can handle its I/O operations. Fixes: #4327 Signed-off-by: Manabu Sugimoto --- src/agent/rustjail/src/process.rs | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/agent/rustjail/src/process.rs b/src/agent/rustjail/src/process.rs index cced9b98f3..d94b595cc1 100644 --- a/src/agent/rustjail/src/process.rs +++ b/src/agent/rustjail/src/process.rs @@ -5,7 +5,7 @@ use libc::pid_t; use std::fs::File; -use std::os::unix::io::RawFd; +use std::os::unix::io::{AsRawFd, RawFd}; use tokio::sync::mpsc::Sender; use nix::errno::Errno; @@ -137,19 +137,25 @@ impl Process { info!(logger, "before create console socket!"); if !p.tty { - info!(logger, "created console socket!"); + if cfg!(feature = "standard-oci-runtime") { + p.stdin = Some(std::io::stdin().as_raw_fd()); + p.stdout = Some(std::io::stdout().as_raw_fd()); + p.stderr = Some(std::io::stderr().as_raw_fd()); + } else { + info!(logger, "created console socket!"); - let (stdin, pstdin) = unistd::pipe2(OFlag::O_CLOEXEC)?; - p.parent_stdin = Some(pstdin); - p.stdin = Some(stdin); + let (stdin, pstdin) = unistd::pipe2(OFlag::O_CLOEXEC)?; + p.parent_stdin = Some(pstdin); + p.stdin = Some(stdin); - let (pstdout, stdout) = create_extended_pipe(OFlag::O_CLOEXEC, pipe_size)?; - p.parent_stdout = Some(pstdout); - p.stdout = Some(stdout); + let (pstdout, stdout) = create_extended_pipe(OFlag::O_CLOEXEC, pipe_size)?; + p.parent_stdout = Some(pstdout); + p.stdout = Some(stdout); - let (pstderr, stderr) = create_extended_pipe(OFlag::O_CLOEXEC, pipe_size)?; - p.parent_stderr = Some(pstderr); - p.stderr = Some(stderr); + let (pstderr, stderr) = create_extended_pipe(OFlag::O_CLOEXEC, pipe_size)?; + p.parent_stderr = Some(pstderr); + p.stderr = Some(stderr); + } } Ok(p) } @@ -284,5 +290,11 @@ mod tests { // group of the calling process. process.pid = 0; assert!(process.signal(libc::SIGCONT).is_ok()); + + if cfg!(feature = "standard-oci-runtime") { + assert_eq!(process.stdin.unwrap(), std::io::stdin().as_raw_fd()); + assert_eq!(process.stdout.unwrap(), std::io::stdout().as_raw_fd()); + assert_eq!(process.stderr.unwrap(), std::io::stderr().as_raw_fd()); + } } }