diff --git a/src/exec.cpp b/src/exec.cpp index 7e51b7ad1..b15398c86 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -117,6 +117,13 @@ char *get_interpreter(const char *command, char *interpreter, size_t buff_size) return NULL; } +/// Assign the terminal to a job. +static void maybe_assign_terminal(const job_t *j) { + if (j->wants_terminal() && j->is_foreground()) { + terminal_give_to_job(j, false /*new job, so not continuing*/); + } +} + /// This function is executed by the child process created by a call to fork(). It should be called /// after \c child_setup_process. It calls execve to replace the fish process image with the command /// specified in \c p. It never returns. Called in a forked child! Do not allocate memory, etc. diff --git a/src/postfork.cpp b/src/postfork.cpp index 5508ae215..0008f9b98 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -134,24 +134,6 @@ bool set_child_group(job_t *j, pid_t child_pid) { return true; } -bool maybe_assign_terminal(const job_t *j) { - if (j->wants_terminal() && j->is_foreground()) { //!OCLINT(early exit) - if (tcgetpgrp(STDIN_FILENO) == j->pgid) { - // We've already assigned the process group control of the terminal when the first - // process in the job was started. There's no need to do so again, and on some platforms - // this can cause an EPERM error. In addition, if we've given control of the terminal to - // a process group, attempting to call tcsetpgrp from the background will cause SIGTTOU - // to be sent to everything in our process group (unless we handle it). - FLOGF(proc_termowner, L"Process group %d already has control of terminal", j->pgid); - } else { - // No need to duplicate the code here, a function already exists that does just this. - return terminal_give_to_job(j, false /*new job, so not continuing*/); - } - } - - return true; -} - int child_setup_process(const job_t *job, process_t *p, const dup2_list_t &dup2s) { // Note we are called in a forked child. for (const auto &act : dup2s.get_actions()) { diff --git a/src/postfork.h b/src/postfork.h index af845f7f9..f813ee268 100644 --- a/src/postfork.h +++ b/src/postfork.h @@ -20,7 +20,6 @@ class process_t; bool set_child_group(job_t *j, pid_t child_pid); // called by parent bool child_set_group(job_t *j, process_t *p); // called by child -bool maybe_assign_terminal(const job_t *j); /// Initialize a new child process. This should be called right away after forking in the child /// process. If job control is enabled for this job, the process is put in the process group of the