aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2009-05-06 22:54:58 +0000
committerJoel Brobecker <brobecker@gnat.com>2009-05-06 22:54:58 +0000
commit8626589c42c3cdb9784be37fff88f631a5f25b6e (patch)
treeb5cb5dbe38b0d45273675a71494ac99ddacf42df
parentba42693bb46c02cf17455d19a93ce1401c016587 (diff)
downloadfsf-binutils-gdb-8626589c42c3cdb9784be37fff88f631a5f25b6e.zip
fsf-binutils-gdb-8626589c42c3cdb9784be37fff88f631a5f25b6e.tar.gz
fsf-binutils-gdb-8626589c42c3cdb9784be37fff88f631a5f25b6e.tar.bz2
* 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.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/utils.c21
2 files changed, 28 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 21bf55d..e219552 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2009-05-06 Joel Brobecker <brobecker@adacore.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.
+
2009-05-06 Pedro Alves <pedro@codesourcery.com>
* inferior.c (add_inferior): Move observer_notify_new_inferior
diff --git a/gdb/utils.c b/gdb/utils.c
index 99b0e76..4396d14 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -67,6 +67,8 @@
#include <sys/time.h>
#include <time.h>
+#include "gdb_usleep.h"
+
#if !HAVE_DECL_MALLOC
extern PTR malloc (); /* ARI: PTR */
#endif
@@ -1477,6 +1479,25 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
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 */
{