delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/01/24/06:21:54

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=GdqJBR0vjKGt2Gj6c4pFZbW8FOPbP
loJ8rg7kd2n1T5Cy4wwE3O24pmigngZO2EsKo086m26VHAtU4OFXEZR0pLOQYBqd
E4RYp1V6YSjle0rR4Sbpnwj6j0S50ZWfN0nrTH0DHd/g1087MCEMjRvHzmJjzo4M
7d7TxsJhmA0IeY=
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=EFD7K2iL2O6DhGTDOPfRrrF0ObQ=; b=KOE
R4eV/5x4fBX6IeQfRPCQi9kg9bM6ljOp7CRfahSv3q4wwT2YP+I7KoSnCajqkwyC
bnBz6OW22gKT+dSb3n+2JuhKngq0xqGgp++L4JKiVv4UPU3/xU7Nl3Ug6IxaQ9Ga
6s8btFXntMp8c17s6vCqz3sKZ/3HR4Pn66s567Vg=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=cpr
X-HELO: mail-lf1-f42.google.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=7JjCuOIgjB/KbdJqXFYUmSOAtZRCt2hbeOEvFgIPSgY=; b=Kxm43dRmOFun43boGDv3PmIslhHZ2Es/bHKGksG2kvgaGHGUnxf7Ex3dbLi96e4Lqb KZd8u/Oy08ipOf4bZeIab6mnqIrDC2QQeu9Mv8jTMBP4JgmfHfLsWzmlnqD2CuyF353L fZIpRyjbsiHBRq3vug58yKBizAYSYot9LaUeB6ilj0C7JM4WNIwJtLvzLl0wviOxpeBH 7dJNaDX4ZUM4cR3yH9d69AGkXjQ7NBcct9KDDIxg/nj1CbN7enlLgdq9qByyqNPhGU/z lqEDRI1JIHjHzY1EwQCeSKGrv+4RMARhY/ZVnnsqCxOfUHG+bFWNFCM+pSSexgJEYzl+ 8s2Q==
MIME-Version: 1.0
From: Koichi Murase <myoga DOT murase AT gmail DOT com>
Date: Fri, 24 Jan 2020 19:20:48 +0800
Message-ID: <CAFLRLk_3ooYdfWxq8sxNRozfz3e3RH8+bLbcnWN8ZUtrp6sQdg@mail.gmail.com>
Subject: Cygwin-3.1.3: read(2) from /dev/consN returns unexpected EOF after select(2) and redirection
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

--000000000000c45a1b059ce0f3ea
Content-Type: text/plain; charset="UTF-8"

Hi, this is another report related to Cygwin console.

Description:

  In a noncanonical mode of console (where tty is /dev/consN), if
  there is some unprocessed inputs from the user side (i.e., terminal
  side), the combination of select(2) (for read) and redirection
  causes the next attempt of read(2) to return EOF [i.e., read(0, buf,
  sz) = 0] even though the TTY is still alive.  Because of this
  behavior, the shell session unexpectedly closes because the shell
  considers the TTY has been closed.

  This only affects the first attempt of read(2) (in each process)
  after the redirection.

Repeat-By:

  This is a reduced test case to reproduce the problem:

  1. Open cygwin console (pseudo console mode) with Bash

    This can be done by, for example, opening Run dialog with "Win +
    R", typing "C:\cygwin64\bin\bash" and finally pressing "Enter".

  2. Run the following command

    $ stty -icanon; printf '\e[6n'; read -t 0; : < /dev/null; stty sane

    As a result, the terminal response CPR (CSI Pn ; Pn R) to DSR(6)
    request (CSI 6 n) is expected to be inserted in the command line.
    It should look like the following:

    $ 7;1R

    However, in the console, the Bash session is closed by the above
    command because Bash receives EOF from the TTY and considers the
    TTY session has been closed.


  Note: Only the first attempt of read(2) after the redirection
  returns EOF.  This can be confirmed by the following command where
  the Bash session does not close.

    $ stty -icanon; printf '\e[6n'; read -t 0; : < /dev/null; read;
    stty sane

  Note: Also the first read(2) fails for each forked process in the
  session:

    $ stty -icanon; printf '\e[6n'; read -t 0; : < /dev/null; wc -c;
    (read||echo fail;read||echo fail2); read; stty sane
    0
    fail

    success
    $

Repeat-By (2):

  This demonstrates the problem more explicitly by system calls.

  1. Open cygwin console (pseudo console mode)

  2. Compile and run the attached program `min1.cpp'.

    $ g++ -o min1.exe min1.cpp
    $ ./min1

  The expected result is something like

    $ ./min1
    CHR CHR CHR CHR CHR CHR CHR
    $

  However, in the console, it prints EOF and exit.  Also the terminal
  response CPR appears to be lost.

    $ ./min1
    EOF
    $


Thank you,

Koichi

--000000000000c45a1b059ce0f3ea
Content-Type: application/octet-stream; name="min1.cpp"
Content-Disposition: attachment; filename="min1.cpp"
Content-Transfer-Encoding: base64
Content-ID: <f_k5s2pxai0>
X-Attachment-Id: f_k5s2pxai0

LyotLSBCRUdJTiBtaW4xLmNwcCAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKi8KI2luY2x1ZGUgPHVuaXN0ZC5o
PgojaW5jbHVkZSA8dGVybWlvcy5oPgojaW5jbHVkZSA8ZmNudGwuaD4KI2lu
Y2x1ZGUgPGN0eXBlLmg+CgpzdHJ1Y3QgdGVybWlvcyBzZXR1cF90dHkoKSB7
CiAgc3RydWN0IHRlcm1pb3Mgb2xkVGVyb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tLS0tLS0tLS0tLS0tLS0tLS0tLSovCg==


--000000000000c45a1b059ce0f3ea
Content-Type: text/plain; charset=us-ascii


--
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
--000000000000c45a1b059ce0f3ea--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019