summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJan Bujak <jan@parity.io>2022-03-23 05:28:29 +0000
committerJan Bujak <jan@parity.io>2022-03-23 14:28:37 +0900
commit4ae4cfd0588fbe93e1cc6501bcb98893ebdf26f3 (patch)
treea0aac77caa70d7fbf7176fd7a10fb0c387dd0cce /test
parent3ca28f681ca7b7caa08809f19ae4f3eccc1d41a2 (diff)
downloadnix-4ae4cfd0588fbe93e1cc6501bcb98893ebdf26f3.zip
Make `uname` always safe
This fixes several issues with the current `uname` bindings: - Do not ignore `uname` errors; at least on glibc `uname` can fail, so now it returns a `Result` instead of assuming that the call will always succeed. - Do not assume `uname` will initialize every member of `utsname`; not every implementation initializes every field, so internally the struct is now zero-initialized. - Do not blindly assume strings returned by `uname` will always be valid UTF-8; `UtsName`'s accessors will now return `&OsStr`s instead of `&str`s.
Diffstat (limited to 'test')
-rw-r--r--test/common/mod.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/test/common/mod.rs b/test/common/mod.rs
index 84a0b4fa..544a1ae3 100644
--- a/test/common/mod.rs
+++ b/test/common/mod.rs
@@ -111,15 +111,15 @@ cfg_if! {
let version_requirement = VersionReq::parse($version_requirement)
.expect("Bad match_version provided");
- let uname = nix::sys::utsname::uname();
- println!("{}", uname.sysname());
- println!("{}", uname.nodename());
- println!("{}", uname.release());
- println!("{}", uname.version());
- println!("{}", uname.machine());
+ let uname = nix::sys::utsname::uname().unwrap();
+ println!("{}", uname.sysname().to_str().unwrap());
+ println!("{}", uname.nodename().to_str().unwrap());
+ println!("{}", uname.release().to_str().unwrap());
+ println!("{}", uname.version().to_str().unwrap());
+ println!("{}", uname.machine().to_str().unwrap());
// Fix stuff that the semver parser can't handle
- let fixed_release = &uname.release().to_string()
+ let fixed_release = &uname.release().to_str().unwrap().to_string()
// Fedora 33 reports version as 4.18.el8_2.x86_64 or
// 5.18.200-fc33.x86_64. Remove the underscore.
.replace("_", "-")