From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18611 invoked by alias); 26 May 2011 22:44:20 -0000 Received: (qmail 18597 invoked by uid 22791); 26 May 2011 22:44:19 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL,BAYES_20,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,TW_FD X-Spam-Check-By: sourceware.org Received: from moutng.kundenserver.de (HELO moutng.kundenserver.de) (212.227.126.186) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 May 2011 22:44:03 +0000 Received: from [127.0.0.1] (dslb-088-073-016-000.pools.arcor-ip.net [88.73.16.0]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MWvfk-1QBNHZ3B9o-00VudY; Fri, 27 May 2011 00:44:02 +0200 Message-ID: <4DDED7B0.4030106@towo.net> Date: Thu, 26 May 2011 22:44:00 -0000 From: Thomas Wolff Reply-To: Thomas Wolff User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Re: select() hanging after terminal killed X-TagToolbar-Keys: D20110527004400172 Content-Type: multipart/mixed; boundary="------------060009030807030101060608" X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2011-05/txt/msg00418.txt.bz2 --------------060009030807030101060608 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1653 On 29.04.2010 17:21, Christopher Faylor wrote: > On Thu, Apr 29, 2010 at 05:11:00PM +0200, Corinna Vinschen wrote: >> On Apr 29 12:53, Thomas Wolff wrote: >>> If a terminal gets killed, its tty/pty is not properly closed. >>> This is likely to confuse applications and let them hang, as observed >>> with mined (thanks Andy for the report) and joe. >>> >>> On Linux and SunOS, a subsequent read() return 0 (indicating EOF); >>> any further read() returns -1, errno indicating EIO. >>> Immediate write() may report success a few times, >>> further write() returns -1, errno indicating EIO. >>> >>> On Linux, select() indicates an exception and EIO. >>> On SunOS, select() indicates both an exception and input (weird), >>> and ENOENT initially, EIO on further attempts. >>> >>> On Cygwin, the following is observed: >>> * EOF is not signalled on read(); rather EIO is indicated right away. >>> (Maybe not too bad, an application can handle that as well.) >>> * select() with timeout hangs. >>> >>> Especially the latter can hardly be handled by an application. >> Can you create a simple testcase? I finally managed it... (attached). In a mintty or xterm, run hupsel > /dev/tty... (some other terminal to observe). Then close the terminal (click on 'X' corner). On Linux, the program terminates. On cygwin, the program hangs in select(). > Hmm. Since the owner has both sides of the pipe open maybe closing the > slave side doesn't trigger select. > > It's possible that Corinna's changes to tty handling might make this > work better. It would be interesting to see how this works in a recent > snapshot. Unfortunately not. Kind regards, Thomas --------------060009030807030101060608 Content-Type: text/plain; name="hupsel.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hupsel.c" Content-length: 1123 #include #include #include #include #include int peek (int fd, int msec) { fd_set readfds; fd_set exceptfds; struct timeval timeoutstru; FD_ZERO (& readfds); FD_SET (fd, & readfds); FD_ZERO (& exceptfds); FD_SET (fd, & exceptfds); timeoutstru.tv_sec = msec / 1000; timeoutstru.tv_usec = (msec % 1000) * 1000; errno = 0; printf ("calling select\n"); int nfds = select (fd + 1, & readfds, 0, & exceptfds, & timeoutstru); printf ("select -> %d (%s), read %02X except %02X\n", nfds, strerror (errno), readfds, exceptfds); return nfds; } void catch_HUP (int hup) { printf ("HUP\n"); signal (SIGHUP, catch_HUP); } int main () { int fdstdin = 0; system ("stty cbreak"); signal (SIGHUP, catch_HUP); while (1) { char buf; int buflen = 1; int nfds = peek (fdstdin, 1500); if (nfds > 0) { printf ("calling read\n"); errno = 0; int n = read (fdstdin, & buf, buflen); if (n <= 0) { printf ("read -> %d (%s); exit\n", n, strerror (errno)); exit (0); } printf ("read -> %d: %c\n", n, buf); } sleep (2); } } --------------060009030807030101060608 Content-Type: text/plain; charset=us-ascii Content-length: 218 -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --------------060009030807030101060608--