zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Bug in sh emulation
Date: Sun, 11 Dec 2011 20:56:58 +0000	[thread overview]
Message-ID: <20111211205658.365243c7@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20111211202024.07c046df@pws-pc.ntlworld.com>

(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@ntlworld.com> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2011-12-11 20:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-10  1:39 Ivan S. Freitas
2011-12-10  2:47 ` Bart Schaefer
2011-12-10  3:40   ` Bart Schaefer
2011-12-10 18:15     ` Peter Stephenson
2011-12-10 19:40   ` Peter Stephenson
2011-12-10 23:28     ` Peter Stephenson
2011-12-11 19:39       ` Peter Stephenson
2011-12-11 20:20         ` Peter Stephenson
2011-12-11 20:56           ` Peter Stephenson [this message]
2011-12-11 23:39             ` Bart Schaefer
2011-12-12 10:01               ` Peter Stephenson
2011-12-12 10:14                 ` Peter Stephenson
2011-12-12 15:44                 ` Bart Schaefer
2011-12-12 16:06                   ` Peter Stephenson
2011-12-12 18:10                     ` Bart Schaefer
2011-12-12 19:16                       ` Peter Stephenson
2011-12-11 22:37         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111211205658.365243c7@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).