uucore/utmpx: remove unwrap in cannon_host
Default to hostname if getaddrinfo fails
@@ -236,9 +236,8 @@ impl Utmpx {
flags: AI_CANONNAME,
..AddrInfoHints::default()
};
- let sockets = getaddrinfo(Some(hostname), None, Some(hints))
- .unwrap()
- .collect::<IOResult<Vec<_>>>()?;
+ if let Ok(sockets) = getaddrinfo(Some(hostname), None, Some(hints)) {
+ let sockets = sockets.collect::<IOResult<Vec<_>>>()?;
for socket in sockets {
if let Some(ai_canonname) = socket.canonname {
return Ok(if display.is_empty() {
@@ -248,6 +247,10 @@ impl Utmpx {
});
}
}
+ } else {
+ // GNU coreutils has this behavior
+ return Ok(hostname.to_string());
+ }
}
Ok(host.to_string())
