From owner-freebsd-current@FreeBSD.ORG Sun Aug 23 04:22:29 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3B65D106568F for ; Sun, 23 Aug 2009 04:22:29 +0000 (UTC) (envelope-from nslay@comcast.net) Received: from QMTA09.emeryville.ca.mail.comcast.net (qmta09.emeryville.ca.mail.comcast.net [76.96.30.96]) by mx1.freebsd.org (Postfix) with ESMTP id 242EF8FC17 for ; Sun, 23 Aug 2009 04:22:29 +0000 (UTC) Received: from OMTA14.emeryville.ca.mail.comcast.net ([76.96.30.60]) by QMTA09.emeryville.ca.mail.comcast.net with comcast id Xg751c0071HpZEsA9g9KSQ; Sun, 23 Aug 2009 04:09:19 +0000 Received: from LIGHTBULB.LOCAL ([69.244.210.117]) by OMTA14.emeryville.ca.mail.comcast.net with comcast id Xg9H1c0042YXfpR8ag9Jmz; Sun, 23 Aug 2009 04:09:19 +0000 Message-ID: <4A90C099.8030605@comcast.net> Date: Sun, 23 Aug 2009 00:07:53 -0400 From: Nathan Lay User-Agent: Thunderbird 2.0.0.22 (X11/20090626) MIME-Version: 1.0 To: Ed Schouten References: <20090822185812.GC61707@felucia.tataz.chchile.org> <20090822194009.GQ1292@hoeg.nl> In-Reply-To: <20090822194009.GQ1292@hoeg.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@FreeBSD.org, Jeremie Le Hen Subject: Re: truss(1) locked in kernel with 8.0-BETA2 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Aug 2009 04:22:29 -0000 Ed Schouten wrote: > Hi Jeremie, > > * Jeremie Le Hen wrote: > >> I've upgraded my laptop to 8.0-BETA2 and ran portupgrade in script(1). >> But according to top, it seems script(1) is going crazy, even after I've >> hit ^C: >> > > The fact that script(1) is going crazy, is a known issue. I have been > pointed to this issue earlier, but unfortunately I don't know what to > do. A certain Colin introduced this bug about 6 years ago. ;-) > > It's basically a shortcoming of pseudo-terminals in general. script(1) > wants to behave in a way which cannot be implemented using > pseudo-terminals; when it receives a hangup on its standard input (on > the outside), it wants to propagate the end-of-file condition and wants > to continue until the child processes are finished, instead of shutting > down immediately. So a couple of milliseconds later on, it calls > select(2) again, but because the TTY it uses on the outside is still in > a hangup condition, select(2) returns immediately. > > This can easily be reproduced as follows: > > script < /dev/null > > I think the only way we can sanely fix this, is by adding a special flag > to instruct script(1) to keep going on, even if stdin disappears. I > wrote a patch for this back in May: > > http://80386.nl/pub/script.diff > > Thanks for reminding me. I should contact re@ about this. > > Instead of zeroing and setting master and STDIN_FILENO on the fd_set every iteration, why not have two fd_sets: the original and temporary. At every iteration the original is copied into the temporary for select() to destroy. Once the hangup condition is detected, the STDIN_FILENO is cleared from the original fd_set so it will not be examined by select() later. For example: fd_set rfds, tmpfds; FD_ZERO(&rfds); FD_SET(master,&rfds); FD_SET(STDIN_FILENO,&rfds); for (;;) { tmpfds = rfds; /* Not sure if this assignment is portable */ n = select(master+1, &tmpfds, NULL, NULL, tvp); if (hangup condition) { FD_CLR(STDIN_FILENO,&rfds); } /* Do other stuff here */ } Best Regards, Nathan Lay