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

Merge pull request #2646 from 353fc443/uresult-uptime

uptime: added UResult
This commit is contained in:
Michael Debertol 2021-09-09 20:32:06 +02:00 committed by GitHub
commit 37c6b794c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,8 @@ extern crate uucore;
pub use uucore::libc;
use uucore::libc::time_t;
use uucore::error::{UResult, USimpleError};
static ABOUT: &str = "Display the current time, the length of time the system has been up,\n\
the number of users on the system, and the average number of jobs\n\
in the run queue over the last 1, 5 and 15 minutes.";
@ -36,21 +38,20 @@ fn usage() -> String {
format!("{0} [OPTION]...", uucore::execution_phrase())
}
pub fn uumain(args: impl uucore::Args) -> i32 {
#[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
let (boot_time, user_count) = process_utmpx();
let uptime = get_uptime(boot_time);
if uptime < 0 {
show_error!("could not retrieve system uptime");
1
Err(USimpleError::new(1, "could not retrieve system uptime"))
} else {
if matches.is_present(options::SINCE) {
let initial_date = Local.timestamp(Utc::now().timestamp() - uptime, 0);
println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S"));
return 0;
return Ok(());
}
print_time();
@ -59,7 +60,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
print_nusers(user_count);
print_loadavg();
0
Ok(())
}
}