public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* grep < fifo fails
@ 2018-10-03 15:37 Ole Tange
  2018-10-03 16:50 ` Marco Atzeri
  2018-10-03 18:46 ` Houder
  0 siblings, 2 replies; 9+ messages in thread
From: Ole Tange @ 2018-10-03 15:37 UTC (permalink / raw)
  To: cygwin

This works:

$ mkfifo fifo
$ echo > fifo & grep .  fifo
[1] 10232
[1]+  Done                    echo > fifo

But this fails:

$ echo > fifo & grep . < fifo
[1] 11756
grep: (standard input): Invalid argument
[1]+  Done                    echo > fifo

I see the same behavior on MINGW, but I do not see the same behavior on GNU/Linux.


Regards,

Ole Tange


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-03 15:37 grep < fifo fails Ole Tange
@ 2018-10-03 16:50 ` Marco Atzeri
  2018-10-03 18:46 ` Houder
  1 sibling, 0 replies; 9+ messages in thread
From: Marco Atzeri @ 2018-10-03 16:50 UTC (permalink / raw)
  To: cygwin

Am 03.10.2018 um 17:37 schrieb Ole Tange:
> This works:
>
> $ mkfifo fifo
> $ echo > fifo & grep .  fifo
> [1] 10232
> [1]+  Done                    echo > fifo
>
> But this fails:
>
> $ echo > fifo & grep . < fifo
> [1] 11756
> grep: (standard input): Invalid argument
> [1]+  Done                    echo > fifo
>
> I see the same behavior on MINGW, but I do not see the same behavior on GNU/Linux.
>
>
> Regards,
>
> Ole Tange

I assume it is a consequence of the same problem on files.
You can not use the same source for input and output.

$ echo "prova" > prova.txt

$ cat prova.txt
prova

$ cat prova.txt > prova.txt

$ cat prova.txt

the file was erased



---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-03 15:37 grep < fifo fails Ole Tange
  2018-10-03 16:50 ` Marco Atzeri
@ 2018-10-03 18:46 ` Houder
  2018-10-04 16:02   ` Houder
  1 sibling, 1 reply; 9+ messages in thread
From: Houder @ 2018-10-03 18:46 UTC (permalink / raw)
  To: cygwin

On Wed, 3 Oct 2018 15:37:14, Ole Tange wrote:
> This works:
> 
> $ mkfifo fifo
> $ echo > fifo & grep .  fifo
> [1] 10232
> [1]+  Done                    echo > fifo
> 
> But this fails:
> 
> $ echo > fifo & grep . < fifo
> [1] 11756
> grep: (standard input): Invalid argument
> [1]+  Done                    echo > fifo
> 
> I see the same behavior on MINGW, but I do not see the same behavior on GNU=
> /Linux.

64-@@ bash --version
GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)64
..
64-@@ echo > fifo & grep . < fifo
[1] 1192
[1]+  Done                    echo > fifo
64-@@ grep --version
grep (GNU grep) 3.0
Packaged by Cygwin (3.0-2)
..
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
64-@@ file fifo
fifo: very short file (no magic)
64-@@

@@ bash --version
GNU bash, version 4.4.12(3)-release (i686-pc-cygwin)
..
@@ echo > fifo & grep . < fifo
[1] 4852
[1]+  Done                    echo > fifo
@@ grep --version
grep (GNU grep) 3.0
Packaged by Cygwin (3.0-2)
..
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
@@ file fifo
fifo: very short file (no magic)
@@

Your version of grep ?????

Regards,
Henri


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-03 18:46 ` Houder
@ 2018-10-04 16:02   ` Houder
  2018-10-05 15:32     ` Houder
  0 siblings, 1 reply; 9+ messages in thread
From: Houder @ 2018-10-04 16:02 UTC (permalink / raw)
  To: cygwin

On Wed, 03 Oct 2018 20:46:11, Houder wrote:
> On Wed, 3 Oct 2018 15:37:14, Ole Tange wrote:
> > This works:
> > 
> > $ mkfifo fifo
> > $ echo > fifo & grep .  fifo
> > [1] 10232
> > [1]+  Done                    echo > fifo
> > 
> > But this fails:
> > 
> > $ echo > fifo & grep . < fifo
> > [1] 11756
> > grep: (standard input): Invalid argument
> > [1]+  Done                    echo > fifo
> > 
> > I see the same behavior on MINGW, but I do not see the same behavior on GNU=
> > /Linux.

My apologies. Did not read you post as careful as I should have the first time.
You are correct: grep is in error here.

(utilities from e.g. coreutils do not show this error in the context above)

Regards,
Henri


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-04 16:02   ` Houder
@ 2018-10-05 15:32     ` Houder
  2018-10-08  8:24       ` Houder
  0 siblings, 1 reply; 9+ messages in thread
From: Houder @ 2018-10-05 15:32 UTC (permalink / raw)
  To: cygwin

On Thu, 04 Oct 2018 18:02:03, Houder wrote:
> On Wed, 03 Oct 2018 20:46:11, Houder wrote:
> > On Wed, 3 Oct 2018 15:37:14, Ole Tange wrote:
> > > This works:
> > > 
> > > $ mkfifo fifo
> > > $ echo > fifo & grep .  fifo
> > > [1] 10232
> > > [1]+  Done                    echo > fifo
> > > 
> > > But this fails:
> > > 
> > > $ echo > fifo & grep . < fifo
> > > [1] 11756
> > > grep: (standard input): Invalid argument
> > > [1]+  Done                    echo > fifo
> > > 
> > > I see the same behavior on MINGW, but I do not see the same behavior on GNU=
> > > /Linux.
> 
> My apologies. Did not read your post as careful as I should have the first time.
> You are correct: grep is in error here.

Filed this bug at bug-grep@gnu.org; it is filed under number 32943.

 - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32943

Regards,
Henri


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-05 15:32     ` Houder
@ 2018-10-08  8:24       ` Houder
  2018-10-08 15:03         ` Eric Blake
  2018-10-10  9:53         ` Houder
  0 siblings, 2 replies; 9+ messages in thread
From: Houder @ 2018-10-08  8:24 UTC (permalink / raw)
  To: cygwin

On Fri, 05 Oct 2018 17:32:16, Houder wrote:
> On Thu, 04 Oct 2018 18:02:03, Houder wrote:
> > On Wed, 03 Oct 2018 20:46:11, Houder wrote:
> > > On Wed, 3 Oct 2018 15:37:14, Ole Tange wrote:
> > > > This works:
> > > > 
> > > > $ mkfifo fifo
> > > > $ echo > fifo & grep .  fifo
> > > > [1] 10232
> > > > [1]+  Done                    echo > fifo
> > > > 
> > > > But this fails:
> > > > 
> > > > $ echo > fifo & grep . < fifo
> > > > [1] 11756
> > > > grep: (standard input): Invalid argument
> > > > [1]+  Done                    echo > fifo
> > > > 
> > > > I see the same behavior on MINGW, but I do not see the same behavior on GNU=
> > > > /Linux.
> > 
> > My apologies. Did not read your post as careful as I should have the first time.
> > You are correct: grep is in error here.
> 
> Filed this bug at bug-grep@gnu.org; it is filed under number 32943.
> 
>  - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32943
> 

grep fails on Cygwin because lseek() on Cygwin fails to recognize
that it is applied to a FIFO. As result of that, it returns EINVAL
in errno, where it should return ESPIPE.

Receiving the wrong value in errno forces reset() (in src/grep.c)
to return false, upon which grep fails.

Before v2.27 of grep, a call to S_ISREG(st->st_mode) in reset()
prevented the call of lseek() and made reset() return true.

The call to S_ISREG() has been removed in v2.27 of grep.

The solution would be either to correct Cygwin's executive or to
insert a Cygwin-specific kludge in grep (in reset() ).

Regards,
Henri


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-08  8:24       ` Houder
@ 2018-10-08 15:03         ` Eric Blake
  2018-10-10 11:22           ` Corinna Vinschen
  2018-10-10  9:53         ` Houder
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Blake @ 2018-10-08 15:03 UTC (permalink / raw)
  To: cygwin

On 10/8/18 3:24 AM, Houder wrote:
> grep fails on Cygwin because lseek() on Cygwin fails to recognize
> that it is applied to a FIFO. As result of that, it returns EINVAL
> in errno, where it should return ESPIPE.
> 
> Receiving the wrong value in errno forces reset() (in src/grep.c)
> to return false, upon which grep fails.
> 
> Before v2.27 of grep, a call to S_ISREG(st->st_mode) in reset()
> prevented the call of lseek() and made reset() return true.
> 
> The call to S_ISREG() has been removed in v2.27 of grep.
> 
> The solution would be either to correct Cygwin's executive or to

s/executive/dll/

> insert a Cygwin-specific kludge in grep (in reset() ).

I see no reason to do a one-off kludge to my build of grep (since that 
does not scale - every other app that also makes decisions based on 
errno values would have to make the same kludge), compared to just 
fixing cygwin1.dll for everyone.

But thanks for isolating the problem!

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-08  8:24       ` Houder
  2018-10-08 15:03         ` Eric Blake
@ 2018-10-10  9:53         ` Houder
  1 sibling, 0 replies; 9+ messages in thread
From: Houder @ 2018-10-10  9:53 UTC (permalink / raw)
  To: cygwin

On Mon, 08 Oct 2018 10:24:01, Houder wrote:
...

> > > > On Wed, 3 Oct 2018 15:37:14, Ole Tange wrote:
> > > > > This works:
> > > > > 
> > > > > $ mkfifo fifo
> > > > > $ echo > fifo & grep .  fifo
> > > > > [1] 10232
> > > > > [1]+  Done                    echo > fifo
> > > > > 
> > > > > But this fails:
> > > > > 
> > > > > $ echo > fifo & grep . < fifo
> > > > > [1] 11756
> > > > > grep: (standard input): Invalid argument
> > > > > [1]+  Done                    echo > fifo
...

> grep fails on Cygwin because lseek() on Cygwin fails to recognize
> that it is applied to a FIFO. As result of that, it returns EINVAL
> in errno, where it should return ESPIPE.
[snip]

> The solution would be either to correct Cygwin's executive or to
> insert a Cygwin-specific kludge in grep (in reset() ).

Right.

64-@@ echo aaa > fifo & grep . < fifo
[1] 3956
aaa
[2]+  Done                    echo aaa > fifo

The following rough patch to the Cygwin executive ... uhm, Cygwin DLL,
makes the above work.

winsup/cygwin/fhandler.h:

class fhandler_fifo: public fhandler_base_overlapped
{
...
// Henri
  off_t lseek (off_t, int)
  {
    set_errno (ESPIPE);
    return -1;
  }
...
};

(I cheated; I did a copy/paste of what is already present in fhandler.h)

Regards,
Henri


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: grep < fifo fails
  2018-10-08 15:03         ` Eric Blake
@ 2018-10-10 11:22           ` Corinna Vinschen
  0 siblings, 0 replies; 9+ messages in thread
From: Corinna Vinschen @ 2018-10-10 11:22 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1279 bytes --]

On Oct  8 10:03, Eric Blake wrote:
> On 10/8/18 3:24 AM, Houder wrote:
> > grep fails on Cygwin because lseek() on Cygwin fails to recognize
> > that it is applied to a FIFO. As result of that, it returns EINVAL
> > in errno, where it should return ESPIPE.
> > 
> > Receiving the wrong value in errno forces reset() (in src/grep.c)
> > to return false, upon which grep fails.
> > 
> > Before v2.27 of grep, a call to S_ISREG(st->st_mode) in reset()
> > prevented the call of lseek() and made reset() return true.
> > 
> > The call to S_ISREG() has been removed in v2.27 of grep.
> > 
> > The solution would be either to correct Cygwin's executive or to
> 
> s/executive/dll/
> 
> > insert a Cygwin-specific kludge in grep (in reset() ).
> 
> I see no reason to do a one-off kludge to my build of grep (since that does
> not scale - every other app that also makes decisions based on errno values
> would have to make the same kludge), compared to just fixing cygwin1.dll for
> everyone.
> 
> But thanks for isolating the problem!

I pushed a patch.  Thanks for tracking this down, Henri!


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-10-10 11:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-03 15:37 grep < fifo fails Ole Tange
2018-10-03 16:50 ` Marco Atzeri
2018-10-03 18:46 ` Houder
2018-10-04 16:02   ` Houder
2018-10-05 15:32     ` Houder
2018-10-08  8:24       ` Houder
2018-10-08 15:03         ` Eric Blake
2018-10-10 11:22           ` Corinna Vinschen
2018-10-10  9:53         ` Houder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).