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:in-reply-to:references:from:date :message-id:subject:to:content-type; q=dns; s=default; b=fc5EeDn cob79Ph1x2F803GCGztX2PSzsDC+tihg79YyK13472yqe/BH/AIJwcasDDW9DdKa ZQLdNYMMpCDPlW825yRf56PMaMNTDANdPyTY68pLe0vWzdscCXq5W05zbf1cCdNa z6A+i6aNKtORydGMz+tszBAA0k5lcB6L+tSo= 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:in-reply-to:references:from:date :message-id:subject:to:content-type; s=default; bh=ha947+KDLGxMt t1eRR+FAZIV1Ao=; b=uHcr2dyk9NCiLAlHc0q3cUTyH1ForfwwfPdjriOnKMcI2 /zmEUmhArAjVHSR42EURJq5eFn9vrsV/FIVL9gQv2fniPsHFgNDLQHTPyUhPb4qE KKQG4oje3n95OH7A0pbJa6MRrVMhcoJC0lgk/WgPR4utGMDI3XurVif0/RYb94= 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=existence, friends X-HELO: mail-yw0-f193.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:in-reply-to:references:from:date :message-id:subject:to; bh=Z1VwgeQw4Lv5Rx4b0Z+wLiW5x7naMfrizMQ/s5uznTA=; b=oOFtCzbJAjzHXSDVdrqx4rvimhJUzg3Fw+DkUA96uk5fOuynnz59HTyyVv5q0B5dRS ANfEgnhB5ggSMl9FU7YX2PV8rhPpi1lYLc+J7jM+QrcLNnAzy/eTHHE+UrceG1ZH06H6 R1qAlU5bpC3OIfjLAIWefVnjOjW+JrffVnrXocfTqsn/CIewRbUQQA69sq6bltAj9Qfv GvseaAxspOoPAg0QzHIwDUF1KQGGLELmW65DsPYEKCUBQC1R8fZqtmurKpPlNlbBPWrb TsYsbA0c6wKQHYqypiQ/KKY1KybaZBDpKdLManwaJwddKe0w/ifcZaCkUv+jXFL5kWL0 cuZw== X-Gm-Message-State: AHYfb5ig/1GFsl2uLa+2N3h4sHen4b2QL+Is46GjeIqJErYrpz0tBn0d gsZHvxd5XUisBb1rkcno0otrzGcGUjcE X-Received: by 10.13.204.130 with SMTP id o124mr3194783ywd.119.1504003314914; Tue, 29 Aug 2017 03:41:54 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20170823160803.GG7469@calimero.vinschen.de> References: <20170823083346 DOT GB7469 AT calimero DOT vinschen DOT de> <20170823160803 DOT GG7469 AT calimero DOT vinschen DOT de> From: Erik Bray Date: Tue, 29 Aug 2017 12:41:54 +0200 Message-ID: Subject: Re: Strange bug with /dev/console in mintty To: cygwin AT cygwin DOT com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes On Wed, Aug 23, 2017 at 6:08 PM, Corinna Vinschen wrote: > On Aug 23 10:33, Corinna Vinschen wrote: >> On Aug 22 18:49, Erik Bray wrote: >> > 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 >> >> /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. > > 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, this patch makes sense. Indeed, the existence check just using GetConsoleCP() was a problem I had noted as well, and the main problem for me was simply that /dev/con{in,out,sole} were being listed under /dev/ at all when not attached to a Windows console (so that code I had that was looping over /dev/ entries would break). -- 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