You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When called from another shell script, fish can't read #3805
N.B. I downloaded a nightly of fish 2.4.0 from SUSE, and behavior is even more frustrating---the shell just hangs trying to read file descriptor 3. Not sure what's up with that (I poked at it with strace -f.)
Would love to have a workaround that enables me to use a fish script as a tool in other scripts. demo-scripts.zip
This is definitely broken. So far I've only gotten as far as finding that it is blocked inside the call to reader_push() from read_interactive(). I'm very surprised no one has noticed this before.
I dug a little deeper. Fish is hanging on the tcsetpgrp() and tcsetattr() calls in reader_interactive_init(). If I just comment those out it gets much farther and reports
<W> fish: Current terminal parameters have rows and/or columns set to zero.
<W> fish: The stty command can be used to correct this (e.g., stty rows 80 columns 24).
It then hangs and you still can't type anything and press [enter] to have it read and echoed. But you can press [ctrl-C] and it will terminate the read.
Basically, fish's handling of the controlling tty, process groups, etc. has a number of quirks. Issue #1258 is definitely relevant. See also #2980.
Reacted by David Adam, quininer, Maksim Kostromin and Vikas kumar
When fish starts, it tries to get into its own process group (setpgid in reader_interactive_init)
After this, it tries to get this group control of the terminal (tcsetpgrp)
That fails if there is still a foreground group that fish is not a member of, by getting a SIGTTOU, which will (unless otherwise handled) stop the process (i.e. fish)
At least in my specific case, the old group continues to stay in the foreground, so if fish hadn't switched there wouldn't be an (apparent) problem
Process groups are removed when no process in them remains, so there should be something left in the old one, presumably the shell that started fish - this also explains why it works with fish, since that gives the processes it starts their own foreground group
So I see two things we could do here:
Don't switch process groups - I can't see a reason for it and it seems to fix at least this case, maybe every one of these
Only perform the tcsetpgrp if there is no (other) foreground group (in that case tcgetpgrp returns "some value larger than 1 that is not presently a process group ID") - in this case we'd have to stop doing stuff we can only do if we're in control
Interestingly the code to start a new process group and grab control of the terminal was removed from fish_pager in 264c065 back in 2006.
Otherwise this behaviour dates back to before the source was under revision control.
I can't see a strong reason that fish tries to start its own process group; the launching process should do that.
There's definitely some confusion in the code; once again shell_pgid is set to a PID, not a PGID. Perhaps the setpgid line was included to fix failing tcsetpgrp calls when handed a PID rather than a PGID??
I suggest we remove the process group switching and trial it in master for a time.
Reacted by Fabian Boehm, Kurtis Rader, S1ahs3r and Jonas De Kegel
Has there been any progress on this? it's quite an annoying behaviour when (what's presumably is causing the issue in #4261 ) fish is set as your default shell
I just ran into a related issue with the tcsetpgrp and tcsetattr in reader_interactive_shell under WSL. This one is a real head scratcher: microsoft/WSL#1653
The same code worked before and after recompiling, it doesn't now.
I've commented out both the tcsetpgrp and tcsetattr calls locally, and would like to trial this in master as discussed above. From my previous work with job control on fish' end, all the child process has to do is try to read or write from/to the terminal and the kernel will take care of the rest, either aborting the process with SIGTTIN or receiving SIGTTOU and hanging until the parent process gives it control of the terminal.
If this takes care of BashOnWindows#1653 and #3805, maybe we can give it a try?
I'll check other shells to see if they have similar code or if they just rely on the parent process to do the right thing.
Activity
krader1961 commentedon Feb 3, 2017
This is definitely broken. So far I've only gotten as far as finding that it is blocked inside the call to
reader_push()fromread_interactive(). I'm very surprised no one has noticed this before.krader1961 commentedon Feb 3, 2017
I dug a little deeper. Fish is hanging on the
tcsetpgrp()andtcsetattr()calls inreader_interactive_init(). If I just comment those out it gets much farther and reportsIt then hangs and you still can't type anything and press [enter] to have it read and echoed. But you can press [ctrl-C] and it will terminate the
read.Basically, fish's handling of the controlling tty, process groups, etc. has a number of quirks. Issue #1258 is definitely relevant. See also #2980.
faho commentedon Mar 31, 2017
So, here's what I found out:
When fish starts, it tries to get into its own process group (
setpgidin reader_interactive_init)After this, it tries to get this group control of the terminal (
tcsetpgrp)That fails if there is still a foreground group that fish is not a member of, by getting a SIGTTOU, which will (unless otherwise handled) stop the process (i.e. fish)
At least in my specific case, the old group continues to stay in the foreground, so if fish hadn't switched there wouldn't be an (apparent) problem
Process groups are removed when no process in them remains, so there should be something left in the old one, presumably the shell that started fish - this also explains why it works with fish, since that gives the processes it starts their own foreground group
So I see two things we could do here:
Don't switch process groups - I can't see a reason for it and it seems to fix at least this case, maybe every one of these
Only perform the
tcsetpgrpif there is no (other) foreground group (in that casetcgetpgrpreturns "some value larger than 1 that is not presently a process group ID") - in this case we'd have to stop doing stuff we can only do if we're in control@krader1961: Any opinion?
zanchey commentedon Jun 19, 2017
Interestingly the code to start a new process group and grab control of the terminal was removed from
fish_pagerin 264c065 back in 2006.Otherwise this behaviour dates back to before the source was under revision control.
I can't see a strong reason that fish tries to start its own process group; the launching process should do that.
There's definitely some confusion in the code; once again
shell_pgidis set to a PID, not a PGID. Perhaps thesetpgidline was included to fix failingtcsetpgrpcalls when handed a PID rather than a PGID??I suggest we remove the process group switching and trial it in master for a time.
faho commentedon Jun 20, 2017
Yes, please!
jlsjonas commentedon Aug 14, 2017
Has there been any progress on this? it's quite an annoying behaviour when (what's presumably is causing the issue in #4261 ) fish is set as your default shell
mqudsi commentedon Aug 20, 2017
I just ran into a related issue with the
tcsetpgrpandtcsetattrinreader_interactive_shellunder WSL. This one is a real head scratcher: microsoft/WSL#1653The same code worked before and after recompiling, it doesn't now.
I've commented out both the
tcsetpgrpandtcsetattrcalls locally, and would like to trial this in master as discussed above. From my previous work with job control on fish' end, all the child process has to do is try to read or write from/to the terminal and the kernel will take care of the rest, either aborting the process withSIGTTINor receivingSIGTTOUand hanging until the parent process gives it control of the terminal.If this takes care of BashOnWindows#1653 and #3805, maybe we can give it a try?
I'll check other shells to see if they have similar code or if they just rely on the parent process to do the right thing.
Fixes job handling involving functions and terminal control
Fixes job handling involving functions and terminal control
No longer put fish in own process group on startup
IsaacOscar commentedon Mar 10, 2018
19 remaining items
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Overhaul job and terminal control
Partially revert 55b3c45 to create pgrp when launched with invalid pgrp
Partially revert 55b3c45 to create pgrp when launched with invalid pgrp
Overhaul job and terminal control
Partially revert 55b3c45 to create pgrp when launched with invalid pgrp