Navigation Menu

Skip to content

Commit

Permalink
Avoid crashing when Avahi is not available
Browse files Browse the repository at this point in the history
When librespot is built with Avahi turned on, it will crash if Avahi is
later not available at runtime.

This change avoids it crashing hard when Avahi is not available;
librespot will merely warn of the issue.

This affects some distribution packages too, where the maintainer might
prefer leaving Avahi support enabled, but many setups don't (or can't)
run Avahi.

Co-authored-by: Nick Steel <nick@nsteel.co.uk>
  • Loading branch information
WhyNotHugo and kingosticks committed May 20, 2022
1 parent 7efc62b commit c4af90f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [playback] Adhere to ReplayGain spec when calculating gain normalisation factor.
- [playback] `alsa`: Use `--volume-range` overrides for softvol controls
- [connect] Don't panic when activating shuffle without previous interaction.
- [main] Fix crash when built with Avahi support but Avahi is locally unavailable.

### Removed
- [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed.
Expand Down
3 changes: 1 addition & 2 deletions discovery/src/lib.rs
Expand Up @@ -111,8 +111,7 @@ impl Builder {
None,
port,
&["VERSION=1.0", "CPath=/"],
)
.unwrap();
).map_err(|e| Error::DnsSdError(io::Error::new(io::ErrorKind::Unsupported, e)))?;

} else {
let responder = libmdns::Responder::spawn(&tokio::runtime::Handle::current())?;
Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Expand Up @@ -1581,19 +1581,15 @@ async fn main() {

if setup.enable_discovery {
let device_id = setup.session_config.device_id.clone();

discovery = match librespot::discovery::Discovery::builder(device_id)
match librespot::discovery::Discovery::builder(device_id)
.name(setup.connect_config.name.clone())
.device_type(setup.connect_config.device_type)
.port(setup.zeroconf_port)
.launch()
{
Ok(d) => Some(d),
Err(e) => {
error!("Discovery Error: {}", e);
exit(1);
}
}
Ok(d) => discovery = Some(d),
Err(err) => warn!("Could not initialise discovery: {}.", err),
};
}

if let Some(credentials) = setup.credentials {
Expand All @@ -1606,6 +1602,11 @@ async fn main() {
)
.fuse(),
);
} else if discovery.is_none() {
error!(
"Discovery is unavailable and no credentials provided. Authentication is not possible."
);
exit(1);
}

loop {
Expand Down

0 comments on commit c4af90f

Please sign in to comment.