Make job_control_mode a static variable with accessors

This commit is contained in:
ridiculousfish 2019-04-29 23:08:01 -07:00
parent 9fb98baba6
commit e10838d5d6
4 changed files with 15 additions and 6 deletions

View file

@ -309,6 +309,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.out.append_format(_(L"This is not a login shell\n")); streams.out.append_format(_(L"This is not a login shell\n"));
} }
auto job_control_mode = get_job_control_mode();
streams.out.append_format( streams.out.append_format(
_(L"Job control: %ls\n"), _(L"Job control: %ls\n"),
job_control_mode == job_control_t::interactive job_control_mode == job_control_t::interactive
@ -335,7 +336,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
opts.new_job_control_mode = new_mode; opts.new_job_control_mode = new_mode;
} }
assert(opts.new_job_control_mode && "Should have a new mode"); assert(opts.new_job_control_mode && "Should have a new mode");
job_control_mode = *opts.new_job_control_mode; set_job_control_mode(*opts.new_job_control_mode);
break; break;
} }
case STATUS_FEATURES: { case STATUS_FEATURES: {
@ -407,17 +408,17 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
} }
case STATUS_IS_FULL_JOB_CTRL: { case STATUS_IS_FULL_JOB_CTRL: {
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd) CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
retval = job_control_mode != job_control_t::all; retval = get_job_control_mode() != job_control_t::all;
break; break;
} }
case STATUS_IS_INTERACTIVE_JOB_CTRL: { case STATUS_IS_INTERACTIVE_JOB_CTRL: {
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd) CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
retval = job_control_mode != job_control_t::interactive; retval = get_job_control_mode() != job_control_t::interactive;
break; break;
} }
case STATUS_IS_NO_JOB_CTRL: { case STATUS_IS_NO_JOB_CTRL: {
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd) CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
retval = job_control_mode != job_control_t::none; retval = get_job_control_mode() != job_control_t::none;
break; break;
} }
case STATUS_STACK_TRACE: { case STATUS_STACK_TRACE: {

View file

@ -1228,6 +1228,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
shared_ptr<job_t> job = std::make_shared<job_t>(acquire_job_id(), block_io, parent_job); shared_ptr<job_t> job = std::make_shared<job_t>(acquire_job_id(), block_io, parent_job);
job->tmodes = tmodes; job->tmodes = tmodes;
auto job_control_mode = get_job_control_mode();
job->set_flag(job_flag_t::JOB_CONTROL, job->set_flag(job_flag_t::JOB_CONTROL,
(job_control_mode == job_control_t::all) || (job_control_mode == job_control_t::all) ||
((job_control_mode == job_control_t::interactive) && shell_is_interactive())); ((job_control_mode == job_control_t::interactive) && shell_is_interactive()));

View file

@ -38,6 +38,7 @@
#include "common.h" #include "common.h"
#include "event.h" #include "event.h"
#include "fallback.h" // IWYU pragma: keep #include "fallback.h" // IWYU pragma: keep
#include "global_safety.h"
#include "io.h" #include "io.h"
#include "output.h" #include "output.h"
#include "parse_tree.h" #include "parse_tree.h"
@ -70,10 +71,15 @@ bool is_block = false;
bool is_breakpoint = false; bool is_breakpoint = false;
bool is_login = false; bool is_login = false;
int is_event = 0; int is_event = 0;
job_control_t job_control_mode = job_control_t::interactive;
int no_exec = 0; int no_exec = 0;
bool have_proc_stat = false; bool have_proc_stat = false;
static relaxed_atomic_t<job_control_t> job_control_mode{job_control_t::interactive};
job_control_t get_job_control_mode() { return job_control_mode; }
void set_job_control_mode(job_control_t mode) { job_control_mode = mode; }
static int is_interactive = -1; static int is_interactive = -1;
bool shell_is_interactive() { bool shell_is_interactive() {

View file

@ -468,7 +468,8 @@ job_list_t &jobs();
/// The current job control mode. /// The current job control mode.
/// ///
/// Must be one of job_control_t::all, job_control_t::interactive and job_control_t::none. /// Must be one of job_control_t::all, job_control_t::interactive and job_control_t::none.
extern job_control_t job_control_mode; job_control_t get_job_control_mode();
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 /// 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 /// verifier mode where fish tries to validate the syntax of a file but doesn't actually do