Skip to content

Commit

Permalink
Merge pull request #13 from matttbe/vsock
Browse files Browse the repository at this point in the history
vsock: socat service for remote console
  • Loading branch information
arighi authored Nov 29, 2024
2 parents f9d3c4a + bd01c91 commit c43ba1c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,28 @@ fn run_snapd() {
}
}

fn extract_vsock_exec(cmdline: &str) -> Option<String> {
let start_marker = "virtme.vsockexec=`";
let end_marker = '`';

let (_before, remaining) = cmdline.split_once(start_marker)?;
let (encoded_cmd, _after) = remaining.split_once(end_marker)?;
Some(encoded_cmd.to_string())
}

fn setup_socat_console() {
if let Ok(cmdline) = std::fs::read_to_string("/proc/cmdline") {
if let Some(exec) = extract_vsock_exec(&cmdline) {
thread::spawn(move || {
let from = "VSOCK-LISTEN:1024,reuseaddr,fork";
let to = format!("EXEC:\"{}\",pty,stderr,setsid,sigint,sane,echo=0", exec);
let args = vec![from, &to];
utils::run_cmd("socat", &args);
});
}
}
}

fn run_misc_services() -> thread::JoinHandle<()> {
thread::spawn(|| {
symlink_fds();
Expand Down Expand Up @@ -1061,6 +1083,9 @@ fn main() {
mount_kernel_modules();
run_systemd_tmpfiles();

// Service running in the background for later
setup_socat_console();

// Service initialization (some services can be parallelized here).
let mut handles = vec![run_udevd(), Some(run_misc_services())];
handles.append(&mut setup_network());
Expand Down

0 comments on commit c43ba1c

Please sign in to comment.