From c74b77aec895bb8cd91c4e1ea83cff291680b9e6 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Mon, 5 Jul 2021 22:42:42 +0100 Subject: [PATCH 1/3] uname: don't report OS as "GNU/Linux" without GNU The `uname` `-o` switch reports the operating system used. If the GNU C standard library (glibc) is not in use, for example if musl is being used instead, report "Linux" instead of "GNU/Linux". --- src/uu/uname/src/uname.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index dda859722..26b4ddd2a 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -30,8 +30,10 @@ pub mod options { pub static OS: &str = "operating-system"; } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "")))] const HOST_OS: &str = "GNU/Linux"; +#[cfg(all(target_os = "linux", not(any(target_env = "gnu", target_env = ""))))] +const HOST_OS: &str = "Linux"; #[cfg(target_os = "windows")] const HOST_OS: &str = "Windows NT"; #[cfg(target_os = "freebsd")] From 330f797378e673835c89dc82ad30e8ea52ea7455 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Tue, 6 Jul 2021 23:40:38 +0100 Subject: [PATCH 2/3] tests/uname: add `--operating-system` test --- tests/by-util/test_uname.rs | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/by-util/test_uname.rs b/tests/by-util/test_uname.rs index de3f42a6b..adcaa1072 100644 --- a/tests/by-util/test_uname.rs +++ b/tests/by-util/test_uname.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_uname() { + new_ucmd!().succeeds(); +} + #[test] fn test_uname_compatible() { new_ucmd!().arg("-a").succeeds(); @@ -45,3 +50,60 @@ fn test_uname_kernel() { #[cfg(not(target_os = "linux"))] ucmd.arg("-o").succeeds(); } + +#[test] +fn test_uname_operating_system() { + #[cfg(target_vendor = "apple")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("Darwin\n"); + #[cfg(target_os = "freebsd")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("FreeBSD\n"); + #[cfg(target_os = "fuchsia")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("Fuchsia\n"); + #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "")))] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("GNU/Linux\n"); + #[cfg(all(target_os = "linux", not(any(target_env = "gnu", target_env = ""))))] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("Linux\n"); + #[cfg(target_os = "netbsd")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("NetBSD\n"); + #[cfg(target_os = "openbsd")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("OpenBSD\n"); + #[cfg(target_os = "redox")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("Redox\n"); + #[cfg(target_os = "windows")] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("Windows NT\n"); +} + +#[test] +fn test_uname_help() { + new_ucmd!() + .arg("--help") + .succeeds() + .stdout_contains("system information"); +} From 7a62d8e4e7cd104edd679fe5fd9125bc18f4a639 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Tue, 6 Jul 2021 23:42:16 +0100 Subject: [PATCH 3/3] uname: add NetBSD to operating systems list --- src/uu/uname/src/uname.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index 26b4ddd2a..abd50d1b8 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -38,6 +38,8 @@ const HOST_OS: &str = "Linux"; const HOST_OS: &str = "Windows NT"; #[cfg(target_os = "freebsd")] const HOST_OS: &str = "FreeBSD"; +#[cfg(target_os = "netbsd")] +const HOST_OS: &str = "NetBSD"; #[cfg(target_os = "openbsd")] const HOST_OS: &str = "OpenBSD"; #[cfg(target_vendor = "apple")]