From 295d7dd0c58ce34d467375702a633d3b61293d18 Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Tue, 3 Dec 2024 20:47:56 +1100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9E=95=20Add=20"fastrand"=20crate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 5 +++-- Cargo.toml | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1eb22b4..2616f45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,6 +195,7 @@ dependencies = [ "console-subscriber", "enumflags2", "event-listener", + "fastrand", "futures-util", "nix", "ntest", @@ -422,9 +423,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "flate2" diff --git a/Cargo.toml b/Cargo.toml index 24a3ce9..ca5bf6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ enumflags2 = "0.7.9" console-subscriber = { version = "0.4.0", optional = true } xdg-home = "1.1.0" event-listener = "5.3.0" +fastrand = "2.2.0" [target.'cfg(unix)'.dependencies] nix = { version = "0.29.0", features = ["user"] } From 8d67580cc2bb8a87f57d4a8bdfc2069b0707e3bb Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Tue, 3 Dec 2024 21:06:51 +1100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20Implement=20unix:dir=20and=20un?= =?UTF-8?q?ix:tmpdir=20for=20`--address`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to https://dbus.freedesktop.org/doc/dbus-specification.html , for unix:tmpdir, the service _may_ create an abstract socket, but is not required to do so, thus our implementation is the same as our unix:dir, as suggested by the specification --- src/bus/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index 1ca1c80..b8f6280 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -164,8 +164,16 @@ impl Bus { addr } - UnixSocket::Dir(_) => bail!("`dir` transport is not supported (yet)."), - UnixSocket::TmpDir(_) => bail!("`tmpdir` transport is not supported (yet)."), + UnixSocket::Dir(dir) | UnixSocket::TmpDir(dir) => { + let path = dir.join(format!("dbus-{}", fastrand::u32(1_000_000..u32::MAX))); + let addr = SocketAddr::from_pathname(&path)?; + info!( + "Listening on UNIX socket file `{}`.", + path.to_string_lossy() + ); + + addr + } _ => bail!("Unsupported address."), }; let std_listener = From 1bf7912b8c56c0f26eca96b61d14181ebef40628 Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Sat, 7 Dec 2024 11:08:46 +1100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A7=20Change=20the=20default=20add?= =?UTF-8?q?ress=20to=20listen=20upon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For UNIX systems, the default is now $XDG_RUNTIME_DIR/dbus-$RANDOM --- src/bus/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index b8f6280..fc686dd 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -258,9 +258,8 @@ fn default_address() -> String { .join("user") .join(format!("{}", nix::unistd::Uid::current())) }); - let path = runtime_dir.join("busd-session"); - format!("unix:path={}", path.display()) + format!("unix:dir={}", runtime_dir.display()) } #[cfg(not(unix))]