diff --git a/src/exec.cpp b/src/exec.cpp index dc6ce6089..110856ff1 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -281,7 +281,7 @@ static bool can_use_posix_spawn_for_job(const std::shared_ptr &job) { if (job->wants_job_control()) { //!OCLINT(collapsible if statements) // We are going to use job control; therefore when we launch this job it will get its own // process group ID. But will it be foregrounded? - if (job->wants_terminal() && job->is_foreground()) { + if (job->should_claim_terminal()) { // It will be foregrounded, so we will call tcsetpgrp(), therefore do not use // posix_spawn. return false; @@ -446,8 +446,7 @@ static bool fork_child_for_process(const std::shared_ptr &job, process_t maybe_t new_termowner{}; p->pid = getpid(); child_set_group(job.get(), p); - child_setup_process(job->wants_terminal() && job->is_foreground() ? job->pgid : INVALID_PID, - true, dup2s); + child_setup_process(job->should_claim_terminal() ? job->pgid : INVALID_PID, true, dup2s); child_action(); DIE("Child process returned control to fork_child lambda!"); } diff --git a/src/proc.cpp b/src/proc.cpp index 2c780abc3..d945bac0d 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -681,8 +681,8 @@ void proc_update_jiffies(parser_t &parser) { int terminal_maybe_give_to_job(const job_t *j, bool continuing_from_stopped) { enum { notneeded = 0, success = 1, error = -1 }; - if (!j->wants_terminal() || !j->is_foreground()) { - // We don't want the job. + if (!j->should_claim_terminal()) { + // The job doesn't want the terminal. return notneeded; } diff --git a/src/proc.h b/src/proc.h index 2133fe160..934d7b48e 100644 --- a/src/proc.h +++ b/src/proc.h @@ -397,8 +397,8 @@ class job_t { /// \return if we want job control. bool wants_job_control() const { return get_flag(job_flag_t::JOB_CONTROL); } - /// \return if this job wants to own the terminal in the foreground. - bool wants_terminal() const { return properties.wants_terminal; } + /// \return if this job should own the terminal when it runs. + bool should_claim_terminal() const { return properties.wants_terminal && is_foreground(); } /// Returns the block IO redirections associated with the job. These are things like the IO /// redirections associated with the begin...end statement.