Skip to content
Closed
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
19 changes: 19 additions & 0 deletions crates/krun/src/bin/krun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ fn main() -> Result<()> {
return Err(err).context("Failed to configure vsock for pulse socket");
}
}

let socket_dir = Path::new(&run_path).join("krun/socket");
std::fs::create_dir_all(&socket_dir)?;
// Dynamic ports: Applications may listen on these sockets as neeeded.
for port in 50000..50200 {
let socket_path = socket_dir.join(format!("port-{}", port));
let socket_path = CString::new(
socket_path
.to_str()
.expect("socket_path should not contain invalid UTF-8"),
)
.context("Failed to process dynamic socket path as it contains NUL character")?;
// SAFETY: `socket_path` is a pointer to a `CString` with long enough lifetime.
let err = unsafe { krun_add_vsock_port(ctx_id, port, socket_path.as_ptr()) };
if err < 0 {
let err = Errno::from_raw_os_error(-err);
return Err(err).context("Failed to configure vsock for dynamic socket");
}
}
}

let username = env::var("USER").context("Failed to get username from environment")?;
Expand Down