Add bus method to spawn an external client

This commit is contained in:
Val Packett 2025-07-17 21:37:42 -03:00
parent 71aecea297
commit 30e76e3291

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use tokio_stream::StreamExt as _;
use tracing::trace;
use tracing::{debug, trace};
pub struct HostedBus {
peers: Arc<busd::peers::Peers>,
@ -78,6 +78,10 @@ impl HostedBus {
pub trait SharedHostedBus {
async fn run_unix_listener(self, listener: tokio::net::UnixListener);
async fn spawn_external_client(
self,
command: &mut tokio::process::Command,
) -> eyre::Result<tokio::process::Child>;
}
impl SharedHostedBus for Arc<tokio::sync::Mutex<HostedBus>> {
@ -86,6 +90,24 @@ impl SharedHostedBus for Arc<tokio::sync::Mutex<HostedBus>> {
self.lock().await.connect_unix(socket).await.unwrap()
}
}
async fn spawn_external_client(
self,
command: &mut tokio::process::Command,
) -> eyre::Result<tokio::process::Child> {
// NOTE: abstract sockets belong to the *network* namespace
// Possibly better to only accept once and let go of the listener / use socketpair & /dev/fd? (Uncommon to reconnect?)
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));
Ok(command
.env(
"DBUS_SESSION_BUS_ADDRESS",
format!("unix:abstract={abstract_path}"),
)
.spawn()?)
}
}
pub struct NameOwnerStream {