Replace debug(1) with FLOGF(warning)

This commit is contained in:
Fabian Homborg 2020-01-19 13:38:47 +01:00
parent 384f18a51c
commit 024e03ab1e
15 changed files with 49 additions and 45 deletions

View File

@ -1777,8 +1777,8 @@ static void validate_new_termsize(struct winsize *new_termsize, const environmen
#ifdef HAVE_WINSIZE
// Highly hackish. This seems like it should be moved.
if (is_main_thread() && parser_t::principal_parser().is_interactive()) {
debug(1, _(L"Current terminal parameters have rows and/or columns set to zero."));
debug(1, _(L"The stty command can be used to correct this "
FLOGF(warning, _(L"Current terminal parameters have rows and/or columns set to zero."));
FLOGF(warning, _(L"The stty command can be used to correct this "
L"(e.g., stty rows 80 columns 24)."));
}
#endif
@ -1801,8 +1801,8 @@ static void validate_new_termsize(struct winsize *new_termsize, const environmen
if (new_termsize->ws_col < MIN_TERM_COL || new_termsize->ws_row < MIN_TERM_ROW) {
// Also highly hackisk.
if (is_main_thread() && parser_t::principal_parser().is_interactive()) {
debug(1, _(L"Current terminal parameters set terminal size to unreasonable value."));
debug(1, _(L"Defaulting terminal size to 80x24."));
FLOGF(warning, _(L"Current terminal parameters set terminal size to unreasonable value."));
FLOGF(warning, _(L"Defaulting terminal size to 80x24."));
}
new_termsize->ws_col = DFLT_TERM_COL;
new_termsize->ws_row = DFLT_TERM_ROW;

View File

@ -277,7 +277,7 @@ static void handle_read_limit_change(const environment_t &vars) {
if (!read_byte_limit_var.missing_or_empty()) {
size_t limit = fish_wcstoull(read_byte_limit_var->as_string().c_str());
if (errno) {
debug(1, "Ignoring fish_read_limit since it is not valid");
FLOGF(warning, "Ignoring fish_read_limit since it is not valid");
} else {
read_byte_limit = limit;
}
@ -395,12 +395,12 @@ static bool initialize_curses_using_fallback(const char *term) {
if (term_env == DEFAULT_TERM1 || term_env == DEFAULT_TERM2) return false;
if (session_interactivity() != session_interactivity_t::not_interactive)
debug(1, _(L"Using fallback terminal type '%s'."), term);
FLOGF(warning, _(L"Using fallback terminal type '%s'."), term);
int err_ret;
if (setupterm(const_cast<char *>(term), STDOUT_FILENO, &err_ret) == OK) return true;
if (session_interactivity() != session_interactivity_t::not_interactive) {
debug(1, _(L"Could not set up terminal using the fallback terminal type '%s'."), term);
FLOGF(warning, _(L"Could not set up terminal using the fallback terminal type '%s'."), term);
}
return false;
}
@ -459,12 +459,12 @@ static void init_curses(const environment_t &vars) {
if (setupterm(nullptr, STDOUT_FILENO, &err_ret) == ERR) {
auto term = vars.get(L"TERM");
if (session_interactivity() != session_interactivity_t::not_interactive) {
debug(1, _(L"Could not set up terminal."));
FLOGF(warning, _(L"Could not set up terminal."));
if (term.missing_or_empty()) {
debug(1, _(L"TERM environment variable not set."));
FLOGF(warning, _(L"TERM environment variable not set."));
} else {
debug(1, _(L"TERM environment variable set to '%ls'."), term->as_string().c_str());
debug(1, _(L"Check that this terminal type is supported on this system."));
FLOGF(warning, _(L"TERM environment variable set to '%ls'."), term->as_string().c_str());
FLOGF(warning, _(L"Check that this terminal type is supported on this system."));
}
}

View File

@ -554,7 +554,7 @@ bool env_universal_t::open_temporary_file(const wcstring &directory, wcstring *o
static bool check_duration(double start_time) {
double duration = timef() - start_time;
if (duration > 0.25) {
debug(1, _(L"Locking the universal var file took too long (%.3f seconds)."), duration);
FLOGF(warning, _(L"Locking the universal var file took too long (%.3f seconds)."), duration);
return false;
}
return true;
@ -902,7 +902,7 @@ void env_universal_t::parse_message_30_internal(const wcstring &msgstr, var_tabl
const wchar_t *cursor = msg;
if (!match(&cursor, f3::SETUVAR)) {
debug(1, PARSE_ERR, msg);
FLOGF(warning, PARSE_ERR, msg);
return;
}
// Parse out flags.
@ -922,7 +922,7 @@ void env_universal_t::parse_message_30_internal(const wcstring &msgstr, var_tabl
// Populate the variable with these flags.
if (!populate_1_variable(cursor, flags, vars, storage)) {
debug(1, PARSE_ERR, msg);
FLOGF(warning, PARSE_ERR, msg);
}
}
@ -942,12 +942,12 @@ void env_universal_t::parse_message_2x_internal(const wcstring &msgstr, var_tabl
} else if (match(&cursor, f2x::SET)) {
flags |= 0;
} else {
debug(1, PARSE_ERR, msg);
FLOGF(warning, PARSE_ERR, msg);
return;
}
if (!populate_1_variable(cursor, flags, vars, storage)) {
debug(1, PARSE_ERR, msg);
FLOGF(warning, PARSE_ERR, msg);
}
}
@ -1216,8 +1216,8 @@ class universal_notifier_notifyd_t : public universal_notifier_t {
uint32_t status =
notify_register_file_descriptor(name.c_str(), &this->notify_fd, 0, &this->token);
if (status != NOTIFY_STATUS_OK) {
debug(1, "notify_register_file_descriptor() failed with status %u.", status);
debug(1, "Universal variable notifications may not be received.");
FLOGF(warning, "notify_register_file_descriptor() failed with status %u.", status);
FLOGF(warning, "Universal variable notifications may not be received.");
}
if (this->notify_fd >= 0) {
// Mark us for non-blocking reads, and CLO_EXEC.
@ -1265,7 +1265,7 @@ class universal_notifier_notifyd_t : public universal_notifier_t {
void post_notification() {
uint32_t status = notify_post(name.c_str());
if (status != NOTIFY_STATUS_OK) {
debug(1, "notify_post() failed with status %u. Uvar notifications may not be sent.",
FLOGF(warning, "notify_post() failed with status %u. Uvar notifications may not be sent.",
status);
}
}

View File

@ -66,7 +66,7 @@ void exec_close(int fd) {
while (close(fd) == -1) {
if (errno != EINTR) {
debug(1, FD_ERROR, fd);
FLOGF(warning, FD_ERROR, fd);
wperror(L"close");
break;
}
@ -364,7 +364,7 @@ static bool fork_child_for_process(const std::shared_ptr<job_t> &job, process_t
}
if (pid < 0) {
debug(1, L"Failed to fork %s!\n", fork_type);
FLOGF(warning, L"Failed to fork %s!\n", fork_type);
job_mark_process_as_failed(job, p);
return false;
}
@ -1073,7 +1073,7 @@ bool exec_job(parser_t &parser, const shared_ptr<job_t> &j, const job_lineage_t
if (!p->is_last_in_job) {
auto pipes = make_autoclose_pipes(conflicts);
if (!pipes) {
debug(1, PIPE_ERROR);
FLOGF(warning, PIPE_ERROR);
wperror(L"pipe");
job_mark_process_as_failed(j, p.get());
exec_error = true;

View File

@ -438,7 +438,7 @@ int main(int argc, char **argv) {
// No-exec is prohibited when in interactive mode.
if (opts.is_interactive_session && opts.no_exec) {
debug(1, _(L"Can not use the no-execute mode when running an interactive session"));
FLOGF(warning, _(L"Can not use the no-execute mode when running an interactive session"));
opts.no_exec = false;
}
@ -513,7 +513,7 @@ int main(int argc, char **argv) {
intern(rel_filename.c_str())};
res = reader_read(parser, fd, {});
if (res) {
debug(1, _(L"Error while reading file %ls\n"),
FLOGF(warning, _(L"Error while reading file %ls\n"),
ld.current_filename ? ld.current_filename : _(L"Standard input"));
}
}

View File

@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include "common.h"
#include "env.h"
#include "fish_version.h"
#include "flog.h"
#include "highlight.h"
#include "operation_context.h"
#include "output.h"
@ -64,7 +65,7 @@ static wcstring read_file(FILE *f) {
// Illegal byte sequence. Try to skip past it.
clearerr(f);
int ch = fgetc(f); // for printing the warning, and seeks forward 1 byte.
debug(1, "%s (byte=%X)", std::strerror(errno), ch);
FLOGF(warning, "%s (byte=%X)", std::strerror(errno), ch);
ret = 1;
continue;
} else {

View File

@ -51,6 +51,8 @@ class category_list_t {
category_t debug{L"debug", L"Debugging aid (on by default)", true};
category_t warning{L"warning", L"Warnings (on by default)", true};
category_t exec_job_status{L"exec-job-status", L"Jobs changing status"};
category_t exec_job_exec{L"exec-job-exec", L"Jobs being executed"};

View File

@ -131,7 +131,7 @@ static bool history_file_lock(int fd, int lock_type) {
int retval = flock(fd, lock_type);
double duration = timef() - start_time;
if (duration > 0.25) {
debug(1, _(L"Locking the history file took too long (%.3f seconds)."), duration);
FLOGF(warning, _(L"Locking the history file took too long (%.3f seconds)."), duration);
// we've decided to stop doing any locking behavior
// but make sure we don't leave the file locked!
if (retval == 0 && lock_type != LOCK_UN) {

View File

@ -185,7 +185,7 @@ shared_ptr<io_bufferfill_t> io_bufferfill_t::create(const fd_set_t &conflicts,
// because our fillthread needs to poll to decide if it should shut down, and also accept input
// from direct buffer transfers.
if (make_fd_nonblocking(pipes->read.fd())) {
debug(1, PIPE_ERROR);
FLOGF(warning, PIPE_ERROR);
wperror(L"fcntl");
return nullptr;
}
@ -254,9 +254,9 @@ bool io_chain_t::append_from_specs(const redirection_spec_list_t &specs, const w
autoclose_fd_t file{wopen_cloexec(path, oflags, OPEN_MASK)};
if (!file.valid()) {
if ((oflags & O_EXCL) && (errno == EEXIST)) {
debug(1, NOCLOB_ERROR, spec.target.c_str());
FLOGF(warning, NOCLOB_ERROR, spec.target.c_str());
} else {
debug(1, FILE_ERROR, spec.target.c_str());
FLOGF(warning, FILE_ERROR, spec.target.c_str());
if (should_debug(1)) wperror(L"open");
}
return false;
@ -321,7 +321,7 @@ maybe_t<autoclose_pipes_t> make_autoclose_pipes(const fd_set_t &fdset) {
int pipes[2] = {-1, -1};
if (pipe(pipes) < 0) {
debug(1, PIPE_ERROR);
FLOGF(warning, PIPE_ERROR);
wperror(L"pipe");
return none();
}

View File

@ -14,6 +14,7 @@
#include "common.h"
#include "env.h"
#include "flog.h"
#include "global_safety.h"
#include "maybe.h"
#include "redirection.h"

View File

@ -404,7 +404,7 @@ void outputter_t::writestr(const wchar_t *str) {
size_t len = wcstombs(nullptr, str, 0); // figure amount of space needed
if (len == static_cast<size_t>(-1)) {
debug(1, L"Tried to print invalid wide character string");
FLOGF(warning, L"Tried to print invalid wide character string");
return;
}

View File

@ -291,7 +291,7 @@ void parser_t::emit_profiling(const char *path) const {
// dying (and hence will not fork).
FILE *f = fopen(path, "w");
if (!f) {
debug(1, _(L"Could not write profiling information to file '%s'"), path);
FLOGF(warning, _(L"Could not write profiling information to file '%s'"), path);
} else {
if (std::fwprintf(f, _(L"Time\tSum\tCommand\n"), profile_items.size()) < 0) {
wperror(L"fwprintf");

View File

@ -107,7 +107,7 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path,
break;
}
default: {
debug(1, MISSING_COMMAND_ERR_MSG, next_path.c_str());
FLOGF(warning, MISSING_COMMAND_ERR_MSG, next_path.c_str());
wperror(L"access");
break;
}

View File

@ -743,7 +743,7 @@ int terminal_maybe_give_to_job(const job_t *j, bool continuing_from_stopped) {
if (errno == ENOTTY) {
redirect_tty_output();
}
debug(1, _(L"Could not send job %d ('%ls') with pgid %d to foreground"),
FLOGF(warning, _(L"Could not send job %d ('%ls') with pgid %d to foreground"),
j->job_id(), j->command_wcstr(), j->pgid);
wperror(L"tcsetpgrp");
return error;
@ -771,7 +771,7 @@ int terminal_maybe_give_to_job(const job_t *j, bool continuing_from_stopped) {
redirect_tty_output();
}
debug(1, _(L"Could not send job %d ('%ls') to foreground"), j->job_id(),
FLOGF(warning, _(L"Could not send job %d ('%ls') to foreground"), j->job_id(),
j->preview().c_str());
wperror(L"tcsetattr");
return error;
@ -804,7 +804,7 @@ static bool terminal_return_from_job(job_t *j, int restore_attrs) {
if (tcsetpgrp(STDIN_FILENO, getpgrp()) == -1) {
if (errno == ENOTTY) redirect_tty_output();
debug(1, _(L"Could not return shell to foreground"));
FLOGF(warning, _(L"Could not return shell to foreground"));
wperror(L"tcsetpgrp");
return false;
}
@ -812,7 +812,7 @@ static bool terminal_return_from_job(job_t *j, int restore_attrs) {
// Save jobs terminal modes.
if (tcgetattr(STDIN_FILENO, &j->tmodes)) {
if (errno == EIO) redirect_tty_output();
debug(1, _(L"Could not return shell to foreground"));
FLOGF(warning, _(L"Could not return shell to foreground"));
wperror(L"tcgetattr");
return false;
}
@ -823,7 +823,7 @@ static bool terminal_return_from_job(job_t *j, int restore_attrs) {
if (restore_attrs) {
if (tcsetattr(STDIN_FILENO, TCSADRAIN, &shell_modes) == -1) {
if (errno == EIO) redirect_tty_output();
debug(1, _(L"Could not return shell to foreground"));
FLOGF(warning, _(L"Could not return shell to foreground"));
wperror(L"tcsetattr");
return false;
}

View File

@ -529,7 +529,7 @@ static void term_donate(outputter_t &outp) {
if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_modes_for_external_cmds) == -1) {
if (errno == EIO) redirect_tty_output();
if (errno != EINTR) {
debug(1, _(L"Could not set terminal mode for new job"));
FLOGF(warning, _(L"Could not set terminal mode for new job"));
wperror(L"tcsetattr");
break;
}
@ -544,7 +544,7 @@ static void term_steal() {
if (tcsetattr(STDIN_FILENO, TCSANOW, &shell_modes) == -1) {
if (errno == EIO) redirect_tty_output();
if (errno != EINTR) {
debug(1, _(L"Could not set terminal mode for shell"));
FLOGF(warning, _(L"Could not set terminal mode for shell"));
perror("tcsetattr");
break;
}
@ -1736,7 +1736,7 @@ static void reader_interactive_init(parser_t &parser) {
}
// No TTY, cannot be interactive?
redirect_tty_output();
debug(1, _(L"No TTY for interactive shell (tcgetpgrp failed)"));
FLOGF(warning, _(L"No TTY for interactive shell (tcgetpgrp failed)"));
wperror(L"setpgid");
exit_without_destructors(1);
}
@ -1748,7 +1748,7 @@ static void reader_interactive_init(parser_t &parser) {
const wchar_t *fmt =
_(L"I appear to be an orphaned process, so I am quitting politely. "
L"My pid is %d.");
debug(1, fmt, (int)getpid());
FLOGF(warning, fmt, (int)getpid());
exit_without_destructors(1);
}
@ -1797,7 +1797,7 @@ static void reader_interactive_init(parser_t &parser) {
if (errno == EIO) {
redirect_tty_output();
}
debug(1, _(L"Failed to set startup terminal mode!"));
FLOGF(warning, _(L"Failed to set startup terminal mode!"));
wperror(L"tcsetattr");
}
}
@ -3528,7 +3528,7 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) {
acc.clear();
if (fclose(in_stream)) {
debug(1, _(L"Error while closing input stream"));
FLOGF(warning, _(L"Error while closing input stream"));
wperror(L"fclose");
res = 1;
}
@ -3550,7 +3550,7 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) {
res = 1;
}
} else {
debug(1, _(L"Error while opening input stream"));
FLOGF(warning, _(L"Error while opening input stream"));
wperror(L"fdopen");
res = 1;
}