mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #2267 from jhscheer/who_fix_runlevel
who: exclude `--runlevel` from non Linux targets (fix #2239)
This commit is contained in:
commit
4061ada132
2 changed files with 25 additions and 36 deletions
|
@ -29,7 +29,6 @@ mod options {
|
|||
pub const ONLY_HOSTNAME_USER: &str = "only_hostname_user";
|
||||
pub const PROCESS: &str = "process";
|
||||
pub const COUNT: &str = "count";
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub const RUNLEVEL: &str = "runlevel";
|
||||
pub const SHORT: &str = "short";
|
||||
pub const TIME: &str = "time";
|
||||
|
@ -41,6 +40,11 @@ mod options {
|
|||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
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 {
|
||||
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"),
|
||||
)
|
||||
.arg(
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
Arg::with_name(options::RUNLEVEL)
|
||||
.long(options::RUNLEVEL)
|
||||
.short("r")
|
||||
.help("print current runlevel"),
|
||||
#[cfg(any(target_vendor = "apple", target_os = "freebsd"))]
|
||||
Arg::with_name(""),
|
||||
.help(RUNLEVEL_HELP),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(options::SHORT)
|
||||
|
@ -267,13 +268,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
assumptions = false;
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
if matches.is_present(options::RUNLEVEL) {
|
||||
need_runlevel = true;
|
||||
include_idle = true;
|
||||
assumptions = false;
|
||||
}
|
||||
if matches.is_present(options::RUNLEVEL) {
|
||||
need_runlevel = true;
|
||||
include_idle = true;
|
||||
assumptions = false;
|
||||
}
|
||||
|
||||
if matches.is_present(options::SHORT) {
|
||||
|
@ -389,15 +387,12 @@ fn current_tty() -> String {
|
|||
|
||||
impl Who {
|
||||
fn exec(&mut self) {
|
||||
let run_level_chk = |record: i16| {
|
||||
#[allow(unused_assignments)]
|
||||
let mut res = false;
|
||||
let run_level_chk = |_record: i16| {
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
return false;
|
||||
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
res = record == utmpx::RUN_LVL;
|
||||
}
|
||||
res
|
||||
#[cfg(target_os = "linux")]
|
||||
return _record == utmpx::RUN_LVL;
|
||||
};
|
||||
|
||||
let f = if self.args.len() == 1 {
|
||||
|
@ -430,7 +425,9 @@ impl Who {
|
|||
if self.need_users && ut.is_user_process() {
|
||||
self.print_user(&ut);
|
||||
} else if self.need_runlevel && run_level_chk(ut.record_type()) {
|
||||
self.print_runlevel(&ut);
|
||||
if cfg!(target_os = "linux") {
|
||||
self.print_runlevel(&ut);
|
||||
}
|
||||
} else if self.need_boottime && ut.record_type() == utmpx::BOOT_TIME {
|
||||
self.print_boottime(&ut);
|
||||
} else if self.need_clockchange && ut.record_type() == utmpx::NEW_TIME {
|
||||
|
|
|
@ -83,23 +83,17 @@ fn test_process() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_runlevel() {
|
||||
for opt in vec!["-r", "--runlevel"] {
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_vendor = "apple", target_os = "freebsd"))]
|
||||
#[test]
|
||||
fn test_runlevel() {
|
||||
let expected = "error: Found argument";
|
||||
for opt in vec!["-r", "--runlevel"] {
|
||||
new_ucmd!().arg(opt).fails().stderr_contains(expected);
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
new_ucmd!().arg(opt).succeeds().stdout_is("");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +125,6 @@ fn test_mesg() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_arg1_arg2() {
|
||||
let args = ["am", "i"];
|
||||
|
@ -142,7 +135,6 @@ fn test_arg1_arg2() {
|
|||
.stdout_is(expected_result(&args));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_too_many_args() {
|
||||
const EXPECTED: &str =
|
||||
|
@ -164,11 +156,11 @@ fn test_users() {
|
|||
let mut v_actual: Vec<&str> = actual.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 > :
|
||||
// <"runner console 2021-05-20 22:03 00:08 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_expect.remove(4);
|
||||
}
|
||||
|
@ -202,7 +194,7 @@ fn test_dead() {
|
|||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_all_separately() {
|
||||
if is_ci() && cfg!(target_os = "macos") {
|
||||
if cfg!(target_os = "macos") {
|
||||
// TODO: fix `-u`, see: test_users
|
||||
return;
|
||||
}
|
||||
|
@ -225,7 +217,7 @@ fn test_all_separately() {
|
|||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_all() {
|
||||
if is_ci() && cfg!(target_os = "macos") {
|
||||
if cfg!(target_os = "macos") {
|
||||
// TODO: fix `-u`, see: test_users
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue