This is the mail archive of the cygwin-patches@cygwin.com 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: EIO error on background tty reads


On Mon, Jun 30, 2003 at 01:37:47PM -0400, Rafael Kitover wrote:
>  else
>    goto setEIO;        /* This is an output error */
>
>This case is only reached if the signal passed to bg_check was SIGTTIN,
>there is no condition to otherwise disallow a background read from a
>tty, but the process requesting the read has SIGTTIN ignored.

Right.  Good analysis.  I noticed the comment was wrong yesterday but I
haven't fixed it yet.

>The comment says that this is an output error, but in this case input is
>being requested.
>
>What I don't understand is if a background write to a terminal without
>sending a
>SIGTTOU which it explicitly ignores is allowed, why not a background read?

Because that's the way it works.  Have you tried this with linux?  I wrote
a test case yesterday.  linux raises an EIO when a background read is
attempted, SIGTTIN is ignored, and the process is not a member of the
terminal's process group.  Test case below.

>This is what I propose:
>
>Index: cygwin/fhandler_termios.cc
>===================================================================
>RCS file: /cvs/src/src/winsup/cygwin/fhandler_termios.cc,v
>retrieving revision 1.46
>diff -u -p -r1.46 fhandler_termios.cc
>--- cygwin/fhandler_termios.cc  16 Jun 2003 03:24:10 -0000      1.46
>+++ cygwin/fhandler_termios.cc  30 Jun 2003 16:45:35 -0000
>@@ -160,10 +160,8 @@ fhandler_termios::bg_check (int sig)
>     goto setEIO;
>   else if (!sigs_ignored)
>     /* nothing */;
>-  else if (sig == SIGTTOU)
>-    return bg_ok;              /* Just allow the output */
>   else
>-    goto setEIO;       /* This is an output error */
>+    return bg_ok;              /* Just allow the output or input */
>
>   /* Don't raise a SIGTT* signal if we have already been interrupted
>      by another signal. */

I don't think this would satisfy the requirement that an EIO be sent
for the above scenario.

cgf

#include <stdio.h>
#include <signal.h>
#include <errno.h>

int
main (int argc, char **argv)
{
  setbuf (stdout, NULL);
  if (fork () == 0)
    {
      char buf[10];
      setpgrp (getpid ());
      signal (SIGTTIN, SIG_IGN);
      puts ("reading");
      printf ("%d = read\n", read (0, buf, 10));
      printf ("errno %d\n", errno);
      perror ("");
      exit (0);
    }
  sleep (4);
}


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