diff --git a/Cargo.lock b/Cargo.lock index d3f9164..8280520 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"] } diff --git a/src/bus/mod.rs b/src/bus/mod.rs index 1ca1c80..fc686dd 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 = @@ -250,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))]