GNU bug report logs - #36455
Question on reading from socket(pair) instead from pipe

Previous Next

Package: grep;

Reported by: "Dr. Werner Fink" <werner <at> suse.de>

Date: Mon, 1 Jul 2019 06:23:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 36455 in the body.
You can then email your comments to 36455 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#36455; Package grep. (Mon, 01 Jul 2019 06:23:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Dr. Werner Fink" <werner <at> suse.de>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Mon, 01 Jul 2019 06:23:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Dr. Werner Fink" <werner <at> suse.de>
To: bug-grep <at> gnu.org
Subject: Question on reading from socket(pair) instead from pipe
Date: Mon, 1 Jul 2019 08:22:36 +0200
[Message part 1 (text/plain, inline)]
Hi,

with grep 3.3 I see for a FIFO this

  echo XXX | strace grep -E XXX
  [...]
  fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0xc), ...}) = 0
  stat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}) = 0
  fstat(0, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
  lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
  read(0, "XXX\n", 98304)                 = 4
  fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0xc), ...}) = 0
  write(1, "XXX\n", 4XXX)                    = 4
  read(0, "", 98304)                      = 0
  close(1)                                = 0
  close(2)                                = 0
  exit_group(0)                           = ?
  +++ exited with 0 +++

prefect but with libpipeline configured to use much faster socketpairs I see
this:

  strace -f ./mgrep -e XXX
  clone(strace: Process 2020 attached
  child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fb632fb4a10) = 2020
  [...]
  [pid  2020] execve("/usr/bin/grep", ["grep", "-e XXX"], 0x7ffd31f42ea8 /* 128 vars */ <unfinished ...>
  [...]
  [pid  2020] fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0xc), ...}) = 0
  [pid  2020] stat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}) = 0
  [pid  2020] fstat(0, {st_mode=S_IFSOCK|0400, st_size=0, ...}) = 0
  [pid  2020] lseek(0, 0, SEEK_CUR)       = -1 ESPIPE (Illegal seek)
  [pid  2020] read(0, "XXX\n", 98304)     = 4
  [pid  2020] read(0, "", 98304)          = 0
  [pid  2020] close(1)                    = 0
  [pid  2020] close(2)                    = 0
  [pid  2020] exit_group(1)               = ?
  [pid  2020] +++ exited with 1 +++

IMHO reading data from a FIFO/pipe or from a FSOCK/socket(pair) should result
in the same result.  The mgrep is a simple test C code which uses libpipeline
to write "XXX\n" to a FILE stream used on the input fd of the sub process for
the grep command:

  FILE *xy;
  int fd = dup(1);
  pipeline *p = pipeline_new();
  pipeline_want_in(p, -1);
  pipeline_want_out(p, fd);
  pipecmd *grep = pipecmd_new("/usr/bin/grep");
  [... handle options and arguments ...]
  xy = pipeline_get_infile (p);
  fprintf(xy, "XXX\n");
  fflush(xy);
  fclose(xy);

Nevertheless in both cases stdout for grep is 136/12 aka /dev/pts/12

Werner

-- 
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#36455; Package grep. (Mon, 01 Jul 2019 08:18:01 GMT) Full text and rfc822 format available.

Message #8 received at 36455 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "Dr. Werner Fink" <werner <at> suse.de>, 36455 <at> debbugs.gnu.org
Subject: Re: bug#36455: Question on reading from socket(pair) instead from pipe
Date: Mon, 1 Jul 2019 01:17:41 -0700
Dr. Werner Fink wrote:
> IMHO reading data from a FIFO/pipe or from a FSOCK/socket(pair) should result
> in the same result.

Yes it should, but only if you invoke 'grep' with the same arguments both times, 
which I expect you didn't. Look at the two execve lines in the strace output.




Information forwarded to bug-grep <at> gnu.org:
bug#36455; Package grep. (Mon, 01 Jul 2019 08:50:01 GMT) Full text and rfc822 format available.

Message #11 received at 36455 <at> debbugs.gnu.org (full text, mbox):

From: "Dr. Werner Fink" <werner <at> suse.de>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 36455 <at> debbugs.gnu.org
Subject: Re: bug#36455: Question on reading from socket(pair) instead from pipe
Date: Mon, 1 Jul 2019 10:48:42 +0200
[Message part 1 (text/plain, inline)]
On 2019/07/01 01:17:41 -0700, Paul Eggert wrote:
> Dr. Werner Fink wrote:
> > IMHO reading data from a FIFO/pipe or from a FSOCK/socket(pair) should result
> > in the same result.
> 
> Yes it should, but only if you invoke 'grep' with the same arguments both
> times, which I expect you didn't. Look at the two execve lines in the strace
> output.

Ah ... I see, indeed ... mea culpa
Looks like pipecmd_argf() does not work the way I expected, whereas adding
    pipecmd_arg(grep, "-e");
    pipecmd_arg(grep, "XXX");
does the job.

-- 
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
[signature.asc (application/pgp-signature, inline)]

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 04 Jul 2019 06:49:01 GMT) Full text and rfc822 format available.

Notification sent to "Dr. Werner Fink" <werner <at> suse.de>:
bug acknowledged by developer. (Thu, 04 Jul 2019 06:49:02 GMT) Full text and rfc822 format available.

Message #16 received at 36455-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "Dr. Werner Fink" <werner <at> suse.de>
Cc: 36455-done <at> debbugs.gnu.org
Subject: Re: bug#36455: Question on reading from socket(pair) instead from pipe
Date: Wed, 3 Jul 2019 23:47:50 -0700
Right, closing the bug report.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 01 Aug 2019 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 241 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.