Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions rs/ic_os/vsock/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#![cfg(target_os = "linux")]

use clap::{Args, Parser};
use std::fs::OpenOptions;
use std::io::Write;
use vsock_lib::protocol::{Command, NotifyData, Payload, UpgradeData};
use vsock_lib::{LinuxVSockClient, VSockClient};

fn main() -> Result<(), String> {
let cli = Cli::parse();

let port = cli.port;
let command = get_command(cli)?;

// Echo notify messages to the local GuestOS console so they are visible
// in cloud environments where the host console is not accessible.
if let Command::Notify(NotifyData { ref message, .. }) = command {
write_to_guest_console(message);
}

let payload = LinuxVSockClient::with_port(port).send_command(command)?;

// Output the values directly
Expand All @@ -20,6 +30,14 @@ fn main() -> Result<(), String> {
Ok(())
}

fn write_to_guest_console(message: &str) {
for path in ["/dev/tty1", "/dev/ttyS0"] {
if let Ok(mut tty) = OpenOptions::new().write(true).open(path) {
let _ = writeln!(tty, "\n{message}");
}
}
}

#[derive(Debug, Parser)]
#[clap(
version = "1.0.0",
Expand Down
Loading