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
[ctrl-C] fails to terminate job when read is involved #4238
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 here cargo but same problem with make):
inotifywait -mrq -e close_write Cargo.toml src/ libgerrit/ --format "%w/%f" | while read CHANGEDFILE
clear
cargo check; and cargo build
echo "DONE"
end
@silvio: Can you try your command and quit before the inotifywait prints the first line?
I'm guessing the issue is that the first read quits, and then the second starts and some of our process group nonsense occurs - see #3952 and related issues.
I'm guessing the issue is that the first read quits, and then the second starts and some of our process group nonsense occurs
Yep, that's it.
The issue is, as soon as the first read quits, fish returns control of the terminal to itself.
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.
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 <[email protected]>
Date: Mon Jul 2418:50:002017 +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 @@ voidjob_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 cat | while read, it starts one job with two processes - the cat, and the read. These are in the same process group, while the parent fish is in another. This would be the case even if fish didn't insist (for some reason) on acquiring its own pgroup on start.
Now, when the cat sends over the first line, the read is done and quits. This causes fish to execute its weirdly named job_continue function, and acquire control over the terminal again (terminal_return_from_job()). This causes the cat to lose control, so it won't receive any input anymore.
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.
It's another piece of the job control/process group pile of REDACTED, but not quite the same.
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 src/.
inotifywait -mrq -e close_write src/ --format "%w/%f"|whileread CHANGEDFILE
clear
make
echo"DONE"
end
The new behavior is:
before the first inotifywait is over, a STRG+C kills the inotifywait without problems
after inotifywait has ended and the while block starts oneSTRG+C doesn't break the execution, but two of them will stop the current process/while block execution
if the called while block is over and we are again in the inotifywait spin. No STRG+C will break anything. But when we run again the while loop it stops immediately
When I execute inotifywait -mrq -e close_write src/ --format "%w/%f" without the while part the STRG+C works. (has not changed)
Note: Technically, it does not end. inotifywait continues running.
Okay, so the issue there is that make is run in a separate job that also gets control of the terminal. After it has ended, we still return control to fish, not the (still running) inotifywait.
This is going to need some major reworking - my gut still tells me that the entire thing should be one job (including make) and hence one process group.
Activity
[-]Problem to ckill inotifywait with fish 2.6.0[/-][+]Problem to sigkill via STRG+C inotifywait with fish 2.6.0[/+]faho commentedon Jul 24, 2017
The "inotifywait" and
cargoare unnecessary here. Any external command piped toreadseems to do.exhibits the same issue (well, after you enter something - I think
catquits if it immediately gets a ctrl-c).I'm unsure of the root cause.
faho commentedon Jul 24, 2017
It actually doesn't.
Which leads me to a theory...
@silvio: Can you try your command and quit before the
inotifywaitprints the first line?I'm guessing the issue is that the first
readquits, and then the second starts and some of our process group nonsense occurs - see #3952 and related issues.faho commentedon Jul 24, 2017
Yep, that's it.
The issue is, as soon as the first
readquits, fish returns control of the terminal to itself.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.
krader1961 commentedon Jul 24, 2017
Pretty close to 100% certain this is a duplicate of #3805.
faho commentedon Jul 24, 2017
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:
The problem is that, when fish starts
cat | while read, it starts one job with two processes - thecat, and theread. These are in the same process group, while the parent fish is in another. This would be the case even if fish didn't insist (for some reason) on acquiring its own pgroup on start.Now, when the
catsends over the first line, thereadis done and quits. This causes fish to execute its weirdly namedjob_continuefunction, and acquire control over the terminal again (terminal_return_from_job()). This causes thecatto lose control, so it won't receive any input anymore.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?
krader1961 commentedon Jul 24, 2017
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.
Only reassume control of term if all foreground jobs finished
faho commentedon Jul 25, 2017
@silvio: Please try #4242.
Only take control of term if the finished job had it
silvio commentedon Jul 25, 2017
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
src/.The new behavior is:
inotifywaitis over, aSTRG+Ckills theinotifywaitwithout problemsinotifywaithas ended and thewhileblock starts oneSTRG+Cdoesn't break the execution, but two of them will stop the current process/whileblock executionwhileblock is over and we are again in theinotifywaitspin. NoSTRG+Cwill break anything. But when we run again thewhileloop it stops immediatelyinotifywait -mrq -e close_write src/ --format "%w/%f"without thewhilepart theSTRG+Cworks. (has not changed)faho commentedon Jul 25, 2017
Note: Technically, it does not end. inotifywait continues running.
Okay, so the issue there is that
makeis run in a separate job that also gets control of the terminal. After it has ended, we still return control to fish, not the (still running) inotifywait.This is going to need some major reworking - my gut still tells me that the entire thing should be one job (including
make) and hence one process group.Fixes job handling involving functions and terminal control
Fixes job handling involving functions and terminal control
Assign terminal to unfinished foreground jobs over shell