From 0e6497ac11314d42aaf4d50dd248999a7590abf3 Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Sat, 14 Dec 2024 17:11:07 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Expose=20the=20socket=20address?= =?UTF-8?q?=20clients=20can=20use?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now, `--print-address` would print the address specification, that is, the input used to determine how and where the server would listen. This would be useful for clients for `unix:path=...`, but for `unix:dir=...` and `unix:tmpdir=...` this would not work. So now we share the socket address that is produced from the address specification. --- src/bus/mod.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index 82c429b..d5ea438 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -46,21 +46,20 @@ enum Listener { impl Bus { pub async fn for_address(address: &str) -> Result { let mut address = Address::from_str(address)?; - let guid: OwnedGuid = match address.guid() { - Some(guid) => guid.to_owned().into(), - None => { - let guid = Guid::generate(); - address = address.set_guid(guid.clone())?; - guid.into() - } - }; let (listener, auth_mechanism) = match address.transport() { #[cfg(unix)] Transport::Unix(unix) => { + // resolve address specification into address that clients can use let addr = Self::unix_addr(unix)?; - - (Self::unix_stream(addr).await?, AuthMechanism::External) + address = Address::try_from( + format!("unix:path={}", addr.as_pathname().unwrap().display()).as_str(), + )?; + + ( + Self::unix_stream(addr.clone()).await?, + AuthMechanism::External, + ) } Transport::Tcp(tcp) => { #[cfg(not(windows))] @@ -75,6 +74,16 @@ impl Bus { _ => bail!("Unsupported address `{}`.", address), }; + let guid: OwnedGuid = match address.guid() { + Some(guid) => guid.to_owned().into(), + None => { + let guid = Guid::generate(); + address = address.set_guid(guid.clone())?; + + guid.into() + } + }; + let peers = Peers::new(); let dbus = DBus::new(peers.clone(), guid.clone());