diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-09-30 22:53:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 22:53:54 -0400 |
commit | 5b33e8d6b4b28c6a64e017bc137bd4897cf9cb74 (patch) | |
tree | 8d0aa970879784f38e4c5724f6101e2a1109302c /src | |
parent | 9afb6d7c88ca515ecd8d37134b567b6d17e0f0fb (diff) |
Use tmp_dir rather than /tmp/ (#260)
Uses a less hard-coded method of writing to /tmp/.
Diffstat (limited to 'src')
-rw-r--r-- | src/app/data_harvester/processes.rs | 2 | ||||
-rw-r--r-- | src/bin/main.rs | 7 | ||||
-rw-r--r-- | src/clap.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/utils/logging.rs | 4 |
5 files changed, 13 insertions, 6 deletions
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs index f290d957..64988338 100644 --- a/src/app/data_harvester/processes.rs +++ b/src/app/data_harvester/processes.rs @@ -262,7 +262,7 @@ fn read_proc<S: core::hash::BuildHasher>( .ok_or(BottomError::MinorError)? .to_string(); let command = { - let cmd = read_path_contents(&pid_stat.proc_cmdline_path)?; + let cmd = read_path_contents(&pid_stat.proc_cmdline_path)?; // FIXME: [PROC] Use full proc name all the time if cmd.trim().is_empty() { format!("[{}]", name) } else { diff --git a/src/bin/main.rs b/src/bin/main.rs index d8e541cd..81ac2041 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -7,6 +7,7 @@ use bottom::{canvas, constants::*, data_conversion::*, options::*, *}; use std::{ boxed::Box, + ffi::OsStr, io::{stdout, Write}, panic, sync::{ @@ -29,11 +30,13 @@ fn main() -> Result<()> { let matches = clap::get_matches(); let is_debug = matches.is_present("debug"); if is_debug { - utils::logging::init_logger(log::LevelFilter::Trace, "/tmp/bottom_debug.log")?; + let mut tmp_dir = std::env::temp_dir(); + tmp_dir.push("bottom_debug.log"); + utils::logging::init_logger(log::LevelFilter::Trace, tmp_dir.as_os_str())?; } else { #[cfg(debug_assertions)] { - utils::logging::init_logger(log::LevelFilter::Debug, "debug.log")?; + utils::logging::init_logger(log::LevelFilter::Debug, OsStr::new("debug.log"))?; } } diff --git a/src/clap.rs b/src/clap.rs index 7c2191a8..b9898198 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -86,7 +86,7 @@ When searching for a process, enables case sensitivity by default.\n\n", .help("Enables debug logging.") .long_help( "\ -Enables debug logging to /tmp/bottom_debug.log.", +Enables debug logging. The program will print where it logged to after running.", ); let disable_click = Arg::with_name("disable_click") .long("disable_click") @@ -254,7 +254,9 @@ pub fn cleanup_terminal( terminal.show_cursor()?; if is_debug { - println!("Your debug file is located at \"/tmp/bottom_debug.log\".",); + let mut tmp_dir = std::env::temp_dir(); + tmp_dir.push("bottom_debug.log"); + println!("Your debug file is located at {:?}", tmp_dir.as_os_str()); } Ok(()) diff --git a/src/utils/logging.rs b/src/utils/logging.rs index fcd1e211..86a55656 100644 --- a/src/utils/logging.rs +++ b/src/utils/logging.rs @@ -1,5 +1,7 @@ +use std::ffi::OsStr; + pub fn init_logger( - min_level: log::LevelFilter, debug_file_name: &str, + min_level: log::LevelFilter, debug_file_name: &OsStr, ) -> Result<(), fern::InitError> { fern::Dispatch::new() .format(|out, message, record| { |