This is the mail archive of the
mailing list for the GDB project.
Re: [RFA/commit] Handle EOF on terminals opened with ENONBLOCK...
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 6 May 2009 16:02:02 -0700
- Subject: Re: [RFA/commit] Handle EOF on terminals opened with ENONBLOCK...
- References: <20090423191446.GB7512@adacore.com>
> 2009-04-23 Joel Brobecker <email@example.com>
> * 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
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 @@
extern PTR malloc (); /* ARI: PTR */
@@ -1477,6 +1479,25 @@ defaulted_query (const char *ctlstr, con
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 */