Skip to content

Commit

Permalink
agent: Pass standard I/O to container launched by runk
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ManaSugi committed Jun 1, 2022
1 parent 9658c62 commit 5903815
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/agent/rustjail/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,19 +137,25 @@ impl Process {
info!(logger, "before create console socket!");

if !p.tty {
info!(logger, "created console socket!");

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 (pstderr, stderr) = create_extended_pipe(OFlag::O_CLOEXEC, pipe_size)?;
p.parent_stderr = Some(pstderr);
p.stderr = Some(stderr);
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 (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);
}
}
Ok(p)
}
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit 5903815

Please sign in to comment.