1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 14:07:46 +00:00

uucore/utmpx: remove unwrap in cannon_host

Default to hostname if getaddrinfo fails
This commit is contained in:
Thomas Queiroz 2021-11-09 19:57:24 -03:00
parent 2e12316ae1
commit 235152a6b7
No known key found for this signature in database
GPG key ID: 229D2DDF7ECA5F8F

View file

@ -236,17 +236,20 @@ impl Utmpx {
flags: AI_CANONNAME, flags: AI_CANONNAME,
..AddrInfoHints::default() ..AddrInfoHints::default()
}; };
let sockets = getaddrinfo(Some(hostname), None, Some(hints)) if let Ok(sockets) = getaddrinfo(Some(hostname), None, Some(hints)) {
.unwrap() let sockets = sockets.collect::<IOResult<Vec<_>>>()?;
.collect::<IOResult<Vec<_>>>()?; for socket in sockets {
for socket in sockets { if let Some(ai_canonname) = socket.canonname {
if let Some(ai_canonname) = socket.canonname { return Ok(if display.is_empty() {
return Ok(if display.is_empty() { ai_canonname
ai_canonname } else {
} else { format!("{}:{}", ai_canonname, display)
format!("{}:{}", ai_canonname, display) });
}); }
} }
} else {
// GNU coreutils has this behavior
return Ok(hostname.to_string());
} }
} }