diff --git a/src/bin/busd.rs b/src/bin/busd.rs index 85a0828..3ef4320 100644 --- a/src/bin/busd.rs +++ b/src/bin/busd.rs @@ -75,7 +75,7 @@ async fn main() -> Result<()> { Err(err) => { if args.config.is_some() || args.session || args.system { // User expected us to read a specific XML file. - error!("Cannot read {}: {} ", config_path.display(), err); + error!("Cannot read {} ", config_path.display()); return Err(err); } else { // No explicit indications from user. Fallback to default. @@ -88,7 +88,7 @@ async fn main() -> Result<()> { let address = if let Some(address) = args.address { Some(address) } else { - config.listen.map(|address| format!("{address}")) + config.listen }; let mut bus = bus::Bus::for_address(address.as_deref()).await?; diff --git a/src/config/mod.rs b/src/config/mod.rs index 60f713e..2c574ff 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -7,7 +7,7 @@ use std::{ use anyhow::{Error, Result}; use policy::OptionalPolicy; use serde::Deserialize; -use zbus::{Address, AuthMechanism}; +use zbus::AuthMechanism; pub mod policy; pub mod rule; @@ -50,9 +50,9 @@ pub struct Config { /// The address is in the standard D-Bus format that contains a transport name plus possible /// parameters/options. // TODO: warn when multiple `` elements are defined, as we only support one - // TODO: consider implementing `Deserialize` over in zbus crate, then removing this "skip..." - #[serde(default, skip_deserializing)] - pub listen: Option
, + // NOTE: we're using `String` here as we parse into a `zbus::Address` later + #[serde(default)] + pub listen: Option, /// The bus daemon will write its pid to the specified file. pub pidfile: Option, @@ -105,7 +105,7 @@ impl TryFrom for Config { // NO-OP: deprecated and ignored } Element::Listen(listen) => { - config.listen = Some(Address::from_str(&listen)?); + config.listen = Some(listen); } Element::Pidfile(p) => config.pidfile = Some(p), Element::Policy(pe) => { @@ -322,10 +322,7 @@ mod tests { assert_eq!( config, Config { - listen: Some( - Address::from_str("tcp:host=localhost,port=0,family=ipv4") - .expect("should parse address") - ), + listen: Some(String::from("tcp:host=localhost,port=0,family=ipv4")), ..Default::default() } ); @@ -361,10 +358,7 @@ mod tests { config, Config { auth: Some(AuthMechanism::External), - listen: Some( - Address::from_str("tcp:host=localhost,port=1234") - .expect("should parse address") - ), + listen: Some(String::from("tcp:host=localhost,port=1234")), policies: vec![ Policy::DefaultContext(vec![ ( diff --git a/tests/config.rs b/tests/config.rs index eb336c2..cd72a34 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -1,10 +1,10 @@ -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; use busd::config::{ Access, BusType, Config, ConnectOperation, MessageType, Name, NameOwnership, Operation, Policy, ReceiveOperation, SendOperation, }; -use zbus::{Address, AuthMechanism}; +use zbus::AuthMechanism; #[test] fn config_read_file_with_includes_ok() { @@ -15,7 +15,7 @@ fn config_read_file_with_includes_ok() { got, Config { auth: Some(AuthMechanism::External), - listen: Some(Address::from_str("unix:path=/tmp/a").expect("should parse address")), + listen: Some(String::from("unix:path=/tmp/a")), policies: vec![ Policy::DefaultContext(vec![ ( @@ -121,9 +121,7 @@ fn config_read_file_session_conf_ok() { assert_eq!( got, Config { - listen: Some( - Address::from_str("unix:path=/run/user/1000/bus").expect("should parse address") - ), + listen: Some(String::from("unix:path=/run/user/1000/bus")), keep_umask: true, policies: vec![Policy::DefaultContext(vec![ ( @@ -158,10 +156,7 @@ fn config_read_file_system_conf_ok() { let want = Config { auth: Some(AuthMechanism::External), fork: true, - listen: Some( - Address::from_str("unix:path=/var/run/dbus/system_bus_socket") - .expect("should parse address"), - ), + listen: Some(String::from("unix:path=/var/run/dbus/system_bus_socket")), pidfile: Some(PathBuf::from("@DBUS_SYSTEM_PID_FILE@")), policies: vec![ Policy::DefaultContext(vec![