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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions src/uu/uptime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ uucore = { workspace = true, features = ["libc", "utmpx", "uptime"] }
[target.'cfg(target_os = "openbsd")'.dependencies]
utmp-classic = { workspace = true }

[target.'cfg(target_os="windows")'.dependencies]
windows-sys = { workspace = true, features = [
"Win32_System_RemoteDesktop",
"Wdk_System_SystemInformation",
] }

[[bin]]
name = "uptime"
path = "src/main.rs"
5 changes: 0 additions & 5 deletions src/uu/uptime/src/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ pub mod options {
pub static PATH: &str = "path";
}

#[cfg(windows)]
extern "C" {
fn GetTickCount() -> u32;
}

#[derive(Debug, Error)]
pub enum UptimeError {
// io::Error wrapper
Expand Down
1 change: 1 addition & 0 deletions src/uucore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ windows-sys = { workspace = true, optional = true, default-features = false, fea
"Win32_Storage_FileSystem",
"Win32_Foundation",
"Win32_System_RemoteDesktop",
"Win32_System_SystemInformation",
"Win32_System_WindowsProgramming",
] }

Expand Down
12 changes: 8 additions & 4 deletions src/uucore/src/lib/features/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,19 @@ pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {

/// Get the system uptime
///
/// # Arguments
///
/// boot_time will be ignored, pass None.
///
/// # Returns
///
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
#[cfg(windows)]
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
use windows_sys::Win32::System::SystemInformation::GetTickCount;
// SAFETY: always return u32
let uptime = unsafe { GetTickCount() };
if uptime < 0 {
Err(UptimeError::SystemUptime)?;
}
Ok(uptime as i64)
Ok(uptime as i64 / 1000)
}

/// Get the system uptime in a human-readable format
Expand Down Expand Up @@ -244,6 +246,7 @@ pub fn get_nusers() -> usize {

let mut num_user = 0;

// SAFETY: WTS_CURRENT_SERVER_HANDLE is a valid handle
unsafe {
let mut session_info_ptr = ptr::null_mut();
let mut session_count = 0;
Expand Down Expand Up @@ -335,6 +338,7 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
use libc::getloadavg;

let mut avg: [c_double; 3] = [0.0; 3];
// SAFETY: checked whether it returns -1
let loads: i32 = unsafe { getloadavg(avg.as_mut_ptr(), 3) };

if loads == -1 {
Expand Down
Loading