-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When called from another shell script, fish can't read #3805
Comments
This is definitely broken. So far I've only gotten as far as finding that it is blocked inside the call to |
I dug a little deeper. Fish is hanging on the
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 Basically, fish's handling of the controlling tty, process groups, etc. has a number of quirks. Issue #1258 is definitely relevant. See also #2980. |
So, here's what I found out:
So I see two things we could do here:
@krader1961: Any opinion? |
Interestingly the code to start a new process group and grab control of the terminal was removed from 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 I suggest we remove the process group switching and trial it in master for a time. |
Yes, please! |
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 The same code worked before and after recompiling, it doesn't now. I've commented out both the 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. |
While the idiomatic fix to fish' myriad of job control issues would be to parse all functions prior to beginning the job pipeline so that everything in the command line can be executed in the context of a single job, that would require a huge effort to rewrite the core job flow in fish and does not make sense at this time. Instead, this patch fixes fish-shell#3952 and fish-shell#206 (but notably not fish-shell#4238) by having jobs that are part of a single command pipeline, including those that are functions executing external commands, use the same process group. This prevents a (parent|child) from crashing with SIGTTIN or hanging at SIGTTOU because it has a different process group than the process currently in control of the terminal. Additionally, since this fix involves removing the code that forces fish to run in its own process group (which IMHO never made sense, as job control is the job of the shell, not the process being launched), it also fixes fish-shell#3805 and works around BashOnWindows#1653.
While the idiomatic fix to fish' myriad of job control issues would be to parse all functions prior to beginning the job pipeline so that everything in the command line can be executed in the context of a single job, that would require a huge effort to rewrite the core job flow in fish and does not make sense at this time. Instead, this patch fixes fish-shell#3952 and fish-shell#206 (but notably not fish-shell#4238) by having jobs that are part of a single command pipeline, including those that are functions executing external commands, use the same process group. This prevents a (parent|child) from crashing with SIGTTIN or hanging at SIGTTOU because it has a different process group than the process currently in control of the terminal. Additionally, since this fix involves removing the code that forces fish to run in its own process group (which IMHO never made sense, as job control is the job of the shell, not the process being launched), it also fixes fish-shell#3805 and works around BashOnWindows#1653.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should elimante the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should elimante the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should elimante the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes #4178. Fixes #3805. Fixes #5210.
If fish detects that it was started with a pgrp of 0 (which appears to oddly be the case when run under firejail), create new process group for fish and give it control of the terminal. This selectively reverts 55b3c45 in cases where an invalid pgrp is detected. Note that this is known to cause problems in other cases, such as fish-shell#3805 and microsoft/WSL#1653, although the former may have been ameliorated or even addressed by the recent job control overhaul, so that's why we are careful to only assign fish to its own pgroup if an invalid pgroup was detected and not as the normal case.
If fish detects that it was started with a pgrp of 0 (which appears to oddly be the case when run under firejail), create new process group for fish and give it control of the terminal. This selectively reverts 55b3c45 in cases where an invalid pgrp is detected. Note that this is known to cause problems in other cases, such as #3805 and microsoft/WSL#1653, although the former may have been ameliorated or even addressed by the recent job control overhaul, so that's why we are careful to only assign fish to its own pgroup if an invalid pgroup was detected and not as the normal case.
* Instead of reaping all child processes when we receive a SIGCHLD, try reaping only processes belonging to process groups from fully- constructed jobs, which should eliminate the need for the keepalive process entirely (WSL's lack of zombies not withstanding) as now completed processes are not reaped until the job has been fully constructed (i.e. all processes launched), which means their process group should still be around for new processes to join. * When `tcgetpgrp()` calls return 0, attempt to `tcsetpgrp()` before invoking failure handling code. * When forking a builtin and not running interactively, do not bail if unable to set/restore terminal attributes. Fixes fish-shell#4178. Fixes fish-shell#3805. Fixes fish-shell#5210.
If fish detects that it was started with a pgrp of 0 (which appears to oddly be the case when run under firejail), create new process group for fish and give it control of the terminal. This selectively reverts 55b3c45 in cases where an invalid pgrp is detected. Note that this is known to cause problems in other cases, such as fish-shell#3805 and microsoft/WSL#1653, although the former may have been ameliorated or even addressed by the recent job control overhaul, so that's why we are careful to only assign fish to its own pgroup if an invalid pgroup was detected and not as the normal case.
sh -c 'env HOME=$(mktemp -d) fish'
)?fish version installed (
fish --version
): fish, version 2.3.1OS/terminal used: Debian Linux (jessie), xterm
I wrote a script using
#!/usr/bin/fish
. The script callsread
. Works fine from command line but not when called from another script.Reproduction steps
Scripts are attached in a zip file, but it may be easier to view source here.
Here is
fish-read
:and here is
call-fish-read
: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
May be related to #3223 and #1258.
The text was updated successfully, but these errors were encountered: