diff --git a/src/builtin.cpp b/src/builtin.cpp index 43419df69..a87b7ef5e 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -156,7 +156,7 @@ wcstring builtin_help_get(parser_t &parser, io_streams_t &streams, const wchar_t UNUSED(parser); UNUSED(streams); // This won't ever work if no_exec is set. - if (no_exec) return wcstring(); + if (no_exec()) return wcstring(); wcstring_list_t lst; wcstring out; diff --git a/src/exec.cpp b/src/exec.cpp index 8b6d884e6..2dcca1198 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -1019,7 +1019,7 @@ bool exec_job(parser_t &parser, shared_ptr j) { bool exec_error = false; // If fish was invoked with -n or --no-execute, then no_exec will be set and we do nothing. - if (no_exec) { + if (no_exec()) { return true; } diff --git a/src/fish.cpp b/src/fish.cpp index 2ce6f0828..afc58c4bd 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -310,7 +310,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) { break; } case 'n': { - no_exec = 1; + set_no_exec(true); break; } case 1: { @@ -390,9 +390,9 @@ int main(int argc, char **argv) { my_optind = fish_parse_opt(argc, argv, &opts); // No-exec is prohibited when in interactive mode. - if (is_interactive_session && no_exec) { + if (is_interactive_session && no_exec()) { debug(1, _(L"Can not use the no-execute mode when running an interactive session")); - no_exec = 0; + set_no_exec(false); } // Only save (and therefore restore) the fg process group if we are interactive. See issues diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 185012d3b..8ac906ab8 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -601,7 +601,7 @@ parse_execution_result_t parse_execution_context_t::run_while_statement( // no_exec means that fish was invoked with -n or --no-execute. If set, we allow the loop to // not-execute once so its contents can be checked, and then break. - if (no_exec) { + if (no_exec()) { break; } } @@ -959,7 +959,7 @@ bool parse_execution_context_t::determine_io_chain(tnode_tvars(), parser->shared()); if (!target_expanded || target.empty()) { // TODO: Improve this error message. diff --git a/src/proc.cpp b/src/proc.cpp index 8dc66a0e1..b6f284e3e 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -58,7 +58,10 @@ bool is_block = false; bool is_breakpoint = false; bool is_login = false; int is_event = 0; -int no_exec = 0; + +static relaxed_atomic_bool_t s_no_exec; +bool no_exec() { return s_no_exec; } +void set_no_exec(bool flag) { s_no_exec = flag; } bool have_proc_stat() { // Check for /proc/self/stat to see if we are running with Linux-style procfs. diff --git a/src/proc.h b/src/proc.h index 8097f96e9..d07a5ecb4 100644 --- a/src/proc.h +++ b/src/proc.h @@ -448,7 +448,8 @@ void set_job_control_mode(job_control_t mode); /// If this flag is set, fish will never fork or run execve. It is used to put fish into a syntax /// verifier mode where fish tries to validate the syntax of a file but doesn't actually do /// anything. -extern int no_exec; +bool no_exec(); +void set_no_exec(bool flag); /// Notify the user about stopped or terminated jobs, and delete completed jobs from the job list. /// If \p interactive is set, allow removing interactive jobs; otherwise skip them.