delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/10/01/10:08:24

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Mon, 01 Oct 2001 23:06:52 +0900 (JST)
Message-Id: <20011001.230652.15243440.gotoh@taiyo.co.jp>
To: cygwin AT cygwin DOT com
Subject: Bug of select() onto PIPE input.
From: Shun-ichi GOTO <gotoh AT taiyo DOT co DOT jp>
X-Mailer: Mew version 2.0.51 on Emacs 20.7 / Mule 4.1 (AOI)
X-Cite-Me: =?iso-2022-jp?B?GyRCOGUbKEI=?=
Mime-Version: 1.0

Hi, cygwin users/developers

## I'm not ML member, please add Cc: gotoh AT taiyo DOT co DOT jp for this thread.

I'm using latest snapshot and encounted to problem around select() for
PIPE input.

The problem is:
  select() onto PIPE input returns immediately as "something exist"
  on command prompt (cmd.exe) and 4nt.

Try attached test program "pipe-select.c" and examine following two
case with some version of DLLs.

(1)  pipe-select

(2)  cat - | pipe-select

With good DLL, (1) waits keyboard input by select() and wait...
When I hit any key, program goes read() and until EOL is start. And repeat.
(2) waits pipe input by select() and wait.
When I enter some chars and ENTER, then program goes read().
Both are good behavior.

With bad DLL, (1) is same to good DLL. But (2) goes read() immediately
although no data is available in PIPE. 

This problem means asyncronous reading using select() is not work if
some input handle is PIPE. For example, OpenSSH executed from NTEmacs is
not work. On this case, ssh.exe goes reading from stdin (PIPE) although
PIPE is empty and blocks processing input from network.

Described above is phenomena on non cygwin shell (cmd.exe and 4nt.exe).
On bash, it seems working good. But once hit CTRL-C to stop select(), 
it hangs. Program cannot terminate select'ing. 
It's another problem.


I checked tests above on command prompt and 4nt.exe on Windows XP and
Windows 2000 with some cygwin1.dll (ver 1.3.3, snap-20010925,
snap-20010927, snap-20010929, snap-20011001) and get results bellow.

cygwin1.dll    result
-----------------------
1.3.3          good
snap-20010925  BAD
snap-20010927  BAD
snap-20010929  good
snap-20011001  BAD



/* pipe-select.c -- test pipe input select()'ing bug. */

#include <stdio.h>
#include <sys/types.h>
#include <sys/select.h>

int
main(int argc, char **argv)
{
    int ret;
    fd_set ifds;
    
    if ( isatty(0) ) {
	puts("stdin is tty");
    } else {
	puts("stdin is NOT tty");
    }

    FD_ZERO(&ifds);
    FD_SET(0, &ifds);
    printf("selecting..."); fflush(stdout);
    ret = select( 1, &ifds, NULL, NULL, NULL);
    printf("ret=%d, ifds=0x%x\n", ret, *(long*)&ifds);
    if ( FD_ISSET(0,&ifds) ) {
	char c;;
	printf("reading: ");fflush(stdout);
	read(0, &c, 1);
	printf("=> '%c'\n", c);
    }
    return 0;
}
// Local Variables:
// compile-command: "gcc pipe-select.c -o pipe-select"
// End:


--- Regards,
 Shun-ichi Goto  <gotoh AT taiyo DOT co DOT jp>
   R&D Group, TAIYO Corp., Tokyo, JAPAN

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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