Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: Re: [RFA/commit] Handle EOF on terminals opened with ENONBLOCK...
Date: Wed, 06 May 2009 23:02:00 -0000	[thread overview]
Message-ID: <20090506230202.GU10734@adacore.com> (raw)
In-Reply-To: <20090423191446.GB7512@adacore.com>

[-- Attachment #1: Type: text/plain, Size: 358 bytes --]

> 2009-04-23  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.

This is what I ended up checking in. Eli, is the comment clearer
for you?

-- 
Joel

[-- Attachment #2: utils.c.diff --]
[-- Type: text/x-diff, Size: 1418 bytes --]

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 <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, 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 */
 	{

  parent reply	other threads:[~2009-05-06 23:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-23 19:14 Joel Brobecker
2009-04-23 19:35 ` Mark Kettenis
2009-04-23 20:37   ` Joel Brobecker
2009-04-23 20:45     ` Mark Kettenis
2009-04-24 10:20 ` Eli Zaretskii
2009-05-06 23:02 ` Joel Brobecker [this message]
2009-05-07  3:13   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090506230202.GU10734@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox