Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsock: socat service for remote console #13

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
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