mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-15 22:44:01 +00:00
Use a normal File for debug-output
Like the TODO said, we no longer need this.
This commit is contained in:
parent
76a80a0678
commit
caac869b6e
1 changed files with 3 additions and 31 deletions
|
@ -39,12 +39,10 @@ use fish::{
|
||||||
},
|
},
|
||||||
eprintf,
|
eprintf,
|
||||||
event::{self, Event},
|
event::{self, Event},
|
||||||
fds::set_cloexec,
|
|
||||||
flog::{self, activate_flog_categories_by_pattern, set_flog_file_fd, FLOG, FLOGF},
|
flog::{self, activate_flog_categories_by_pattern, set_flog_file_fd, FLOG, FLOGF},
|
||||||
fprintf, function, future_feature_flags as features, history,
|
fprintf, function, future_feature_flags as features, history,
|
||||||
history::start_private_mode,
|
history::start_private_mode,
|
||||||
io::IoChain,
|
io::IoChain,
|
||||||
libc::setlinebuf,
|
|
||||||
nix::{getpid, isatty},
|
nix::{getpid, isatty},
|
||||||
parse_constants::{ParseErrorList, ParseTreeFlags},
|
parse_constants::{ParseErrorList, ParseTreeFlags},
|
||||||
parse_tree::ParsedSource,
|
parse_tree::ParsedSource,
|
||||||
|
@ -511,48 +509,26 @@ fn main() {
|
||||||
opts.debug_output = env::var_os("FISH_DEBUG_OUTPUT");
|
opts.debug_output = env::var_os("FISH_DEBUG_OUTPUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut debug_output = std::ptr::null_mut();
|
|
||||||
if let Some(debug_path) = opts.debug_output {
|
if let Some(debug_path) = opts.debug_output {
|
||||||
let path = cstr_from_osstr(&debug_path);
|
match File::options()
|
||||||
let mode = CString::new("w").unwrap();
|
|
||||||
let debug_file = unsafe { libc::fopen(path.as_ptr(), mode.as_ptr()) };
|
|
||||||
|
|
||||||
if debug_file.is_null() {
|
|
||||||
eprintln!("Could not open file {:?}", debug_output);
|
|
||||||
let s = CString::new("fopen").unwrap();
|
|
||||||
unsafe { libc::perror(s.as_ptr()) }
|
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
set_cloexec(unsafe { libc::fileno(debug_file) }, true);
|
|
||||||
unsafe { setlinebuf(debug_file) };
|
|
||||||
set_flog_file_fd(unsafe { libc::fileno(debug_file) });
|
|
||||||
|
|
||||||
debug_output = debug_file;
|
|
||||||
|
|
||||||
/* TODO: just use File when C++ does not need a *mut FILE
|
|
||||||
|
|
||||||
debug_output = match File::options()
|
|
||||||
.write(true)
|
.write(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(debug_path)
|
.open(debug_path.clone())
|
||||||
{
|
{
|
||||||
Ok(dbg_file) => {
|
Ok(dbg_file) => {
|
||||||
// Rust sets O_CLOEXEC by default
|
// Rust sets O_CLOEXEC by default
|
||||||
// https://github.com/rust-lang/rust/blob/07438b0928c6691d6ee734a5a77823ec143be94d/library/std/src/sys/unix/fs.rs#L1059
|
// https://github.com/rust-lang/rust/blob/07438b0928c6691d6ee734a5a77823ec143be94d/library/std/src/sys/unix/fs.rs#L1059
|
||||||
|
|
||||||
flog::set_flog_file_fd(dbg_file.as_raw_fd());
|
flog::set_flog_file_fd(dbg_file.as_raw_fd());
|
||||||
Some(dbg_file)
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// TODO: should not be debug-print
|
// TODO: should not be debug-print
|
||||||
eprintln!("Could not open file {:?}", debug_output);
|
eprintln!("Could not open file {:?}", debug_path);
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No-exec is prohibited when in interactive mode.
|
// No-exec is prohibited when in interactive mode.
|
||||||
|
@ -756,10 +732,6 @@ fn main() {
|
||||||
print_rusage_self();
|
print_rusage_self();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !debug_output.is_null() {
|
|
||||||
unsafe { libc::fclose(debug_output) };
|
|
||||||
}
|
|
||||||
|
|
||||||
asan_maybe_exit(exit_status);
|
asan_maybe_exit(exit_status);
|
||||||
exit_without_destructors(exit_status)
|
exit_without_destructors(exit_status)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue