Skip to content

Commit

Permalink
task: ipmlement close_io
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang Tianyang <[email protected]>
  • Loading branch information
Burning1020 committed Jan 24, 2024
1 parent 942c49d commit 4d237e2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
8 changes: 4 additions & 4 deletions vmm/sandbox/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vmm/task/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vmm/task/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ impl ProcessFactory<ExecProcess> for KuasarExecFactory {
spec: p,
exit_signal: Default::default(),
}),
stdin: Arc::new(Mutex::new(None)),
})
}
}
Expand Down
17 changes: 15 additions & 2 deletions vmm/task/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub(crate) async fn copy_io_or_console<P>(
) -> Result<()> {
if p.stdio.terminal {
if let Some(console_socket) = socket {
let console_result = copy_console(&console_socket, &p.stdio, exit_signal).await;
let console_result = copy_console(p, &console_socket, &p.stdio, exit_signal).await;
console_socket.clean().await;
match console_result {
Ok(c) => {
Expand All @@ -144,7 +144,8 @@ pub(crate) async fn copy_io_or_console<P>(
Ok(())
}

async fn copy_console(
async fn copy_console<P>(
p: &ProcessTemplate<P>,
console_socket: &ConsoleSocket,
stdio: &Stdio,
exit_signal: Arc<ExitSignal>,
Expand All @@ -155,6 +156,18 @@ async fn copy_console(
let f = unsafe { File::from_raw_fd(fd) };
if !stdio.stdin.is_empty() {
debug!("copy_console: pipe stdin to console");

let stdin_clone = stdio.stdin.clone();
let stdin_w = p.stdin.clone();
// open the write side to make sure read side unblock, as open write side
// will block too, open it in another thread
tokio::spawn(async move {
if let Ok(stdin_file) = OpenOptions::new().write(true).open(stdin_clone).await {
let mut lock_guard = stdin_w.lock().await;
*lock_guard = Some(stdin_file);
}
});

let console_stdin = f
.try_clone()
.await
Expand Down

0 comments on commit 4d237e2

Please sign in to comment.