This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: poll()/select() on a tty fd in a backgrounded process raises SIGTTIN


On 25/07/2016 17:55, Corinna Vinschen wrote:
On Jul 25 17:52, Jon Turney wrote:
This test case is reduced from a problem seen with gdb, since commit
0b333c5e, where gdb stops with SIGTTIN when the inferior is started.

Did you find out where it stops and do you have any ideas how we could
fix this?

Um.

gdb stops because a poll() on stdin (even when stdin is not ready to read)
while backgrounded causes a SIGTTIN to be raised.

I think this caused by select.cc:peek_console/peek_pipe calling
fhandler_termios::bg_check(SIGTTIN).

My idea for fixing it is to remove that behaviour from cygwin, assuming I'm
right in thinking that the behaviour is incorrect, although I'm wary of
touching something that's so old, and I don't understand why that call to
bg_check is in there at all...

So, this is presumably so that the exception conditions which bg_check() knows about make the fd ready, irrespective of if peeking it shows some input.

This may be an (old) misunderstanding how that's supposed to work.

Just removing sounds a bit dangerous, but we can try it.  Maybe it
just isn't necessary, but we need to check if it doesn't break
something else.  Like, say, not stopping at all anymore...

Attached is the patch as discussed on IRC, with some additional commentary.

After writing these comments, it's perhaps a bit clearer to me that bg_check() could be re-written to take a bg_check_operation enum (read, write, change_settings, peek), rather than trying to encode that operation as a signal number, but that might be changing things too much.

Also, looking at the uses of bg_check(), it's odd that handler_console::ioctl for TIOCSWINSZ calls bg_check (SIGTTOU), which should probably be -SIGTTOU, otherwise a background process could resize a console window without causing SIGTTOU. But then that operation doesn't seem to be implemented for console, but is for ttys, but it doesn't use bg_check...

Attachment: 0001-Don-t-raise-SIGTTIN-from-poll-select.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]