mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
Minor refactoring of logic around when a job wants to claim the terminal
Introduce should_claim_terminal() which encapsulates an && exprsesion which was previously repeated a lot.
This commit is contained in:
parent
d577eb4aaa
commit
8181883111
3 changed files with 6 additions and 7 deletions
|
@ -281,7 +281,7 @@ static bool can_use_posix_spawn_for_job(const std::shared_ptr<job_t> &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_t> &job, process_t
|
|||
maybe_t<pid_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!");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue