Skip to content

Acquire tty if interactive when running builtins - #5133

Merged
ridiculousfish merged 1 commit into
fish-shell:masterfrom
ridiculousfish:grab_tty
Aug 12, 2018
Merged

ridiculousfish merged 1 commit into
fish-shell:masterfrom
ridiculousfish:grab_tty

Conversation

@ridiculousfish

Copy link
Copy Markdown
Member

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.

I don't know how principled this fix is because job control is quite confusing.
But it's certainly true that when running builtins interactively, we expect to own
the terminal, so I don't believe this can make anything worse.

Fixes #4540

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 fish-shell#4540
@zanchey

zanchey commented Aug 7, 2018

Copy link
Copy Markdown
Member

Looks good here on Debian 8 (Linux 4.9.0-5-amd64, Debian GLIBC 2.24-11+deb9u3, tmux 2.3).

@ridiculousfish
ridiculousfish merged commit fa66ac8 into fish-shell:master Aug 12, 2018
@ridiculousfish ridiculousfish added this to the fish-3.0 milestone Aug 12, 2018
@zx8

zx8 commented Aug 12, 2018

Copy link
Copy Markdown

Doesn't seem to fix #4540 for me, presumably something to do with the fact that my prompt shows Git info:

$ read | cat
read>
$ e<E> fish: More than one job in foreground: job 1: 'command git rev-parse --git-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree HEAD 2>/dev/null' job 2: 'pwd | sed -r \
            -e "s@^$HOME(\$|/)@~\1@" \
            -e 's@^/private/@/@''
<E> fish: Errors detected, shutting down. Break on sanity_lose() to debug.

@faho faho mentioned this pull request Aug 13, 2018
ridiculousfish added a commit that referenced this pull request Aug 18, 2018
Fix #5133 changed builtins to acquire the terminal, but this regressed
caused fish to be stopped when running in background via `sudo fish`.
Fix this by only acquiring the terminal if the terminal was owned by the
builtin's pgroup.

Fixes #5147
ridiculousfish added a commit to ridiculousfish/fish-shell that referenced this pull request Jan 31, 2020
fish has some unprincipled code that attempts to tcsetpgrp() to own the
terminal before running a builtin; this was added because 'read' might
want to read from the terminal. I added this code before fully
understanding how process groups and terminals work. A better fix would
be to ensure that fish is marked as the pgroup leader in the job when
the builtin is the first process in the job, and we do that now.

Courageously back out the changes to grab the terminal; see fish-shell#5147 and
also fish-shell#5133.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 17, 2020
@ridiculousfish
ridiculousfish deleted the grab_tty branch August 22, 2020 18:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read | cat crashes fish

3 participants