From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117039 invoked by alias); 22 Aug 2017 16:49:05 -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 117024 invoked by uid 89); 22 Aug 2017 16:49:04 -0000 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 Received: from mail-yw0-f170.google.com (HELO mail-yw0-f170.google.com) (209.85.161.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Aug 2017 16:49:03 +0000 Received: by mail-yw0-f170.google.com with SMTP id s143so111468499ywg.1 for ; Tue, 22 Aug 2017 09:49:02 -0700 (PDT) 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 Received: by 10.37.91.9 with HTTP; Tue, 22 Aug 2017 09:49:00 -0700 (PDT) From: Erik Bray Date: Tue, 22 Aug 2017 16:49:00 -0000 Message-ID: Subject: Strange bug with /dev/console in mintty To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00198.txt.bz2 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