Discussion:
is-cygwin-tty check
Mihail Konev
2016-11-12 02:21:07 UTC
Permalink
A function for mingw-w64 is being proposed,
that would distinguish between an ordinary named pipe,
and a mintty-like stdin.

(Needed for mingw-w64 packages that rely on isatty()/fstat(stdin)
to work correctly if they are launched not from cmd.exe console).

Currently, it checks the ObjectNameInformation for
- possible "\\?\" in front of string
- "\Device\NamedPipe\"
- any characters afterwards
- "-pty[0-9]+-"
- allowing anything afterwards

Is the check correct?

In particular, should it put any restrictions
on what is before and after the -pty%d- (slashes, non-[-a-z0-9] ?)
Mihail Konev
2016-11-12 02:34:26 UTC
Permalink
Post by Mihail Konev
Is the check correct?
In particular, should it put any restrictions
on what is before and after the -pty%d- (slashes, non-[-a-z0-9] ?)
A spare question ...

fhandler_tty.cc says it all:
\Device\NamedPipe\[a-z0-9]+-[a-z0-9]+-pty[0-9]+-[-a-z0-9]+
Corinna Vinschen
2016-11-12 09:11:42 UTC
Permalink
Hi Mihail,
Post by Mihail Konev
Post by Mihail Konev
Is the check correct?
In particular, should it put any restrictions
on what is before and after the -pty%d- (slashes, non-[-a-z0-9] ?)
A spare question ...
\Device\NamedPipe\[a-z0-9]+-[a-z0-9]+-pty[0-9]+-[-a-z0-9]+
That looks a bit too open for my taste. I attached a proposal for
an isatty(3) replacement I proposed to a customer a couple years ago.
Hope that helps. Feel free to discuss it further on this list.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Mihail Konev
2016-11-12 11:07:52 UTC
Permalink
The first word was allowed to be [a-z0-9]* to allow for any future cygwin fork.
Sticking to cygwin/msys.

Now pipe name would be checked for being

(cygwin|msys)-[a-z0-9]{16}-pty[0-9]+-(to|from)-master

Should the "to-master-cyg" pipe be considered tty?

Assuming that "master-ctl" and "echoloop" do not.

Also, there are

winsup/cygwin/dtable.cc: char std[3][sizeof ("/dev/ptyNNNN")];
winsup/cygwin/fhandler_tty.cc: char buf[sizeof ("opened pty master for ptyNNNNNNNNNNN")];
winsup/cygwin/fhandler_tty.cc: char pipename[sizeof("ptyNNNN-to-master-cyg")];
winsup/cygwin/tty.cc: char pipename[sizeof("ptyNNNN-from-master")];

Should the "pty[0-9]+" be "pty[0-9]{1,4}" ?
Corinna Vinschen
2016-11-12 13:23:02 UTC
Permalink
Post by Mihail Konev
The first word was allowed to be [a-z0-9]* to allow for any future cygwin fork.
Sticking to cygwin/msys.
Now pipe name would be checked for being
(cygwin|msys)-[a-z0-9]{16}-pty[0-9]+-(to|from)-master
Should the "to-master-cyg" pipe be considered tty?
In theory those should be invisible to a native process but it
shoudn't hurt to handle them alike.
Post by Mihail Konev
Assuming that "master-ctl" and "echoloop" do not.
Right.
Post by Mihail Konev
Also, there are
Everything else is Cygwin-inside and handled by Cygwin's isatty.
Post by Mihail Konev
Should the "pty[0-9]+" be "pty[0-9]{1,4}" ?
Makes sense.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Loading...