From ff1d651415a2752e82ec417294f9bdf8c234c10f Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sat, 14 May 2016 20:35:54 -0700 Subject: rename get_is_interactive and remove stupid test I'm doing this as part of fixing issue #2980. The code for managing tty modes and job control is a horrible mess. This is a very tiny step towards improving the situation. --- src/builtin.cpp | 6 +++--- src/parse_execution.cpp | 6 +++--- src/parse_tree.cpp | 2 +- src/parser.cpp | 6 +++--- src/proc.cpp | 7 ++++--- src/proc.h | 2 +- src/reader.cpp | 6 +++--- src/sanity.cpp | 3 +-- src/signal.cpp | 8 +++----- 9 files changed, 22 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/builtin.cpp b/src/builtin.cpp index db528aa0..e5261cb4 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -181,7 +181,7 @@ void builtin_print_help(parser_t &parser, io_streams_t &streams, const wchar_t * screen_height = common_get_height(); lines = count_char(str, L'\n'); - if (!get_is_interactive() || (lines > 2 * screen_height / 3)) { + if (!shell_is_interactive() || (lines > 2 * screen_height / 3)) { wchar_t *pos; int cut = 0; int i; @@ -2368,7 +2368,7 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { argv[0], dir_in.c_str()); } - if (!get_is_interactive()) { + if (!shell_is_interactive()) { streams.err.append(parser.current_line()); } @@ -2385,7 +2385,7 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { streams.err.append_format(_(L"%ls: '%ls' is not a directory\n"), argv[0], dir.c_str()); } - if (!get_is_interactive()) { + if (!shell_is_interactive()) { streams.err.append(parser.current_line()); } diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 13e49924..cca0b8d9 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -1183,7 +1183,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t // Get terminal modes. struct termios tmodes = {}; - if (get_is_interactive()) { + if (shell_is_interactive()) { if (tcgetattr(STDIN_FILENO, &tmodes)) { // Need real error handling here. wperror(L"tcgetattr"); @@ -1254,14 +1254,14 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t j->tmodes = tmodes; job_set_flag(j, JOB_CONTROL, (job_control_mode == JOB_CONTROL_ALL) || - ((job_control_mode == JOB_CONTROL_INTERACTIVE) && (get_is_interactive()))); + ((job_control_mode == JOB_CONTROL_INTERACTIVE) && (shell_is_interactive()))); job_set_flag(j, JOB_FOREGROUND, !tree.job_should_be_backgrounded(job_node)); job_set_flag(j, JOB_TERMINAL, job_get_flag(j, JOB_CONTROL) && !is_subshell && !is_event); job_set_flag(j, JOB_SKIP_NOTIFICATION, - is_subshell || is_block || is_event || !get_is_interactive()); + is_subshell || is_block || is_event || !shell_is_interactive()); // Tell the current block what its job is. This has to happen before we populate it (#1394). parser->current_block()->job = j; diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 1ec7aa43..8bd7d4f9 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -139,7 +139,7 @@ wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring } wcstring parse_error_t::describe(const wcstring &src) const { - return this->describe_with_prefix(src, wcstring(), get_is_interactive(), false); + return this->describe_with_prefix(src, wcstring(), shell_is_interactive(), false); } void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) { diff --git a/src/parser.cpp b/src/parser.cpp index 47d1994f..17d845ab 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -522,7 +522,7 @@ wcstring parser_t::current_line() { wcstring prefix; // If we are not going to print a stack trace, at least print the line number and filename. - if (!get_is_interactive() || is_function()) { + if (!shell_is_interactive() || is_function()) { if (file) { append_format(prefix, _(L"%ls (line %d): "), user_presentable_path(file).c_str(), lineno); @@ -533,7 +533,7 @@ wcstring parser_t::current_line() { } } - bool is_interactive = get_is_interactive(); + bool is_interactive = shell_is_interactive(); bool skip_caret = is_interactive && !is_function(); // Use an error with empty text. @@ -756,7 +756,7 @@ void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &erro if (!errors.empty()) { const parse_error_t &err = errors.at(0); - const bool is_interactive = get_is_interactive(); + const bool is_interactive = shell_is_interactive(); // Determine if we want to try to print a caret to point at the source error. The // err.source_start <= src.size() check is due to the nasty way that slices work, which is diff --git a/src/proc.cpp b/src/proc.cpp index 305be0df..2e370754 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -101,10 +101,11 @@ static int is_interactive = -1; static bool proc_had_barrier = false; -int get_is_interactive(void) { +bool shell_is_interactive(void) { ASSERT_IS_MAIN_THREAD(); - // is_interactive is initialized to -1; ensure someone has popped/pushed it before then. - assert(is_interactive >= 0); + // is_interactive is statically initialized to -1. Ensure it has been dynamically set + // before we're called. + assert(is_interactive != -1); return is_interactive > 0; } diff --git a/src/proc.h b/src/proc.h index 3d24405c..704f8719 100644 --- a/src/proc.h +++ b/src/proc.h @@ -232,7 +232,7 @@ extern int is_subshell; extern int is_block; /// Whether we are reading from the keyboard right now. -int get_is_interactive(void); +bool shell_is_interactive(void); /// Whether this shell is attached to the keyboard at all. extern int is_interactive_session; diff --git a/src/reader.cpp b/src/reader.cpp index bd428871..235086c9 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1686,7 +1686,7 @@ static void reader_interactive_destroy() { void reader_sanity_check() { // Note: 'data' is non-null if we are interactive, except in the testing environment. - if (get_is_interactive() && data != NULL) { + if (shell_is_interactive() && data != NULL) { if (data->command_line.position > data->command_line.size()) sanity_lose(); if (data->colors.size() != data->command_line.size()) sanity_lose(); if (data->indents.size() != data->command_line.size()) sanity_lose(); @@ -2217,7 +2217,7 @@ static void reader_super_highlight_me_plenty(int match_highlight_pos_adjust, boo } bool shell_is_exiting() { - if (get_is_interactive()) + if (shell_is_interactive()) return job_list_is_empty() && data != NULL && data->end_loop; else return end_loop; @@ -3412,7 +3412,7 @@ int reader_read(int fd, const io_chain_t &io) { int inter = ((fd == STDIN_FILENO) && isatty(STDIN_FILENO)); proc_push_interactive(inter); - res = get_is_interactive() ? read_i() : read_ni(fd, io); + res = shell_is_interactive() ? read_i() : read_ni(fd, io); // If the exit command was called in a script, only exit the script, not the program. if (data) data->end_loop = 0; diff --git a/src/sanity.cpp b/src/sanity.cpp index d6da40f4..895112ca 100644 --- a/src/sanity.cpp +++ b/src/sanity.cpp @@ -18,8 +18,7 @@ void sanity_lose() { } int sanity_check() { - if (!insane) - if (get_is_interactive()) history_sanity_check(); + if (!insane && shell_is_interactive()) history_sanity_check(); if (!insane) reader_sanity_check(); if (!insane) kill_sanity_check(); if (!insane) proc_sanity_check(); diff --git a/src/signal.cpp b/src/signal.cpp index f5c356f7..f232b01c 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -249,8 +249,6 @@ void signal_reset_handlers() { void signal_set_handlers() { struct sigaction act; - if (get_is_interactive() == -1) return; - sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; act.sa_sigaction = &default_handler; @@ -267,9 +265,9 @@ void signal_set_handlers() { // Ignore sigpipe, which we may get from the universal variable notifier. sigaction(SIGPIPE, &act, 0); - if (get_is_interactive()) { - // Interactive mode. Ignore interactive signals. We are a shell, we know whats best for the - // user. + if (shell_is_interactive()) { + // Interactive mode. Ignore interactive signals. We are a shell, we know what is best for + // the user. act.sa_handler = SIG_IGN; sigaction(SIGINT, &act, 0); -- cgit v1.2.3