Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug in sh emulation
(sorry! it's me again... however, this time I think I'm really getting
there...)
> On Sun, 11 Dec 2011 19:39:49 +0000
> Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> I'm vaguely coming to the conclusion the SIGTTOU's are endemic because
> we only do the attachtty() from the new process, which starts off in the
> background, and hence the signal ignoring is a key feature...
http://www.gnu.org/s/hello/manual/libc/Job-Control-Signals.html
— Macro: int SIGTTOU
This is similar to SIGTTIN, but is generated when a process in a
background job attempts to write to the terminal *or set its modes*.
^^^^^^^^^^^^^^^^
Aha! I think the improbability sum is now complete.
Why the bug occurred:
- POSIXJOBS and MONITOR are on initially
- Fork for subshell
- attachtty() in subshell, which is in background to begin with ---
parent shell is foreground. This works because SIGTTOU is being ignored.
- Shell stopped ignoring SIGTTOU (wrong because...)
- MONITOR left on because of POSIXJOBS (correct because this is a subshell)
- Fork for pipeline
- attachtty() again... SIGTTOU not being ignored, so this causes mayhem.
What should happen:
- Fork for subshell as before
- attachtty() as before
- Shell keeps ignoring SIGTTOU because...
- MONITOR is left on for POSIXJOBs as this is a (...) subshell in the
foreground.
- Fork for pipeline
- attachtty() works because SIGTTOU is still ignored
- Now stop ignoring SIGTTOU because the pipeline element is not a (...)
subshell, it's some random command
- MONITOR is turned off for the same reason.
So I think I've convinced myself the immediately preceding patch is
correct.
In addition to fixing the bug we get:
% emulate sh -c '(echo foo | grep foo & jobs)'
[2] done echo foo |
running grep foo
% foo
(some inevitable races meaning it may not look quite like that) as job
control in the subshell has stayed on because of POSIXJOBS and has
worked correctly by entering the pipeline into the job table.
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author