mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
who: exclude --runlevel from non Linux targets (fix #2239)
This commit is contained in:
parent
70e65c419f
commit
44c033a013
2 changed files with 25 additions and 40 deletions
|
@ -29,7 +29,6 @@ mod options {
|
||||||
pub const ONLY_HOSTNAME_USER: &str = "only_hostname_user";
|
pub const ONLY_HOSTNAME_USER: &str = "only_hostname_user";
|
||||||
pub const PROCESS: &str = "process";
|
pub const PROCESS: &str = "process";
|
||||||
pub const COUNT: &str = "count";
|
pub const COUNT: &str = "count";
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
pub const RUNLEVEL: &str = "runlevel";
|
pub const RUNLEVEL: &str = "runlevel";
|
||||||
pub const SHORT: &str = "short";
|
pub const SHORT: &str = "short";
|
||||||
pub const TIME: &str = "time";
|
pub const TIME: &str = "time";
|
||||||
|
@ -41,6 +40,11 @@ mod options {
|
||||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
static ABOUT: &str = "Print information about users who are currently logged in.";
|
static ABOUT: &str = "Print information about users who are currently logged in.";
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux"))]
|
||||||
|
static RUNLEVEL_HELP: &str = "print current runlevel";
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)";
|
||||||
|
|
||||||
fn get_usage() -> String {
|
fn get_usage() -> String {
|
||||||
format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!())
|
format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!())
|
||||||
}
|
}
|
||||||
|
@ -119,13 +123,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.help("all login names and number of users logged on"),
|
.help("all login names and number of users logged on"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
Arg::with_name(options::RUNLEVEL)
|
Arg::with_name(options::RUNLEVEL)
|
||||||
.long(options::RUNLEVEL)
|
.long(options::RUNLEVEL)
|
||||||
.short("r")
|
.short("r")
|
||||||
.help("print current runlevel"),
|
.help(RUNLEVEL_HELP),
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "freebsd"))]
|
|
||||||
Arg::with_name(""),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SHORT)
|
Arg::with_name(options::SHORT)
|
||||||
|
@ -267,14 +268,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
assumptions = false;
|
assumptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
{
|
|
||||||
if matches.is_present(options::RUNLEVEL) {
|
if matches.is_present(options::RUNLEVEL) {
|
||||||
need_runlevel = true;
|
need_runlevel = true;
|
||||||
include_idle = true;
|
include_idle = true;
|
||||||
assumptions = false;
|
assumptions = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::SHORT) {
|
if matches.is_present(options::SHORT) {
|
||||||
short_output = true;
|
short_output = true;
|
||||||
|
@ -389,15 +387,12 @@ fn current_tty() -> String {
|
||||||
|
|
||||||
impl Who {
|
impl Who {
|
||||||
fn exec(&mut self) {
|
fn exec(&mut self) {
|
||||||
let run_level_chk = |record: i16| {
|
let run_level_chk = |_record: i16| {
|
||||||
#[allow(unused_assignments)]
|
#[cfg(not(target_os = "linux"))]
|
||||||
let mut res = false;
|
return false;
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
return _record == utmpx::RUN_LVL;
|
||||||
res = record == utmpx::RUN_LVL;
|
|
||||||
}
|
|
||||||
res
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let f = if self.args.len() == 1 {
|
let f = if self.args.len() == 1 {
|
||||||
|
@ -430,7 +425,9 @@ impl Who {
|
||||||
if self.need_users && ut.is_user_process() {
|
if self.need_users && ut.is_user_process() {
|
||||||
self.print_user(&ut);
|
self.print_user(&ut);
|
||||||
} else if self.need_runlevel && run_level_chk(ut.record_type()) {
|
} else if self.need_runlevel && run_level_chk(ut.record_type()) {
|
||||||
|
if cfg!(target_os = "linux") {
|
||||||
self.print_runlevel(&ut);
|
self.print_runlevel(&ut);
|
||||||
|
}
|
||||||
} else if self.need_boottime && ut.record_type() == utmpx::BOOT_TIME {
|
} else if self.need_boottime && ut.record_type() == utmpx::BOOT_TIME {
|
||||||
self.print_boottime(&ut);
|
self.print_boottime(&ut);
|
||||||
} else if self.need_clockchange && ut.record_type() == utmpx::NEW_TIME {
|
} else if self.need_clockchange && ut.record_type() == utmpx::NEW_TIME {
|
||||||
|
|
|
@ -83,27 +83,17 @@ fn test_process() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_runlevel() {
|
fn test_runlevel() {
|
||||||
for opt in vec!["-r", "--runlevel"] {
|
for opt in vec!["-r", "--runlevel"] {
|
||||||
|
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg(opt)
|
.arg(opt)
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is(expected_result(&[opt]));
|
.stdout_is(expected_result(&[opt]));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "freebsd"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
#[test]
|
new_ucmd!().arg(opt).succeeds().stdout_is("");
|
||||||
fn test_runlevel() {
|
|
||||||
let expected =
|
|
||||||
"error: Found argument";
|
|
||||||
for opt in vec!["-r", "--runlevel"] {
|
|
||||||
new_ucmd!()
|
|
||||||
.arg(opt)
|
|
||||||
.fails()
|
|
||||||
.stderr_contains(expected);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +125,6 @@ fn test_mesg() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_arg1_arg2() {
|
fn test_arg1_arg2() {
|
||||||
let args = ["am", "i"];
|
let args = ["am", "i"];
|
||||||
|
@ -146,7 +135,6 @@ fn test_arg1_arg2() {
|
||||||
.stdout_is(expected_result(&args));
|
.stdout_is(expected_result(&args));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_too_many_args() {
|
fn test_too_many_args() {
|
||||||
const EXPECTED: &str =
|
const EXPECTED: &str =
|
||||||
|
@ -168,11 +156,11 @@ fn test_users() {
|
||||||
let mut v_actual: Vec<&str> = actual.split_whitespace().collect();
|
let mut v_actual: Vec<&str> = actual.split_whitespace().collect();
|
||||||
let mut v_expect: Vec<&str> = expect.split_whitespace().collect();
|
let mut v_expect: Vec<&str> = expect.split_whitespace().collect();
|
||||||
|
|
||||||
// TODO: `--users` differs from GNU's output on manOS running in CI
|
// TODO: `--users` differs from GNU's output on macOS
|
||||||
// Diff < left / right > :
|
// Diff < left / right > :
|
||||||
// <"runner console 2021-05-20 22:03 00:08 196\n"
|
// <"runner console 2021-05-20 22:03 00:08 196\n"
|
||||||
// >"runner console 2021-05-20 22:03 old 196\n"
|
// >"runner console 2021-05-20 22:03 old 196\n"
|
||||||
if is_ci() && cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
v_actual.remove(4);
|
v_actual.remove(4);
|
||||||
v_expect.remove(4);
|
v_expect.remove(4);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +194,7 @@ fn test_dead() {
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all_separately() {
|
fn test_all_separately() {
|
||||||
if is_ci() && cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
// TODO: fix `-u`, see: test_users
|
// TODO: fix `-u`, see: test_users
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +217,7 @@ fn test_all_separately() {
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all() {
|
fn test_all() {
|
||||||
if is_ci() && cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
// TODO: fix `-u`, see: test_users
|
// TODO: fix `-u`, see: test_users
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue