delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/05/09/15:22:02

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO,RCVD_IN_HOSTKARMA_YE,RCVD_IN_SORBS_WEB,SPF_HELO_PASS
X-Spam-Check-By: sourceware.org
From: "James Johnston" <JamesJ AT motionview3d DOT com>
To: <cygwin AT cygwin DOT com>
References: <020501cd23f2$20f07620$62d16260$@motionview3d.com> <20120427143753 DOT GO25385 AT calimero DOT vinschen DOT de> <025501cd24c6$6a353990$3e9facb0$@motionview3d.com> <4F9B38FB DOT 9030607 AT dancol DOT org> <20120428052727 DOT GA23749 AT ednor DOT casa DOT cgf DOT cx> <4F9BD262 DOT 2000403 AT dancol DOT org> <4FAABEAE DOT 7000309 AT tlinx DOT org>
In-Reply-To: <4FAABEAE.7000309@tlinx.org>
Subject: RE: Cygwin passes through null writes to other software when redirecting standard input/output (i.e. piping)
Date: Wed, 9 May 2012 19:21:34 -0000
Message-ID: <053b01cd2e18$f3f9ce60$dbed6b20$@motionview3d.com>
MIME-Version: 1.0
X-IsSubscribed: yes
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
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id q49JLw7G025853

> -----Original Message-----
> Sent: Wednesday, May 09, 2012 19:00
> Subject: Re: Cygwin passes through null writes to other software when
> redirecting standard input/output (i.e. piping)
>
> I can't say with 100% certainty, but I would bet with 90+% confidence that
> this
> is a bug in MS's libraries -- they "cheat" and use a null/0 byte read as a
> signal for end of file rather than sending out-of-band information that *nix
> supports.

From examining .NET Framework source, it seems clear to me they did not plan on message pipe inputs.  Win32 ReadFile API normally uses a zero byte read to indicate end-of-file; I think it's not cheating.  Pipes present a special case.  I'm not sure how MS's runtime libraries could send out-of-band information; the operating system does not really support this as far as I know?

Of course, these libraries are very widely used... 

> Essentially you need a 'shim' layer between a POSIX compliant subsystem
> to NON-POSIX compliant programs.
> 
> I'm sure that in the case that my assumptions are true, you wouldn't want to
> deliberate put something in cygwin that would make it less POSIX compliant
> when
> it is only to support external-to-cygwin, NON-POSIX compliant programs...
> 
> Note -- I use programs between cygwin and Windows 'alot', so I want these
> things
> to work as well.

Maybe I'm naïve and this is harder than it looks, but couldn't Cygwin determine if the program being piped to links with CYGWIN1.DLL (or similar detection technique), and then use byte or message pipes accordingly?  Example:

# Byte pipe used because Win32Program.exe does not link with CYGWIN1.DLLL
cat Testfile.txt | ./Win32Program.exe
# Message pipe used because grep links with CYGWIN1.DLL
cat Testfile.txt | grep Hello
# Message pipe still used because the program we are calling links with CYGWIN1.DLL
./Win32Program.exe | grep Hello

If that is still not POSIX compliant enough for the sending program (e.g. "cat" in this example), then I suppose Cygwin could automatically insert a message-to-byte pipe shim like the author proposes.  That seems pretty kludgy though.


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


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