Skip to content

Commit c4af90f

Browse files
Hugo Osvaldo Barrerakingosticks
andcommitted
Avoid crashing when Avahi is not available
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 <[email protected]>
1 parent 7efc62b commit c4af90f

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- [playback] Adhere to ReplayGain spec when calculating gain normalisation factor.
3636
- [playback] `alsa`: Use `--volume-range` overrides for softvol controls
3737
- [connect] Don't panic when activating shuffle without previous interaction.
38+
- [main] Fix crash when built with Avahi support but Avahi is locally unavailable.
3839

3940
### Removed
4041
- [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed.

discovery/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl Builder {
111111
None,
112112
port,
113113
&["VERSION=1.0", "CPath=/"],
114-
)
115-
.unwrap();
114+
).map_err(|e| Error::DnsSdError(io::Error::new(io::ErrorKind::Unsupported, e)))?;
116115

117116
} else {
118117
let responder = libmdns::Responder::spawn(&tokio::runtime::Handle::current())?;

src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,19 +1581,15 @@ async fn main() {
15811581

15821582
if setup.enable_discovery {
15831583
let device_id = setup.session_config.device_id.clone();
1584-
1585-
discovery = match librespot::discovery::Discovery::builder(device_id)
1584+
match librespot::discovery::Discovery::builder(device_id)
15861585
.name(setup.connect_config.name.clone())
15871586
.device_type(setup.connect_config.device_type)
15881587
.port(setup.zeroconf_port)
15891588
.launch()
15901589
{
1591-
Ok(d) => Some(d),
1592-
Err(e) => {
1593-
error!("Discovery Error: {}", e);
1594-
exit(1);
1595-
}
1596-
}
1590+
Ok(d) => discovery = Some(d),
1591+
Err(err) => warn!("Could not initialise discovery: {}.", err),
1592+
};
15971593
}
15981594

15991595
if let Some(credentials) = setup.credentials {
@@ -1606,6 +1602,11 @@ async fn main() {
16061602
)
16071603
.fuse(),
16081604
);
1605+
} else if discovery.is_none() {
1606+
error!(
1607+
"Discovery is unavailable and no credentials provided. Authentication is not possible."
1608+
);
1609+
exit(1);
16091610
}
16101611

16111612
loop {

0 commit comments

Comments
 (0)