From 30e76e32912eed0113781054d51b8cd52e3516d7 Mon Sep 17 00:00:00 2001 From: Val Packett Date: Thu, 17 Jul 2025 21:37:42 -0300 Subject: [PATCH] Add bus method to spawn an external client --- sidebus-broker/src/bus.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/sidebus-broker/src/bus.rs b/sidebus-broker/src/bus.rs index 4b37ccc..4607379 100644 --- a/sidebus-broker/src/bus.rs +++ b/sidebus-broker/src/bus.rs @@ -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, @@ -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; } impl SharedHostedBus for Arc> { @@ -86,6 +90,24 @@ impl SharedHostedBus for Arc> { self.lock().await.connect_unix(socket).await.unwrap() } } + + async fn spawn_external_client( + self, + command: &mut tokio::process::Command, + ) -> eyre::Result { + // 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 {