Skip to content

Commit f580003

Browse files
committed
uptime: make it compile on Android & Redox
1 parent 6991e8f commit f580003

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
@@ -20,7 +20,7 @@ use uucore::LocalizedCommand;
2020
use uucore::format_usage;
2121

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

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

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

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

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

210215
let since_date = Local
@@ -234,7 +239,7 @@ fn print_loadavg() {
234239
}
235240

236241
#[cfg(unix)]
237-
#[cfg(not(target_os = "openbsd"))]
242+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
238243
fn process_utmpx(file: Option<&OsString>) -> (Option<time_t>, usize) {
239244
let mut nusers = 0;
240245
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
@@ -79,6 +79,12 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
7979
}
8080
}
8181

82+
// TODO implement functionality
83+
#[cfg(any(target_os = "android", target_os = "redox"))]
84+
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
85+
Err(UptimeError::SystemUptime)?
86+
}
87+
8288
/// Get the system uptime
8389
///
8490
/// # Arguments
@@ -89,7 +95,7 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
8995
///
9096
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
9197
#[cfg(unix)]
92-
#[cfg(not(target_os = "openbsd"))]
98+
#[cfg(not(any(target_os = "openbsd", target_os = "android", target_os = "redox")))]
9399
pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {
94100
use crate::utmpx::Utmpx;
95101
use libc::BOOT_TIME;
@@ -189,7 +195,7 @@ pub fn get_formatted_uptime(boot_time: Option<time_t>) -> UResult<String> {
189195
///
190196
/// Returns the number of users currently logged in if successful, otherwise 0.
191197
#[cfg(unix)]
192-
#[cfg(not(target_os = "openbsd"))]
198+
#[cfg(not(any(target_os = "openbsd", target_os = "android", target_os = "redox")))]
193199
// see: https://gitlab.com/procps-ng/procps/-/blob/4740a0efa79cade867cfc7b32955fe0f75bf5173/library/uptime.c#L63-L115
194200
pub fn get_nusers() -> usize {
195201
use crate::utmpx::Utmpx;
@@ -236,6 +242,12 @@ pub fn get_nusers(file: &str) -> usize {
236242
nusers
237243
}
238244

245+
// TODO implement functionality
246+
#[cfg(any(target_os = "android", target_os = "redox"))]
247+
pub fn get_nusers() -> usize {
248+
0
249+
}
250+
239251
/// Get the number of users currently logged in
240252
///
241253
/// # Returns
@@ -334,6 +346,7 @@ pub fn get_formatted_nusers() -> String {
334346
/// Returns a UResult with the load average if successful, otherwise an UptimeError.
335347
/// The load average is a tuple of three floating point numbers representing the 1-minute, 5-minute, and 15-minute load averages.
336348
#[cfg(unix)]
349+
#[cfg(not(any(target_os = "android", target_os = "redox")))]
337350
pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
338351
use crate::libc::c_double;
339352
use libc::getloadavg;
@@ -349,6 +362,12 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
349362
}
350363
}
351364

365+
// TODO implement functionality
366+
#[cfg(any(target_os = "android", target_os = "redox"))]
367+
pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
368+
Err(UptimeError::SystemLoadavg)?
369+
}
370+
352371
/// Get the system load average
353372
/// Windows does not have an equivalent to the load average on Unix-like systems.
354373
///

0 commit comments

Comments
 (0)