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
[ctrl-C] fails to terminate job when read
is involved
#4238
Comments
The "inotifywait" and cat | while read line; echo $line; end exhibits the same issue (well, after you enter something - I think I'm unsure of the root cause. |
It actually doesn't. Which leads me to a theory... @silvio: Can you try your command and quit before the I'm guessing the issue is that the first |
Yep, that's it. The issue is, as soon as the first This is easy enough to work around (so trivial in fact that I can write the code), but I'm unsure if that is something we want to keep in the code. There's numerous problems with our mapping of processes to jobs, which should be fixed properly. |
read
is involved
Pretty close to 100% certain this is a duplicate of #3805. |
I'm pretty sure it's not. It's another piece of the job control/process group pile of REDACTED, but not quite the same. As I said, I have something that fixes this: commit 8c02fc42f5189883ee83ef26bf908d9b1da0eda0
Author: Fabian Homborg <FHomborg@gmail.com>
Date: Mon Jul 24 18:50:00 2017 +0200
Only return control of term if all foreground jobs quit
Fixes #4238.
diff --git a/src/proc.cpp b/src/proc.cpp
index 063f01fe..3e24d3d8 100644
--- a/src/proc.cpp
+++ b/src/proc.cpp
@@ -970,7 +970,17 @@ void job_continue(job_t *j, bool cont) {
// Put the shell back in the foreground.
if (j->get_flag(JOB_TERMINAL) && j->get_flag(JOB_FOREGROUND)) {
- terminal_return_from_job(j);
+ // HACK: Only return if this is the last foreground job
+ job_iterator_t jobs;
+ bool have_job = false;
+ for (auto job = jobs.next(); job; job = jobs.next()) {
+ if (job != j && job->get_flag(JOB_TERMINAL) && job->get_flag(JOB_FOREGROUND)) {
+ have_job = true;
+ }
+ }
+ if (have_job == false) {
+ terminal_return_from_job(j);
+ }
}
}
} The problem is that, when fish starts Now, when the As you see above, what my patch does is only do the returning if all jobs that want control over the terminal have finished. The proper solution would probably not consider the job finished in the first place. The second read would take the place of the first (in the same job) and it would just continue. Does that make any sense? |
Right. When I said it's a duplicate of #3805 I didn't mean to imply the broken behavior (i.e., the symptom) was the same only that the underlying reason for both problems likely has the same root cause: our weird job control management. I'm nervous about making piecemeal changes. I took a quick glance at your change and it looks okay as does your reasoning about the problem. So it's probably worth turning into a PR and asking people to build and test it on their systems. |
hi @faho , I have tested your #4242 with commit "586166b75512339b9a5366fc80477db3b0cddabf". The behaviour has changed but has not repaired the problem. I have slightly adopted my testcase to give you a test with out cargo tools in your hand. Its now usable to work in the fish-shell repository. Start it and do a touch somewhere in inotifywait -mrq -e close_write src/ --format "%w/%f" | while read CHANGEDFILE
clear
make
echo "DONE"
end The new behavior is:
|
Note: Technically, it does not end. inotifywait continues running. Okay, so the issue there is that This is going to need some major reworking - my gut still tells me that the entire thing should be one job (including |
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.
When a foreground job that had control of the terminal has completed, assign control of the terminal to the next foreground job in the pipeline (if any) prior to giving control of the terminal back to the shell. This is similar to @faho's fix for fish-shell#4238 but will handle situations where the next job in the chain is not in the same process group (so commands executed by functions, etc can take control of the terminal, too). Fixes fish-shell#4238. Testing obviously needed.
fish version: 2.6.0
uname: Linux xxx 4.11.7-041107-generic #201706240231 SMP Sat Jun 24 06:33:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
TERM: screen-256color (tmux)
The problem occurs with a plain shell too.
I use a
inotifywait
-while-end call for cyclic compiling (no differences between the used build system herecargo
but same problem withmake
):I cannot stop the program via
STRG+C
.The text was updated successfully, but these errors were encountered: