Skip to content

Commit 44016bf

Browse files
committed
uptime: make it compile on Android & Redox
1 parent 07a4399 commit 44016bf

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/uu/uptime/src/uptime.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use clap::{Arg, ArgAction, Command};
1919
use uucore::format_usage;
2020

2121
#[cfg(unix)]
22-
#[cfg(not(target_os = "openbsd"))]
22+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
2323
use uucore::utmpx::*;
2424

2525
pub mod options {
@@ -162,7 +162,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
162162
print_time();
163163
let user_count;
164164

165-
#[cfg(not(target_os = "openbsd"))]
165+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
166166
{
167167
let (boot_time, count) = process_utmpx(Some(file_path));
168168
if let Some(time) = boot_time {
@@ -176,7 +176,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
176176
user_count = count;
177177
}
178178

179-
#[cfg(target_os = "openbsd")]
179+
#[cfg(any(target_os = "openbsd", target_os = "redox", target_os = "android"))]
180180
{
181181
let upsecs = get_uptime(None)?;
182182
if upsecs >= 0 {
@@ -198,12 +198,17 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
198198

199199
fn uptime_since() -> UResult<()> {
200200
#[cfg(unix)]
201-
#[cfg(not(target_os = "openbsd"))]
201+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
202202
let uptime = {
203203
let (boot_time, _) = process_utmpx(None);
204204
get_uptime(boot_time)?
205205
};
206-
#[cfg(any(windows, target_os = "openbsd"))]
206+
#[cfg(any(
207+
windows,
208+
target_os = "openbsd",
209+
target_os = "redox",
210+
target_os = "android"
211+
))]
207212
let uptime = get_uptime(None)?;
208213

209214
let since_date = Local
@@ -233,7 +238,7 @@ fn print_loadavg() {
233238
}
234239

235240
#[cfg(unix)]
236-
#[cfg(not(target_os = "openbsd"))]
241+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
237242
fn process_utmpx(file: Option<&OsString>) -> (Option<time_t>, usize) {
238243
let mut nusers = 0;
239244
let mut boot_time = None;

src/uucore/src/lib/features/uptime.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
120120
}
121121
}
122122

123+
// TODO implement functionality
124+
#[cfg(any(target_os = "android", target_os = "redox"))]
125+
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
126+
Err(UptimeError::SystemUptime)?
127+
}
128+
123129
/// Get the system uptime
124130
///
125131
/// # Arguments
@@ -130,7 +136,7 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
130136
///
131137
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
132138
#[cfg(unix)]
133-
#[cfg(not(target_os = "openbsd"))]
139+
#[cfg(not(any(target_os = "openbsd", target_os = "android", target_os = "redox")))]
134140
pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {
135141
use crate::utmpx::Utmpx;
136142
use libc::BOOT_TIME;
@@ -251,7 +257,7 @@ pub fn get_formatted_uptime(boot_time: Option<time_t>) -> UResult<String> {
251257
///
252258
/// Returns the number of users currently logged in if successful, otherwise 0.
253259
#[cfg(unix)]
254-
#[cfg(not(target_os = "openbsd"))]
260+
#[cfg(not(any(target_os = "openbsd", target_os = "android", target_os = "redox")))]
255261
// see: https://gitlab.com/procps-ng/procps/-/blob/4740a0efa79cade867cfc7b32955fe0f75bf5173/library/uptime.c#L63-L115
256262
pub fn get_nusers() -> usize {
257263
use crate::utmpx::Utmpx;
@@ -293,6 +299,12 @@ pub fn get_nusers(file: &str) -> usize {
293299
.count()
294300
}
295301

302+
// TODO implement functionality
303+
#[cfg(any(target_os = "android", target_os = "redox"))]
304+
pub fn get_nusers() -> usize {
305+
0
306+
}
307+
296308
/// Get the number of users currently logged in
297309
///
298310
/// # Returns
@@ -391,6 +403,7 @@ pub fn get_formatted_nusers() -> String {
391403
/// Returns a UResult with the load average if successful, otherwise an UptimeError.
392404
/// The load average is a tuple of three floating point numbers representing the 1-minute, 5-minute, and 15-minute load averages.
393405
#[cfg(unix)]
406+
#[cfg(not(any(target_os = "android", target_os = "redox")))]
394407
pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
395408
use crate::libc::c_double;
396409
use libc::getloadavg;
@@ -406,6 +419,12 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
406419
}
407420
}
408421

422+
// TODO implement functionality
423+
#[cfg(any(target_os = "android", target_os = "redox"))]
424+
pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
425+
Err(UptimeError::SystemLoadavg)?
426+
}
427+
409428
/// Get the system load average
410429
/// Windows does not have an equivalent to the load average on Unix-like systems.
411430
///

0 commit comments

Comments
 (0)