bug: redirect stderr on FreeBSD to avoid drawing on UI (#897)

This commit is contained in:
Clement Tsang 2022-11-17 03:18:05 -05:00 committed by GitHub
parent 31d2e4a746
commit a07fa305fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 7 deletions

12
Cargo.lock generated
View File

@ -219,6 +219,7 @@ dependencies = [
"ctrlc",
"dirs",
"fern",
"filedescriptor",
"futures",
"futures-timer",
"fxhash",
@ -589,6 +590,17 @@ dependencies = [
"log",
]
[[package]]
name = "filedescriptor"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7199d965852c3bac31f779ef99cbb4537f80e952e2d6aa0ffeb30cce00f4f46e"
dependencies = [
"libc",
"thiserror",
"winapi",
]
[[package]]
name = "float-cmp"
version = "0.9.0"

View File

@ -111,6 +111,7 @@ winapi = "0.3.9"
[target.'cfg(target_os = "freebsd")'.dependencies]
serde_json = { version = "1.0.82" }
sysctl = { version = "0.5.2", optional = true }
filedescriptor = "0.8.2"
[dev-dependencies]
assert_cmd = "2.0.4"

View File

@ -251,14 +251,22 @@ impl DataCollector {
if self.widgets_to_harvest.use_temp {
self.sys.refresh_components();
}
if cfg!(target_os = "windows") && self.widgets_to_harvest.use_net {
self.sys.refresh_networks();
#[cfg(target_os = "windows")]
{
if self.widgets_to_harvest.use_net {
self.sys.refresh_networks();
}
}
if cfg!(target_os = "freebsd") && self.widgets_to_harvest.use_disk {
self.sys.refresh_disks();
}
if cfg!(target_os = "freebsd") && self.widgets_to_harvest.use_mem {
self.sys.refresh_memory();
#[cfg(target_os = "freebsd")]
{
if self.widgets_to_harvest.use_disk {
self.sys.refresh_disks();
}
if self.widgets_to_harvest.use_mem {
self.sys.refresh_memory();
}
}
}

View File

@ -131,6 +131,16 @@ fn main() -> Result<()> {
terminal.clear()?;
terminal.hide_cursor()?;
#[cfg(target_os = "freebsd")]
let _stderr_fd = {
// A really ugly band-aid to suppress stderr warnings on FreeBSD due to sysinfo.
use filedescriptor::{FileDescriptor, StdioDescriptor};
use std::fs::OpenOptions;
let path = OpenOptions::new().write(true).open("/dev/null")?;
FileDescriptor::redirect_stdio(&path, StdioDescriptor::Stderr)?
};
// Set panic hook
panic::set_hook(Box::new(panic_hook));