X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=m6qvPYAg7iLOtHrFK/IJlnvDLETEB ca0bs5Hj3smo0BbB8IIKW+flR/l6pORisYnX40zaVsQx8WZI96J8+VEExCYhsToE /RuYQ/ED02NPOthWc0ZZ8bQBpIDtMOgRsmk9sn3OFXblqypch6eoEkAH9/QjDAHi iYjd2ma7WvneY0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=nEX5LiZu3eWeaxICjLOCl56DMBo=; b=Zqn JDeRjfMWR9XFYPBCHXJRSgwwvMRq+lYQeQHF0IKD+qgYufkMWPiF+MivUl6z4t2n r9vpdRlYqRfRPJfvQy3PYJWgInGUkRD7mk23Jc5uvCm2OhHCBsAUu/uLFyqVBmJs i1+ye4CivGHzgrutLTMzMNqwEPhPyBByDXFWUlGE= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=bray, Erik, erik, friends X-HELO: mail-yw0-f170.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=XqEn5rITdr2BNE5AYZh4zoqOmA4eWUxH8t+UM5hAppQ=; b=V6LTid5ZEpcN1ZgkqlS0DAAf+EPBn1ZdvDQIfJzXN2iQAsHSAITZXQcIGNb5dS1Vd7 ddS2PkDsD3npyIZxr2y5EveH40VLYvjHIq6aXBsz6CU7guLuVebmRrGj5zSHxfc03XEh 1XFNTgGZcWdyusX3kvgXjDsEWl+z6K+kiEelyd9NmGRLZamk34D2t+nliFbXQ5v05k6Y RxswOizC9VcPXqz9nlA0+To9kQWhLnzB4ZQfBzGyP0w9LEfqkOs8n7Bi+bIGQ/d8tW7O Rm3hAs4Fm+yCrKh0NMfe5s+vqTLl28wWEuTYYToCJb9nd8GZWeHHW2GsCNihhYCGslk7 iGsg== X-Gm-Message-State: AHYfb5h5u8vpNneDceKpV4QpfFT0QJE1Xst2UObLsUPqY3EL5aB92sxD Xokr7IJb8SOvh9eCME3/PcbCJVYj0v53Vqc= X-Received: by 10.37.244.67 with SMTP id p3mr1150258ybe.33.1503420540943; Tue, 22 Aug 2017 09:49:00 -0700 (PDT) MIME-Version: 1.0 From: Erik Bray Date: Tue, 22 Aug 2017 18:49:00 +0200 Message-ID: Subject: Strange bug with /dev/console in mintty To: cygwin AT cygwin DOT com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes Hi folks, 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: $ 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 The same command when run in mintty returns: 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 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: 203 if (cdev->get_major () == 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 number 209 as the current consX. */ 210 de->d_ino = myself->ctty; 211 } where myself->ctty seems to depend largely on what file types the stdio handles are attached to. 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: $ ls -l /dev/console ls: cannot access '/dev/console': No such device or address which is the error message for a ENXIO. This is coming specifically from the function build_fh_pc in dtable.cc. The reason is that trying to access /dev/console results in trying to create an fhandler_console for a non-existent console. I'm not really sure what the correct behavior should be here though, and if it should be fixed on the mintty side or the Cygwin side. Thanks, Erik -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple