Use tmp_dir rather than /tmp/ (#260)

Uses a less hard-coded method of writing to /tmp/.
This commit is contained in:
Clement Tsang 2020-09-30 22:53:54 -04:00 committed by GitHub
parent 9afb6d7c88
commit 5b33e8d6b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 6 deletions

View File

@ -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 {

View File

@ -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"))?;
}
}

View File

@ -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")

View File

@ -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(())

View File

@ -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| {