From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Paul N. Hilfinger" To: gdb-patches@sources.redhat.com Subject: RFA: Fix for piped input on Linux Date: Tue, 08 May 2001 16:17:00 -0000 Message-id: <200105082317.QAA02186@localhost.localdomain> X-SW-Source: 2001-05/msg00106.html I'm not sure if piping input to GDB is all that common, but I happened to encounter an odd little glitch on my RedHat Linux 6.2 setup (2.2.16-3 i686) that causes GDB to receive bogus SIGHUPs on input. The following works for me, but someone who actually understands the real semantics of the flags ought to comment. The symptom encountered is that gdb foo < script works just fine, but cat script | gdb foo (for example) fails with messages such as (gdb) Hangup detected on fd 0 error detected on stdin without reading a single complete command. With the change, one gets the message above only at EOF, where it makes a little more sense. Paul Hilfinger 2001-05-08 Paul N. Hilfinger ChangeLog: * event-loop.c (handle_file_event): Mask off POLLHUP when we receive input. For some reason, Redhat Linux 6.2 (at least) sets the POLLHUP bit on each input when reading from a pipe (not from a file). diff -c -3 -p -r1.16 event-loop.c *** event-loop.c 2001/03/27 20:36:23 1.16 --- event-loop.c 2001/05/08 22:38:07 *************** handle_file_event (int event_file_desc) *** 662,667 **** --- 662,674 ---- if (use_poll) { #ifdef HAVE_POLL + /* The following two lines address a problem seen on at + least one Linux version (RedHat 6.2): when input + comes from a pipe, the POLLHUP flag is set on each + input, so in the event we are expecting input and get + it, we turn off POLLHUP. */ + if (file_ptr->ready_mask & file_ptr->mask & POLLIN) + file_ptr->ready_mask &= ~POLLHUP; error_mask = POLLHUP | POLLERR | POLLNVAL; mask = (file_ptr->ready_mask & file_ptr->mask) | (file_ptr->ready_mask & error_mask);