mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-22 21:59:29 +08:00
Revert "terminal_give_to_job() was bypassing the cont
branch"
This reverts commit b27217e106
.
It was meant for the major branch.
This commit is contained in:
parent
bd601019fe
commit
7b443ac1d3
35
src/proc.cpp
35
src/proc.cpp
|
@ -789,8 +789,6 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal_block(true);
|
|
||||||
|
|
||||||
//Previously, terminal_give_to_job was being called for each process in a job, hence all the comments
|
//Previously, terminal_give_to_job was being called for each process in a job, hence all the comments
|
||||||
//and warnings below. It is now only called for the first process in a job.t d
|
//and warnings below. It is now only called for the first process in a job.t d
|
||||||
|
|
||||||
|
@ -803,10 +801,11 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
||||||
//for SIGTTOU are installed. Read: http://curiousthing.org/sigttin-sigttou-deep-dive-linux
|
//for SIGTTOU are installed. Read: http://curiousthing.org/sigttin-sigttou-deep-dive-linux
|
||||||
//In all cases, our goal here was just to hand over control of the terminal to this process group,
|
//In all cases, our goal here was just to hand over control of the terminal to this process group,
|
||||||
//which is a no-op if it's already been done.
|
//which is a no-op if it's already been done.
|
||||||
if (tcgetpgrp(STDIN_FILENO) == j->pgid) {
|
auto previous_owner = tcgetpgrp(STDIN_FILENO);
|
||||||
|
if (previous_owner == j->pgid) {
|
||||||
debug(2, L"Process group %d already has control of terminal\n", j->pgid);
|
debug(2, L"Process group %d already has control of terminal\n", j->pgid);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
debug(4, L"Attempting bring process group to foreground via tcsetpgrp for job->pgid %d\n", j->pgid);
|
debug(4, L"Attempting bring process group to foreground via tcsetpgrp for job->pgid %d\n", j->pgid);
|
||||||
debug(4, L"caller session id: %d, pgid %d has session id: %d\n", getsid(0), j->pgid, getsid(j->pgid));
|
debug(4, L"caller session id: %d, pgid %d has session id: %d\n", getsid(0), j->pgid, getsid(j->pgid));
|
||||||
|
|
||||||
|
@ -819,35 +818,19 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
||||||
//thing is that we can guarantee the process isn't going to exit while we wait (which would cause us to
|
//thing is that we can guarantee the process isn't going to exit while we wait (which would cause us to
|
||||||
//possibly block indefinitely).
|
//possibly block indefinitely).
|
||||||
|
|
||||||
while (tcsetpgrp(STDIN_FILENO, j->pgid) != 0) {
|
signal_block(true);
|
||||||
if (errno == EINTR) {
|
int result = -1;
|
||||||
//always retry on EINTR
|
errno = EINTR;
|
||||||
|
while (result == -1 && (errno == EINTR || errno == EPERM)) {
|
||||||
|
result = tcsetpgrp(STDIN_FILENO, j->pgid);
|
||||||
}
|
}
|
||||||
else if (errno == EPERM) {
|
if (result == -1) {
|
||||||
//so long as this isn't because the process group is dead
|
|
||||||
int wait_result = waitpid(-1 * j->pgid, &wait_result, WNOHANG);
|
|
||||||
if (wait_result == -1) {
|
|
||||||
//everyone in the process group has exited
|
|
||||||
//The only way that can happen is if the very last process in the group terminated, and didn't need
|
|
||||||
//to access the terminal, otherwise it would have hung waiting for terminal IO. We can ignore this.
|
|
||||||
//Note that -1 is technically an "error" for waitpid in the sense that an invalid argument was specified
|
|
||||||
//because no such process group exists any longer.
|
|
||||||
//a "success" result would mean processes from the group still exist but is still running in some state
|
|
||||||
//or the other.
|
|
||||||
debug(3, L"terminal_give_to_job(): tcsetpgrp called but process group %d has terminated.\n", j->pgid);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
debug(2, L"terminal_give_to_job(): EPERM.\n", j->pgid);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (errno == ENOTTY) redirect_tty_output();
|
if (errno == ENOTTY) redirect_tty_output();
|
||||||
debug(1, _(L"terminal_give_to_job(): Could not send job %d ('%ls') with pgid %d to foreground"), j->job_id, j->command_wcstr(), j->pgid);
|
debug(1, _(L"terminal_give_to_job(): Could not send job %d ('%ls') with pgid %d to foreground"), j->job_id, j->command_wcstr(), j->pgid);
|
||||||
wperror(L"tcsetpgrp");
|
wperror(L"tcsetpgrp");
|
||||||
signal_unblock(true);
|
signal_unblock(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cont) {
|
if (cont) {
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user