Add bus method to spawn an external client
This commit is contained in:
parent
71aecea297
commit
30e76e3291
1 changed files with 23 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio_stream::StreamExt as _;
|
use tokio_stream::StreamExt as _;
|
||||||
use tracing::trace;
|
use tracing::{debug, trace};
|
||||||
|
|
||||||
pub struct HostedBus {
|
pub struct HostedBus {
|
||||||
peers: Arc<busd::peers::Peers>,
|
peers: Arc<busd::peers::Peers>,
|
||||||
|
|
@ -78,6 +78,10 @@ impl HostedBus {
|
||||||
|
|
||||||
pub trait SharedHostedBus {
|
pub trait SharedHostedBus {
|
||||||
async fn run_unix_listener(self, listener: tokio::net::UnixListener);
|
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>> {
|
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()
|
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 {
|
pub struct NameOwnerStream {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue