luit: Cygwin compatibility

Yann Droneaud ydroneaud at mandriva.com
Wed Oct 7 02:16:14 PDT 2009


Le mardi 06 octobre 2009 à 17:38 +0200, Mark Kettenis a écrit :
> > From: Adam Jackson <ajax at nwnk.net>
> > Date: Tue, 06 Oct 2009 11:21:13 -0400
> > 
> > On Mon, 2009-10-05 at 19:08 -0500, Yaakov (Cygwin/X) wrote:
> > 
> > > Cygwin has O_NOCTTY but no TIOCSCTTY, so the tty is never made=20
> > > controlling.  This raises two questions:
> > >=20
> > > 1) What is the point of O_NOCTTY if TIOCSCTTY is called right afterwards?
> > 
> > Hah!  Can't think of one.
> 
> But I can.  The TIOCSCTTY ioctl will fail if the process already has a
> controlling tty (even if the current controlling tty is the same as
> the tty you want to make controlling).  So you need to open the tty
> with O_NOCTTY to make sure this doesn't happen.


You could check controlling tty using this trick:

#ifndef HAVE_CTERMID
static const char *ctty = "/dev/tty";
#define get_ctty() ctty
#else
#define get_ctty() ctermid(NULL) /* under GNU system, ctermid() always
return "/dev/tty" */
#endif

/* try to open /dev/tty, if an error occur, there's no controlling tty
*/
int
check_ctty(void)
{
  int fd;

  fd = open(get_ctty(), O_RDWR); /* if we can open this,
                                    fbgetty has a controlling terminal
*/
  if (fd != -1)
    close(fd);

  return fd;
}


But I don't know if it's working under cygwin.

-- 
Yann Droneaud





More information about the xorg-devel mailing list