mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 05:41:16 -03:00
Simplify maybe_assign_terminal()
Move this out of postfork, it is not called after fork.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user