From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4963 invoked by alias); 6 May 2009 23:02:13 -0000 Received: (qmail 4879 invoked by uid 22791); 6 May 2009 23:02:12 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 May 2009 23:02:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 668652BAC32 for ; Wed, 6 May 2009 19:02:04 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id hZLIcXU6SHPV for ; Wed, 6 May 2009 19:02:04 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2905D2BAB71 for ; Wed, 6 May 2009 19:02:04 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 4835DF5900; Wed, 6 May 2009 16:02:02 -0700 (PDT) Date: Wed, 06 May 2009 23:02:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: Re: [RFA/commit] Handle EOF on terminals opened with ENONBLOCK... Message-ID: <20090506230202.GU10734@adacore.com> References: <20090423191446.GB7512@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="uQr8t48UFsdbeI+V" Content-Disposition: inline In-Reply-To: <20090423191446.GB7512@adacore.com> User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-05/txt/msg00138.txt.bz2 --uQr8t48UFsdbeI+V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 358 > 2009-04-23 Joel Brobecker > > * utils.c: Add include of gdb_usleep.h. > (defaulted_query): Detect false EOF conditions that happen > on terminals opened with the O_NONBLOCK flag when there is > nothing to read. This is what I ended up checking in. Eli, is the comment clearer for you? -- Joel --uQr8t48UFsdbeI+V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="utils.c.diff" Content-length: 1418 Index: utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.210 diff -u -p -r1.210 utils.c --- utils.c 24 Apr 2009 22:10:03 -0000 1.210 +++ utils.c 6 May 2009 22:51:37 -0000 @@ -67,6 +67,8 @@ #include #include +#include "gdb_usleep.h" + #if !HAVE_DECL_MALLOC extern PTR malloc (); /* ARI: PTR */ #endif @@ -1477,6 +1479,25 @@ defaulted_query (const char *ctlstr, con gdb_flush (gdb_stdout); answer = fgetc (stdin); + + /* We expect fgetc to block until a character is read. But + this may not be the case if the terminal was opened with + the NONBLOCK flag. In that case, if there is nothing to + read on stdin, fgetc returns EOF, but also sets the error + condition flag on stdin and errno to EAGAIN. With a true + EOF, stdin's error condition flag is not set. + + A situation where this behavior was observed is a pseudo + terminal on AIX. */ + while (answer == EOF && ferror (stdin) && errno == EAGAIN) + { + /* Not a real EOF. Wait a little while and try again until + we read something. */ + clearerr (stdin); + gdb_usleep (10000); + answer = fgetc (stdin); + } + clearerr (stdin); /* in case of C-d */ if (answer == EOF) /* C-d */ { --uQr8t48UFsdbeI+V--