Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ rstest_reuse = "0.7.0"
rustc-hash = "2.1.1"
rust-ini = "0.21.0"
# raw-backend's linux_execfn is not supported on linux < 6.4 if /proc is not mounted. So use-libc-auxv is needed
rustix = { version = "1.1.4", features = ["param", "use-libc-auxv"] }
rustix = { version = "1.1.4", features = ["param", "use-libc-auxv", "time"] }
same-file = "1.0.6"
self_cell = "1.0.4"
selinux = "0.6"
Expand Down
26 changes: 4 additions & 22 deletions src/uucore/src/lib/features/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,13 @@ fn get_macos_boot_time_sysctl() -> Option<time_t> {
///
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
#[cfg(target_os = "openbsd")]
#[allow(clippy::unnecessary_wraps, reason = "needed on some platforms")]
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
use libc::CLOCK_BOOTTIME;
use libc::clock_gettime;

use libc::c_int;
use libc::timespec;
use rustix::time::{ClockId, clock_gettime};

let mut tp: timespec = timespec {
tv_sec: 0,
tv_nsec: 0,
};
let tp = clock_gettime(ClockId::Boottime);

// OpenBSD prototype: clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
let ret: c_int = unsafe { clock_gettime(CLOCK_BOOTTIME, &raw mut tp) };

if ret == 0 {
#[cfg(target_pointer_width = "64")]
let uptime: i64 = tp.tv_sec;
#[cfg(not(target_pointer_width = "64"))]
let uptime: i64 = tp.tv_sec.into();

Ok(uptime)
} else {
Err(UptimeError::SystemUptime)?
}
Ok(tp.tv_sec as i64)
}

/// Get the system uptime
Expand Down
Loading