From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122472 invoked by alias); 23 Aug 2017 08:37:48 -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 119700 invoked by uid 89); 23 Aug 2017 08:33:51 -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=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 08:33:50 +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 5CE9772106C12 for ; Wed, 23 Aug 2017 10:33:47 +0200 (CEST) Received: from calimero.vinschen.de (calimero.vinschen.de [192.168.129.6]) by aqua.hirmke.de (Postfix) with ESMTP id AC7D95E01D4 for ; Wed, 23 Aug 2017 10:33:46 +0200 (CEST) Received: by calimero.vinschen.de (Postfix, from userid 500) id 90A24A80420; Wed, 23 Aug 2017 10:33:46 +0200 (CEST) Date: Wed, 23 Aug 2017 08:37:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Strange bug with /dev/console in mintty Message-ID: <20170823083346.GB7469@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bCsyhTFzCvuiizWE" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017-08/txt/msg00212.txt.bz2 --bCsyhTFzCvuiizWE Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 3022 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 num= ber > 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 /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. 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. I'll think about the existence check. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --bCsyhTFzCvuiizWE Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZnT3qAAoJEPU2Bp2uRE+g6jsP/R6Y1h2ToLHXKwUk3PYFuE49 qarDW8g4RTY5F5PM9AzL7pA8VE2U8OSd/wfcQhu0U2ygild3PFSV0tyR8MiQ7R2W YiUlajK2X6YBGxyTIhxunoOfX3r8GJJhn12FVpOYV8/ncyV9Il6DSr6hmA2F6EQx 83euiYPzkvVbTmDsilEqyqoIwCcGISMQXYREo7CHawrh3Oc9+PCrakXUjrxZue4C TbtL57VXQ2Ct1+wZMn/96+Z3C1VvefBJY7Z9kW5Mtut7rnW8Ms10c4qY7Z90Qyma 8SIZwSx7qA6MDiQ0waXZVzG5uWr60Luv/TSKuGwnnXWOJhMgUE4nlXA9ilxTO5mT XE28hYMopgThzjzfbaLCcYoxkApcQI+xj6LUaLQdCxk2Rv1r6yfmv6gnCmGHhl/C cymF3oBSgQRydLkK9fZit7wsnCP56BScrHLKdO6pKTDPoDZtrSzLyaBQBXbNdQ1f J+mqKnme0G74xjMIoOjk43HQvDY/Bu3yA+zCeDwTv3aGpo03ka4lFBhYkZjl+hsP Bhuw424iGKkdSyhLXcktlZvM1n+8qHyfZnBcMRP6M5hP2ShaCX5F+cneWwgX337+ LVUjje6WmZYvFSBb2yznsiNBn+RzrcFeiFh/hzaBmxVWc/t8GUZSBSGiPSKkasaX zU39snylpZR7DGpSjJEH =2ttQ -----END PGP SIGNATURE----- --bCsyhTFzCvuiizWE--