From a9260f8cb5224d2789c4caca040295926ce27931 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 00:56:24 -0700 Subject: [PATCH 01/17] Add Illumos to os types list --- os_info/src/os_type.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index 5b59d07d..6b31eefe 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -31,6 +31,8 @@ pub enum Type { /// Linux based operating system (). HardenedBSD, /// HardenedBSD (https://hardenedbsd.org/) + Illumos, + /// Illumos (https://en.wikipedia.org/wiki/Illumos) Linux, /// Mac OS X/OS X/macOS (). Macos, From 4a779ca0342fd2b0dd3cfdb09c65036aa36bb490 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 00:57:43 -0700 Subject: [PATCH 02/17] Create a display for illumos --- os_info/src/os_type.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index 6b31eefe..60886eb6 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -89,6 +89,7 @@ impl Display for Type { Type::Amazon => write!(f, "Amazon Linux AMI"), Type::Arch => write!(f, "Arch Linux"), Type::DragonFly => write!(f, "DragonFly BSD"), + Type::Illumos => write!(f, "Illumos"), Type::Macos => write!(f, "Mac OS"), Type::MidnightBSD => write!(f, "Midnight BSD"), Type::Mint => write!(f, "Linux Mint"), From c38baef38a26ae8de7d5e7d33ca2c6b75be9333e Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:12:07 -0700 Subject: [PATCH 03/17] Create file for illumos --- os_info/src/illumos/mod.rs | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 os_info/src/illumos/mod.rs diff --git a/os_info/src/illumos/mod.rs b/os_info/src/illumos/mod.rs new file mode 100644 index 00000000..3bc2298e --- /dev/null +++ b/os_info/src/illumos/mod.rs @@ -0,0 +1,55 @@ +use std::process::Command; +use std::str; + +use log::{error, trace}; + +use crate::{bitness, uname::uname, Info, Type, Version}; + +pub fn current_platform() -> Info { + trace!("illumos::current_platform is called"); + + let version = uname() + .map(Version::from_string) + .unwrap_or_else(|| Version::Unknown); + + let info = Info { + os_type: get_os(), + version, + bitness: bitness::get(), + ..Default::default() + }; + + trace!("Returning {:?}", info); + info +} + +fn get_os() -> Type { + let os = Command::new("uname") + .arg("-o") + .output() + .expect("Failed to get OS"); + + match str::from_utf8(&os.stdout) { + Ok("illumos\n") => { + Type::Illumos + }, + Ok(_) => { + Type::Unknown + }, + Err(_) => { + Type::Unknown + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn os_type() { + let version = current_platform(); + assert_eq!(Type::Illumos, version.os_type()); + } +} From 215ad21a95c56134b541500e33947e0e072b0aef Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:12:18 -0700 Subject: [PATCH 04/17] Add a function for bitness detection on illumos --- os_info/src/bitness.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/os_info/src/bitness.rs b/os_info/src/bitness.rs index 28b6d0ce..16b4dc76 100644 --- a/os_info/src/bitness.rs +++ b/os_info/src/bitness.rs @@ -78,6 +78,19 @@ pub fn get() -> Bitness { } } +#[cfg(target_os = "illumos")] +pub fn get() -> Bitness { + match &Command::new("uname").arg("-p").output() { + Ok(Output { stdout, .. }) if stdout == b"amd64\n" => Bitness::X64, + Ok(Output { stdout, .. }) if stdout == b"x86_64\n" => Bitness::X64, + Ok(Output { stdout, .. }) if stdout == b"i386\n" => Bitness::X32, + Ok(Output { stdout, .. }) if stdout == b"aarch64\n" => Bitness::X64, + Ok(Output { stdout, .. }) if stdout == b"earmv7hf\n" => Bitness::X32, + Ok(Output { stdout, .. }) if stdout == b"sparc64\n" => Bitness::X64, + _ => Bitness::Unknown, + } +} + #[cfg(all( test, any( From a219ea8a8744bbb87e36062ac9287839393d14c1 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:33:46 -0700 Subject: [PATCH 05/17] Add illumos to target list where deps are declared --- os_info/src/bitness.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/os_info/src/bitness.rs b/os_info/src/bitness.rs index 16b4dc76..5043f645 100644 --- a/os_info/src/bitness.rs +++ b/os_info/src/bitness.rs @@ -4,6 +4,7 @@ use std::fmt::{self, Display, Formatter}; #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "illumos", target_os = "linux", target_os = "macos", target_os = "netbsd", From 1c71226274cdce61e33b5f38247c74e18193837d Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:35:11 -0700 Subject: [PATCH 06/17] Try removing new line character --- os_info/src/illumos/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os_info/src/illumos/mod.rs b/os_info/src/illumos/mod.rs index 3bc2298e..f6d0d851 100644 --- a/os_info/src/illumos/mod.rs +++ b/os_info/src/illumos/mod.rs @@ -30,7 +30,7 @@ fn get_os() -> Type { .expect("Failed to get OS"); match str::from_utf8(&os.stdout) { - Ok("illumos\n") => { + Ok("illumos") => { Type::Illumos }, Ok(_) => { From 70c37c3fa34a17abc1c08589316fd7fc9b99503b Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:38:02 -0700 Subject: [PATCH 07/17] Add illumos targets --- os_info/src/illumos/mod.rs | 2 +- os_info/src/lib.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/os_info/src/illumos/mod.rs b/os_info/src/illumos/mod.rs index f6d0d851..3bc2298e 100644 --- a/os_info/src/illumos/mod.rs +++ b/os_info/src/illumos/mod.rs @@ -30,7 +30,7 @@ fn get_os() -> Type { .expect("Failed to get OS"); match str::from_utf8(&os.stdout) { - Ok("illumos") => { + Ok("illumos\n") => { Type::Illumos }, Ok(_) => { diff --git a/os_info/src/lib.rs b/os_info/src/lib.rs index 318e32e8..a1a6746e 100644 --- a/os_info/src/lib.rs +++ b/os_info/src/lib.rs @@ -26,6 +26,10 @@ mod imp; #[path = "freebsd/mod.rs"] mod imp; +#[cfg(target_os = "illumos")] +#[path = "illumos/mod.rs"] +mod imp; + #[cfg(target_os = "linux")] #[path = "linux/mod.rs"] mod imp; @@ -55,6 +59,7 @@ mod imp; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "illumos", target_os = "linux", target_os = "macos", target_os = "netbsd", @@ -73,6 +78,7 @@ mod os_type; #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "illumos", target_os = "netbsd", target_os = "openbsd" ))] From 6aed94eaf8c1ae6baa8494bf0231d56382df819a Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:41:44 -0700 Subject: [PATCH 08/17] Add a uname function specifically for illumos --- os_info/src/uname.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/os_info/src/uname.rs b/os_info/src/uname.rs index f4417e88..1b9e556b 100644 --- a/os_info/src/uname.rs +++ b/os_info/src/uname.rs @@ -20,6 +20,25 @@ pub fn uname() -> Option { }) } +#[cfg(target_os = "illumos")] +pub fn uname() -> Option { + Command::new("uname") + .arg("-v") + .output() + .map_err(|e| { + error!("Failed to invoke 'uname': {:?}", e); + }) + .ok() + .and_then(|out| { + if out.status.success() { + Some(String::from_utf8_lossy(&out.stdout).trim_end().to_owned()) + } else { + log::error!("'uname' invocation error: {:?}", out); + None + } + }) +} + #[cfg(test)] mod tests { use super::*; From d4b3fae08bf90b35cbf0ff98d21c16663a1af4b6 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:44:00 -0700 Subject: [PATCH 09/17] Remove function uname for illumos --- os_info/src/uname.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/os_info/src/uname.rs b/os_info/src/uname.rs index 1b9e556b..f4417e88 100644 --- a/os_info/src/uname.rs +++ b/os_info/src/uname.rs @@ -20,25 +20,6 @@ pub fn uname() -> Option { }) } -#[cfg(target_os = "illumos")] -pub fn uname() -> Option { - Command::new("uname") - .arg("-v") - .output() - .map_err(|e| { - error!("Failed to invoke 'uname': {:?}", e); - }) - .ok() - .and_then(|out| { - if out.status.success() { - Some(String::from_utf8_lossy(&out.stdout).trim_end().to_owned()) - } else { - log::error!("'uname' invocation error: {:?}", out); - None - } - }) -} - #[cfg(test)] mod tests { use super::*; From 9dfb19539eb5f3558d3c21f8c4a4674e96155333 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:44:09 -0700 Subject: [PATCH 10/17] Implement private function to get version on illumos --- os_info/src/illumos/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/os_info/src/illumos/mod.rs b/os_info/src/illumos/mod.rs index 3bc2298e..78cbe353 100644 --- a/os_info/src/illumos/mod.rs +++ b/os_info/src/illumos/mod.rs @@ -8,7 +8,7 @@ use crate::{bitness, uname::uname, Info, Type, Version}; pub fn current_platform() -> Info { trace!("illumos::current_platform is called"); - let version = uname() + let version = get_version() .map(Version::from_string) .unwrap_or_else(|| Version::Unknown); @@ -23,6 +23,24 @@ pub fn current_platform() -> Info { info } +fn get_version() -> Option { + Command::new("uname") + .arg("-v") + .output() + .map_err(|e| { + error!("Failed to invoke 'uname': {:?}", e); + }) + .ok() + .and_then(|out| { + if out.status.success() { + Some(String::from_utf8_lossy(&out.stdout).trim_end().to_owned()) + } else { + log::error!("'uname' invocation error: {:?}", out); + None + } + }) +} + fn get_os() -> Type { let os = Command::new("uname") .arg("-o") From d1090530a7870987d4d6295174b220c166c7209e Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:47:33 -0700 Subject: [PATCH 11/17] Add illumos to the readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2c1fe3ee..495477f3 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Right now, the following operating system types can be returned: - Fedora - FreeBSD - HardenedBSD +- Illumos - Linux - Linux Mint - macOS (Mac OS X or OS X) From 45492bca9d237c4d65bab3dab37bcd7012454186 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:47:46 -0700 Subject: [PATCH 12/17] Format fixes --- os_info/src/illumos/mod.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/os_info/src/illumos/mod.rs b/os_info/src/illumos/mod.rs index 78cbe353..1f23771f 100644 --- a/os_info/src/illumos/mod.rs +++ b/os_info/src/illumos/mod.rs @@ -48,15 +48,9 @@ fn get_os() -> Type { .expect("Failed to get OS"); match str::from_utf8(&os.stdout) { - Ok("illumos\n") => { - Type::Illumos - }, - Ok(_) => { - Type::Unknown - }, - Err(_) => { - Type::Unknown - } + Ok("illumos\n") => Type::Illumos, + Ok(_) => Type::Unknown, + Err(_) => Type::Unknown, } } From 725203ac2bced2abc15fc9e7549c09b9bcb40a3b Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 01:49:15 -0700 Subject: [PATCH 13/17] Add illumos --- cspell-dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index 27883338..b03c687b 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -9,6 +9,7 @@ endeavouros freebsd hardenedbsd hbsd +illumos libntdll linuxmint macos From 18fb0512f9f0fce7d36982e20211dce11176da16 Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 08:45:26 -0700 Subject: [PATCH 14/17] Make 'I' lowercase since this is illumos convention --- os_info/src/os_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index 60886eb6..f0ebab43 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -89,7 +89,7 @@ impl Display for Type { Type::Amazon => write!(f, "Amazon Linux AMI"), Type::Arch => write!(f, "Arch Linux"), Type::DragonFly => write!(f, "DragonFly BSD"), - Type::Illumos => write!(f, "Illumos"), + Type::Illumos => write!(f, "illumos"), Type::Macos => write!(f, "Mac OS"), Type::MidnightBSD => write!(f, "Midnight BSD"), Type::Mint => write!(f, "Linux Mint"), From ebc3b0e146a543f7918b83d57c70144aaaeb6e6f Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 08:50:01 -0700 Subject: [PATCH 15/17] Make use of isainfo for bitness uname and getconf do not report properly, but isainfo does --- os_info/src/bitness.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/os_info/src/bitness.rs b/os_info/src/bitness.rs index 5043f645..a675bc78 100644 --- a/os_info/src/bitness.rs +++ b/os_info/src/bitness.rs @@ -81,13 +81,9 @@ pub fn get() -> Bitness { #[cfg(target_os = "illumos")] pub fn get() -> Bitness { - match &Command::new("uname").arg("-p").output() { - Ok(Output { stdout, .. }) if stdout == b"amd64\n" => Bitness::X64, - Ok(Output { stdout, .. }) if stdout == b"x86_64\n" => Bitness::X64, - Ok(Output { stdout, .. }) if stdout == b"i386\n" => Bitness::X32, - Ok(Output { stdout, .. }) if stdout == b"aarch64\n" => Bitness::X64, - Ok(Output { stdout, .. }) if stdout == b"earmv7hf\n" => Bitness::X32, - Ok(Output { stdout, .. }) if stdout == b"sparc64\n" => Bitness::X64, + match &Command::new("isainfo").arg("-b").output() { + Ok(Output { stdout, .. }) if stdout == b"64\n" => Bitness::X64, + Ok(Output { stdout, .. }) if stdout == b"32\n" => Bitness::X64, _ => Bitness::Unknown, } } From b317711afcd9c9eb733b8f28d2d115b5242f45cf Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 08:53:59 -0700 Subject: [PATCH 16/17] Add isainfo --- cspell-dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index b03c687b..bba5692e 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -10,6 +10,7 @@ freebsd hardenedbsd hbsd illumos +isainfo libntdll linuxmint macos From 63f423936b5d62477a73c6f43b4c1b059a3be39b Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Mon, 25 Apr 2022 08:57:09 -0700 Subject: [PATCH 17/17] Correction, return Bitness::X32 when it see "32\n" --- os_info/src/bitness.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os_info/src/bitness.rs b/os_info/src/bitness.rs index a675bc78..dba7e1c8 100644 --- a/os_info/src/bitness.rs +++ b/os_info/src/bitness.rs @@ -83,7 +83,7 @@ pub fn get() -> Bitness { pub fn get() -> Bitness { match &Command::new("isainfo").arg("-b").output() { Ok(Output { stdout, .. }) if stdout == b"64\n" => Bitness::X64, - Ok(Output { stdout, .. }) if stdout == b"32\n" => Bitness::X64, + Ok(Output { stdout, .. }) if stdout == b"32\n" => Bitness::X32, _ => Bitness::Unknown, } }