mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
Merge pull request #2743 from thomasqueirozb/who_uresult
who: use UResult
This commit is contained in:
commit
b4416abc82
2 changed files with 31 additions and 20 deletions
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) ttyname hostnames runlevel mesg wtmp statted boottime deadprocs initspawn clockchange curr runlvline pidstr exitstr hoststr
|
// spell-checker:ignore (ToDO) ttyname hostnames runlevel mesg wtmp statted boottime deadprocs initspawn clockchange curr runlvline pidstr exitstr hoststr
|
||||||
|
|
||||||
#[macro_use]
|
use uucore::display::Quotable;
|
||||||
extern crate uucore;
|
use uucore::error::{FromIo, UResult};
|
||||||
use uucore::libc::{ttyname, STDIN_FILENO, S_IWGRP};
|
use uucore::libc::{ttyname, STDIN_FILENO, S_IWGRP};
|
||||||
use uucore::utmpx::{self, time, Utmpx};
|
use uucore::utmpx::{self, time, Utmpx};
|
||||||
|
|
||||||
|
@ -59,7 +59,8 @@ fn get_long_usage() -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let args = args
|
let args = args
|
||||||
.collect_str(InvalidEncodingHandling::Ignore)
|
.collect_str(InvalidEncodingHandling::Ignore)
|
||||||
.accept_any();
|
.accept_any();
|
||||||
|
@ -157,9 +158,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
args: files,
|
args: files,
|
||||||
};
|
};
|
||||||
|
|
||||||
who.exec();
|
who.exec()
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
pub fn uu_app() -> App<'static, 'static> {
|
||||||
|
@ -326,7 +325,7 @@ fn current_tty() -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Who {
|
impl Who {
|
||||||
fn exec(&mut self) {
|
fn exec(&mut self) -> UResult<()> {
|
||||||
let run_level_chk = |_record: i16| {
|
let run_level_chk = |_record: i16| {
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
return false;
|
return false;
|
||||||
|
@ -362,7 +361,7 @@ impl Who {
|
||||||
for ut in records {
|
for ut in records {
|
||||||
if !self.my_line_only || cur_tty == ut.tty_device() {
|
if !self.my_line_only || cur_tty == ut.tty_device() {
|
||||||
if self.need_users && ut.is_user_process() {
|
if self.need_users && ut.is_user_process() {
|
||||||
self.print_user(&ut);
|
self.print_user(&ut)?;
|
||||||
} else if self.need_runlevel && run_level_chk(ut.record_type()) {
|
} else if self.need_runlevel && run_level_chk(ut.record_type()) {
|
||||||
if cfg!(target_os = "linux") {
|
if cfg!(target_os = "linux") {
|
||||||
self.print_runlevel(&ut);
|
self.print_runlevel(&ut);
|
||||||
|
@ -383,6 +382,7 @@ impl Who {
|
||||||
if ut.record_type() == utmpx::BOOT_TIME {}
|
if ut.record_type() == utmpx::BOOT_TIME {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -464,7 +464,7 @@ impl Who {
|
||||||
self.print_line("", ' ', "system boot", &time_string(ut), "", "", "", "");
|
self.print_line("", ' ', "system boot", &time_string(ut), "", "", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_user(&self, ut: &Utmpx) {
|
fn print_user(&self, ut: &Utmpx) -> UResult<()> {
|
||||||
let mut p = PathBuf::from("/dev");
|
let mut p = PathBuf::from("/dev");
|
||||||
p.push(ut.tty_device().as_str());
|
p.push(ut.tty_device().as_str());
|
||||||
let mesg;
|
let mesg;
|
||||||
|
@ -491,7 +491,13 @@ impl Who {
|
||||||
};
|
};
|
||||||
|
|
||||||
let s = if self.do_lookup {
|
let s = if self.do_lookup {
|
||||||
crash_if_err!(1, ut.canon_host())
|
ut.canon_host().map_err_context(|| {
|
||||||
|
let host = ut.host();
|
||||||
|
format!(
|
||||||
|
"failed to canonicalize {}",
|
||||||
|
host.split(':').next().unwrap_or(&host).quote()
|
||||||
|
)
|
||||||
|
})?
|
||||||
} else {
|
} else {
|
||||||
ut.host()
|
ut.host()
|
||||||
};
|
};
|
||||||
|
@ -507,6 +513,8 @@ impl Who {
|
||||||
hoststr.as_str(),
|
hoststr.as_str(),
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue