Add option to expose a (non-fd-capable) unix socket instead of vsock

libkrun does not use vsock on the host, so we need to provide this to
work with muvm.
This commit is contained in:
Val Packett 2025-10-03 05:13:38 -03:00
parent 250c459866
commit 4fd76692db
2 changed files with 93 additions and 32 deletions

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use std::{hash::DefaultHasher, sync::Arc};
use tokio_stream::StreamExt as _;
use tracing::{debug, trace};
use tracing::{debug, error, trace};
pub struct HostedBus {
peers: Arc<busd::peers::Peers>,
@ -57,10 +57,14 @@ impl HostedBus {
.map_err(|err| eyre::eyre!(Box::new(err))) // https://github.com/eyre-rs/eyre/issues/31 XXX: busd should not use anyhow!
}
pub async fn connect_unix(&mut self, socket: tokio::net::UnixStream) -> eyre::Result<()> {
pub async fn connect_unix(
&mut self,
socket: tokio::net::UnixStream,
auth: zbus::AuthMechanism,
) -> eyre::Result<()> {
let id = self.next_id();
self.peers
.add(&self.guid, id, socket.into(), zbus::AuthMechanism::External)
.add(&self.guid, id, socket.into(), auth)
.await
.map_err(|err| eyre::eyre!(Box::new(err)))
}
@ -77,7 +81,7 @@ impl HostedBus {
}
pub trait SharedHostedBus {
async fn run_unix_listener(self, listener: tokio::net::UnixListener);
async fn run_unix_listener(self, listener: tokio::net::UnixListener, auth: zbus::AuthMechanism);
async fn spawn_external_client(
self,
command: &mut tokio::process::Command,
@ -85,9 +89,15 @@ pub trait SharedHostedBus {
}
impl SharedHostedBus for Arc<tokio::sync::Mutex<HostedBus>> {
async fn run_unix_listener(self, listener: tokio::net::UnixListener) {
async fn run_unix_listener(
self,
listener: tokio::net::UnixListener,
auth: zbus::AuthMechanism,
) {
while let Ok((socket, _remote_addr)) = listener.accept().await {
self.lock().await.connect_unix(socket).await.unwrap()
if let Err(e) = self.lock().await.connect_unix(socket, auth).await {
error!("unix connection: {:?}", e);
}
}
}
@ -100,7 +110,7 @@ impl SharedHostedBus for Arc<tokio::sync::Mutex<HostedBus>> {
let abstract_path = format!("/run/sidebus-broker/{}", zbus::Guid::generate());
let listener = tokio::net::UnixListener::bind(format!("\0{abstract_path}"))?;
debug!(%abstract_path, "opened listener for external client");
tokio::spawn(self.run_unix_listener(listener));
tokio::spawn(self.run_unix_listener(listener, zbus::AuthMechanism::External));
Ok(command
.env(
"DBUS_SESSION_BUS_ADDRESS",