Mail Archives: cygwin/2020/01/25/04:30:16
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:date:from:to:subject:message-id:in-reply-to
|
| :references:mime-version:content-type:content-transfer-encoding;
|
| q=dns; s=default; b=r+pWOG2OC61EC5LxkxUBUdUxtIdNyffm7kWebFOhVxC
|
| hpeUzRsYsoK9TqvZipT20Y7yTjVp/aRiYOW2bJxX9u+HPx5SpHH/02TlytiqBK+H
|
| KBbwYWF6QhjgD7HGg9OJdboj0cxtUxB+3/xbcpTS/ZrpDHHlv+8a4mBpNAFvC1ho
|
| =
|
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:date:from:to:subject:message-id:in-reply-to
|
| :references:mime-version:content-type:content-transfer-encoding;
|
| s=default; bh=AGo/x0IOVQymxg8XEgWHvYPh5rQ=; b=pRzV6uuk0Fvvvkyxt
|
| XAKFrOs+nHijBZOx8InJzq581gQlJSVCzAllT1RSVgF9TQOapXXAEa0ArwJgu1kp
|
| 1JYyvLMhXEYzmXJBevIQiB+Wn+2LKvA8dwBjQHBoRCXfp7huYz9XFUasddPoHgsq
|
| heD/sYtX5VxdTBGdGZsOEMUBrk=
|
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.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=murase, Murase, Koichi, 3.1.2
|
X-HELO: | conssluserg-03.nifty.com
|
DKIM-Filter: | OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com 00P9T3kd031344
|
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp; s=dec2015msa; t=1579944543; bh=PEouH2CZR6t26O5pkYKh7LQn+0aHUFXJF/S6/XwxsQM=; h=Date:From:To:Subject:In-Reply-To:References:From; b=gqdlK4ByB+wRxckYPNzXQ8lzBBX+uKBKcn3if6vgnd17QvbmEnvPruElpOeGaENkZ JBwDYSTJWpI5PzSrPoOdqYh8hbt6uwfq1ZgQC07/weYwDFi5eAb2bTQpGX1TKv++ph l+tSvXYjujbWIJQRPkv5KnNcEdDwwVcY6Zqhhg+5atgMeGJI3VSBI2HpxO72VRbfJ0 ExIVwq/XSX4Q18BWE0s3TL9qpp1jDUwpY9ZmTMf56vIol2iNO1Q0mmTqXjFOVUwNP5 MgeWgrjIBonkkUzTyTOpsXSS8KKC128Li1iRvOISdWysc1Fu+wCw5XWO9VxdwWrK+a k43ZOR00Epekw==
|
Date: | Sat, 25 Jan 2020 18:29:10 +0900
|
From: | Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
|
To: | cygwin AT cygwin DOT com
|
Subject: | Re: Cygwin-3.1.3: read(2) from /dev/consN returns unexpected EOF after select(2) and redirection
|
Message-Id: | <20200125182910.1d13e8d9bdf8af852135e450@nifty.ne.jp>
|
In-Reply-To: | <CAFLRLk_3ooYdfWxq8sxNRozfz3e3RH8+bLbcnWN8ZUtrp6sQdg@mail.gmail.com>
|
References: | <CAFLRLk_3ooYdfWxq8sxNRozfz3e3RH8+bLbcnWN8ZUtrp6sQdg AT mail DOT gmail DOT com>
|
Mime-Version: | 1.0
|
X-IsSubscribed: | yes
|
On Fri, 24 Jan 2020 19:20:48 +0800
Koichi Murase wrote:
> 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
> $
Thanks for the report. The minimum test case would be:
#include <sys/select.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
int fd1 = STDIN_FILENO, fd2;
char c1 = 'A', c2 = 'B';
int r1, r2;
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd1, &readfds);
select(fd1+1, &readfds, NULL, NULL, NULL);
fd2 = dup(fd1);
r1 = read(fd1, &c1, 1);
r2 = read(fd2, &c2, 1);
printf("fd=%d: ret=%d (%c)\n", fd1, r1, c1);
printf("fd=%d: ret=%d (%c)\n", fd2, r2, c2);
return 0;
}
If "12<enter>" is typed in this test case, the expected result is:
12
fd=0: ret=1 (1)
fd=3: ret=1 (2)
However in the console of cygwin 3.1.2, it is:
12
fd=0: ret=1 (1)
fd=3: ret=0 (B)
That is, the chars typed before dup() cannot be read from new fd.
This occurs because the readahead buffer (rabuf) in the console
is newly created by dup(), and does not inherit from the parent.
This test case does not work as expected also in cygwin 3.0.7.
I will submit a patch for this issue, in which rabuf is shared
between all console instances in a process.
--
Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
--
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
- Raw text -