From owner-freebsd-stable@FreeBSD.ORG Thu Oct 25 08:46:05 2012 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F065D4A7 for ; Thu, 25 Oct 2012 08:46:05 +0000 (UTC) (envelope-from jdc@koitsu.strangled.net) Received: from qmta01.emeryville.ca.mail.comcast.net (qmta01.emeryville.ca.mail.comcast.net [IPv6:2001:558:fe2d:43:76:96:30:16]) by mx1.freebsd.org (Postfix) with ESMTP id CB3BA8FC12 for ; Thu, 25 Oct 2012 08:46:05 +0000 (UTC) Received: from omta22.emeryville.ca.mail.comcast.net ([76.96.30.89]) by qmta01.emeryville.ca.mail.comcast.net with comcast id FLgg1k0051vN32cA1Lm59V; Thu, 25 Oct 2012 08:46:05 +0000 Received: from koitsu.strangled.net ([67.180.84.87]) by omta22.emeryville.ca.mail.comcast.net with comcast id FLm41k00C1t3BNj8iLm40V; Thu, 25 Oct 2012 08:46:05 +0000 Received: by icarus.home.lan (Postfix, from userid 1000) id F19D973A31; Thu, 25 Oct 2012 01:46:03 -0700 (PDT) Date: Thu, 25 Oct 2012 01:46:03 -0700 From: Jeremy Chadwick To: Ed Schouten Subject: Re: pty/tty or signal strangeness, or grep/bsdgrep bug? Message-ID: <20121025084603.GA1937@icarus.home.lan> References: <20121023142703.GA79098@icarus.home.lan> <20121023203928.GZ35915@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Konstantin Belousov , freebsd-stable@freebsd.org, jhb@freebsd.org X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Oct 2012 08:46:06 -0000 On Thu, Oct 25, 2012 at 09:45:11AM +0200, Ed Schouten wrote: > 2012/10/23 Ed Schouten : > > Will try to come up with a decent patch tomorrow evening. > > Ahem; the day after tomorrow. Jeremy, could you please try the following patch? > > http://80386.nl/pub/tty-bg-read.txt > > I decomposed the TTY read routine into four separate functions to > improve clarity. While this was initially true, I think it's a pity > the four functions are constantly becoming a bit more complex. > > The same issue is also present on the output path, but I have no idea > how realistic/hard it is to fix this issue. Also, it might not really > be an issue in practice. If you do a large write and become a > non-foreground process group, you might be able to circumvent TOSTOP > while the write() is in transit. > > Fixing this might be tedious, because we currently enforce that writes > to a TTY are serialized. Blocking inside the write() might then cause > a deadlock. But in my opinion, I would prefer the serialization over > the enforcing of TOSTOP. After the patch, testing with grep and cat, and checking cv/state for the latter case: (01:30:39 jdc@icarus) ~ $ csh % grep -r "-2011" . & [1] 1964 % jobs [1] + Suspended (tty input) grep -r -2011 . % fg grep -r -2011 . ^C % jobs % grep -r "-2011" . ^Z Suspended % bg [1] grep -r -2011 . & [1] + Suspended (tty input) grep -r -2011 . % fg grep -r -2011 . ^C % cat & [1] 2042 % jobs [1] + Suspended (tty input) cat % ps -auxwU jdc | grep cat jdc 2042 0.0 0.0 9908 1496 1 T 1:34AM 0:00.00 cat jdc 2044 0.0 0.0 16268 1864 1 S+ 1:34AM 0:00.00 grep cat % top -b -U jdc | grep cat 2042 jdc 1 20 0 9908K 1496K STOP 0 0:00 0.00% cat 2047 jdc 1 20 0 16268K 1864K piperd 0 0:00 0.00% grep cat % fg cat ^C % exit I do not get dropped characters or witness any other anomalies. I tested behaviour with /bin/sh, as well as bash. All seems good. > Thanks again for reporting the issue! No, thank *you* and others for looking + fixing it! :-) I assume a commit to HEAD + MFC in 2 weeks is in order? I'll update the PR with this part of our mail thread. -- | Jeremy Chadwick jdc@koitsu.org | | UNIX Systems Administrator http://jdc.koitsu.org/ | | Mountain View, CA, US | | Making life hard for others since 1977. PGP 4BD6C0CB |