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 <Manabu.Sugimoto@sony.com>
This commit is contained in:
Manabu Sugimoto 2022-05-27 15:50:02 +09:00
parent 9658c6218e
commit 5903815746

View File

@ -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,6 +137,11 @@ impl Process {
info!(logger, "before create console socket!");
if !p.tty {
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)?;
@ -151,6 +156,7 @@ impl Process {
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());
}
}
}