From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3874 invoked by alias); 23 Aug 2017 16:08:10 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 3849 invoked by uid 89); 23 Aug 2017 16:08:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-101.9 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*R:D*cygwin.com, friends, H*c:application X-HELO: drew.franken.de Received: from mail-n.franken.de (HELO drew.franken.de) (193.175.24.27) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Aug 2017 16:08:07 +0000 Received: from aqua.hirmke.de (aquarius.franken.de [193.175.24.89]) (Authenticated sender: aquarius) by mail-n.franken.de (Postfix) with ESMTPSA id 4416572106C12 for ; Wed, 23 Aug 2017 18:08:04 +0200 (CEST) Received: from calimero.vinschen.de (calimero.vinschen.de [192.168.129.6]) by aqua.hirmke.de (Postfix) with ESMTP id 773555E04F7 for ; Wed, 23 Aug 2017 18:08:03 +0200 (CEST) Received: by calimero.vinschen.de (Postfix, from userid 500) id 58706A80463; Wed, 23 Aug 2017 18:08:03 +0200 (CEST) Date: Wed, 23 Aug 2017 16:08:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Strange bug with /dev/console in mintty Message-ID: <20170823160803.GG7469@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20170823083346.GB7469@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zCKi3GIZzVBPywwA" Content-Disposition: inline In-Reply-To: <20170823083346.GB7469@calimero.vinschen.de> User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017-08/txt/msg00213.txt.bz2 --zCKi3GIZzVBPywwA Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 3413 On Aug 23 10:33, Corinna Vinschen wrote: > On Aug 22 18:49, Erik Bray wrote: > > Hi folks, > >=20 > > I noticed a strange discrepancy when running Cygwin through mintty, vs > > through a normal cmd.exe console. This is on a build from the latest > > git master, but also on Cygwin 2.8.0. When run from a cmd.exe > > console, we can see the following output from fhandler_dev::readdir: > >=20 > > $ ls -l /dev/con* > > crw-rw-rw- 4 Erik M. Bray Erik M. Bray 3, 0 Aug 22 18:29 /dev/conin > > crw-rw-rw- 4 Erik M. Bray Erik M. Bray 3, 0 Aug 22 18:29 /dev/conout > > crw-rw-rw- 4 Erik M. Bray Erik M. Bray 3, 0 Aug 22 18:29 /dev/cons0 > > crw-rw-rw- 4 Erik M. Bray Erik M. Bray 3, 0 Aug 22 18:29 /dev/console > >=20 > > The same command when run in mintty returns: > >=20 > > crw-rw-rw- 1 Erik M. Bray Erik M. Bray 5, 255 Aug 22 18:29 /dev/conin > > crw-rw-rw- 1 Erik M. Bray Erik M. Bray 5, 254 Aug 22 18:29 /dev/conout > > crw-rw-rw- 1 Erik M. Bray Erik M. Bray 5, 1 Aug 22 18:29 /dev/console > >=20 > > In the latter case, the device numbers are the default device numbers > > for /dev/console, etc. In the former case, the inodes for > > /dev/console, /dev/conin, and /dev/conout are set to the same as > > /dev/cons0. This logic can be found in fhandler_dev::readdir: > >=20 > > 203 if (cdev->get_major () =3D=3D DEV_TTY_MAJOR > > 204 && (cdev->is_device (FH_CONIN) > > 205 || cdev->is_device (FH_CONOUT) > > 206 || cdev->is_device (FH_CONSOLE))) > > 207 { > > 208 /* Make sure conin, conout, and console have the same inode n= umber > > 209 as the current consX. */ > > 210 de->d_ino =3D myself->ctty; > > 211 } > >=20 > > where myself->ctty seems to depend largely on what file types the > > stdio handles are attached to. > >=20 > > When running from cmd.exe, GetStdHandle(...) returns handles to a > > character stream--i.e. the console itself. However, when running from > > mintty it returns pipes (specifically, to a pty, probably related to > > the call to forkpty in mintty). In Cygwin (particularly, in > > dtable::init_std_file_from_handle) the result ends up being that when > > the stdio handles are pipes, the /dev/cons0 device never gets created. > > And thus /dev/console and friends never get rerouted to a real device. > > This results in errors when trying to access /dev/console directly: > >=20 > > $ ls -l /dev/console > > ls: cannot access '/dev/console': No such device or address >=20 > /dev/console is an old concept in Cygwin and it was always attached to > the current console window, *if* you were running inside a windows > console. It was never implemented for pseudo ttys as used by mintty. >=20 > The fact that the /dev emulation shows the con devices is a bit > disappointing, given that they are basically unusable. The existence > check only checks if GetConsoleCP() returns successfully, but that's > true for a pseudo tty as well. A console is attached to the process > anyway. >=20 > I'll think about the existence check. I checked in a patch removing the /dev/conin, /dev/conout and /dev/console files from /dev if the process is not running from a console. Check out the latest developer snapshot from https://cygwin.com/snapshots/ Thanks, Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --zCKi3GIZzVBPywwA Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZnahjAAoJEPU2Bp2uRE+gQzkP/0rXxB/xIEHr0P5MczVykUo+ Lk+ZaV/Gc98LpPnPsvRgNxGQgdbCmbjPEMF0U8/l9OwJ6+5zyJ9SDzkDpjV5LVNJ PZYv84NgCse3BiJDC7lnXeLlSppTx8BiJ16oVNAEHur40Osnzs0KaDaXvVl5wjRf iKOvU1qjhO5aYywf2PZ2KntgPSQvJ8gQsGRuNv8od4CuX39VmmiCjqn3dltJFKJW 3C2cwTCSXzlRw+h0RZqqkiVXG9m9EQttPdhFGN41YpihhKs2W6R+xvIEOzHtqQlv yDR9YNI4ZuLA/z4DiGzpIUS88JZZU6mC2fyHSb6tYdjaGgYXdilQFWFOV93Vp0dH i8YYDooML6ZNvA0jCQgyGLnXiLNZFdk3utxGr+ZcJD7CztQ8aejFQNejP9m6VaXm p2W7Jsx5Bz/kZEpCGe0QChe3xG9Sb69FAG7VAdkklmr5HcvBiw/aGD9/4XTOGd+j y25OPqQvl0Ih6aJARPyz7uGDkY2xFdzLeccy+XgDF57RCcAWma5/fQWeM1JK4Df9 mQCqjd/moNpLhaeR0pVb4ArKLivY8ZkaoOx+WmsOF+JBNfOaHA1B9E5ubHXQgqwm o9Wr5rqQYoeLIO5MsohNA6tUhv/UtCBfir2KvftTYb+1umQtHwPwtVPzdimfYyRs EoyhlsCVFhDVdgBnmNC6 =4L2p -----END PGP SIGNATURE----- --zCKi3GIZzVBPywwA--