mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-29 22:41:16 -03:00
Acquire tty if interactive when running builtins
When running a builtin, if we are an interactive shell and stdin is a tty, then acquire ownership of the terminal via tcgetpgrp() before running the builtin, and set it back after. Fixes #4540
This commit is contained in:
11
src/proc.cpp
11
src/proc.cpp
@@ -870,6 +870,17 @@ bool terminal_give_to_job(const job_t *j, bool cont) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pid_t terminal_acquire_before_builtin() {
|
||||
pid_t selfpid = getpid();
|
||||
pid_t current_owner = tcgetpgrp(STDIN_FILENO);
|
||||
if (current_owner >= 0 && current_owner != selfpid) {
|
||||
if (tcsetpgrp(STDIN_FILENO, selfpid) == 0) {
|
||||
return current_owner;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Returns control of the terminal to the shell, and saves the terminal attribute state to the job,
|
||||
/// so that we can restore the terminal ownership to the job at a later time.
|
||||
static bool terminal_return_from_job(job_t *j) {
|
||||
|
||||
Reference in New Issue
Block a user