• grep-2.27-1 fails when >/dev/null 2>&1

    From Lars Bro@21:1/5 to All on Tue Jan 3 21:50:02 2017
    --001a113d0ad4005fe8054536ac86
    Content-Type: text/plain; charset=UTF-8

    Hi list,

    I am using Debian Stretch, obtained with debootstrap (as of Jan 02 2017).
    Linux kernel of the host is 4.4.6, and the following is run in a chroot.
    File system is ext4.

    When I try to run "./configure" of one of the applications I use, it fails, claiming that gmake is not present.

    When looking into the "configure script" I find this construct:

    /bin/sh -c 'make --version | grep GNU' >/dev/null 2>&1

    And when I test it, I see this:

    root@mini:/# /bin/sh -c 'make --version | grep GNU' >/dev/null 2>&1 root@mini:/# echo $?
    2
    root@mini:/# /bin/sh -c 'make --version | grep GNU' >/dev/null 2>/dev/null root@mini:/# echo $?

    0
    root@mini:/#

    There is apparently something that goes wrong when "dup(2)" is used as in
    &1

    I did an strace of the two constructs:
    This is the failing:

    "/bin/sh -c 'make --version | gre"..., 8192) = 55
    open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
    fcntl(1, F_DUPFD, 10) = 11
    close(1) = 0
    fcntl(11, F_SETFD, FD_CLOEXEC) = 0
    dup2(3, 1) = 1
    close(3) = 0
    fcntl(2, F_DUPFD, 10) = 12
    close(2) = 0
    fcntl(12, F_SETFD, FD_CLOEXEC) = 0
    dup2(1, 2)

    [pid 11678] read(0, "GNU Make 4.1\nBuilt for x86_64-pc"..., 32768) =
    297
    [pid 11678] splice(0, NULL, 1, NULL, 32768, SPLICE_F_MOVE) = -1
    EINVAL
    (Invalid argument)


    And this one works

    read(0, /bin/sh -c 'make --version | grep GNU' > /dev/null
    /dev/null
    " /bin/sh -c 'make --version | gr"..., 8192) = 64
    open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
    fcntl(1, F_DUPFD, 10) = 11
    close(1) = 0
    fcntl(11, F_SETFD, FD_CLOEXEC) = 0
    dup2(3, 1) = 1
    close(3) = 0
    open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
    fcntl(2, F_DUPFD, 10) = 12
    close(2) = 0
    fcntl(12, F_SETFD, FD_CLOEXEC) = 0
    dup2(3, 2) = 2
    close(3)

    [pid 11689] read(0, "GNU Make 4.1\nBuilt for x86_64-pc"..., 32768) =
    297
    [pid 11689] splice(0, NULL, 1, NULL, 32768, SPLICE_F_MOVE) = 0

    This suggests that there is something with the "splice(2)" system call.

    I tried with grep_2.25-6 wich was in Stretch before. It works as below:

    [pid 11821] <... read resumed> "GNU Make 4.1\nBuilt for x86_64-
    pc"...,
    32768) = 297
    ...
    [pid 11821] read(0, "", 32768) = 0
    [pid 11821] write(1, "GNU Make 4.1\nLicense GPLv3+: GNU"..., 91) = 91


    It seems to work because it uses read(0,...) and write(1,...) instead of splice().

    I could temporarily downgrade grep to that version, but I fear that the
    problem may be of a more general nature.

    yours,

    Lars Bro

    --001a113d0ad4005fe8054536ac86
    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable

    <div dir="ltr">Hi list,<br><br>I am using Debian Stretch, obtained with debootstrap (as of Jan 02 2017). Linux kernel of the host is 4.4.6, and the following is run in a chroot. File system is ext4.<br><br>When I try to run &quot;./configure&quot; of one
    of the applications I use, it fails, claiming that gmake is not present.<br><br>When looking into the &quot;configure script&quot; I find this construct:<br><br>/bin/sh -c &#39;make --version | grep GNU&#39; &gt;/dev/null 2&gt;&amp;1<br><br>And when I
    test it, I see this:<br><br>root@mini:/# /bin/sh -c &#39;make --version | grep GNU&#39; &gt;/dev/null 2&gt;&amp;1<br>root@mini:/# echo $?<br>2<br>root@mini:/# /bin/sh -c &#39;make --version | grep GNU&#39; &gt;/dev/null 2&gt;/dev/null<br>root@mini:/#
    echo $?<br>0<br>root@mini:/#<br><br>There is apparently something that goes wrong when &quot;dup(2)&quot; is used as in 2&gt;&amp;1<br><br>I did an strace of the two constructs:<br>This is the failing:<br><br>&quot;/bin/sh -c &#39;make --version | gre&
    quot;..., 8192) = 55<br>open(&quot;/dev/null&quot;, O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3<br>fcntl(1, F_DUPFD, 10)                   = 11<br>close(1)                                = 0<br>fcntl(11, F_SETFD, FD_CLOEXEC)         Â
     = 0<br>dup2(3, 1)                              = 1<br>close(3)                                = 0<br>fcntl(2, F_DUPFD, 10)                   = 12<br>close(2)                                = 0<br>
    fcntl(12, F_SETFD, FD_CLOEXEC)          = 0<br>dup2(1, 2)<br><br>[pid 11678] read(0, &quot;GNU Make 4.1\nBuilt for x86_64-pc&quot;..., 32768) =<br>297<br>[pid 11678] splice(0, NULL, 1, NULL, 32768, SPLICE_F_MOVE) = -1<br>EINVAL <br>(Invalid argument)
    <br><br><br>And this one works<br><br>read(0,  /bin/sh -c &#39;make --version | grep GNU&#39; &gt; /dev/null<br>2&gt;/dev/null<br>&quot; /bin/sh -c &#39;make --version | gr&quot;..., 8192) = 64<br>open(&quot;/dev/null&quot;, O_WRONLY|O_CREAT|O_TRUNC,
    0666) = 3<br>fcntl(1, F_DUPFD, 10)                   = 11<br>close(1)                                = 0<br>fcntl(11, F_SETFD, FD_CLOEXEC)          = 0<br>dup2(3, 1)                              = 1<br>close(3)
                                   = 0<br>open(&quot;/dev/null&quot;, O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3<br>fcntl(2, F_DUPFD, 10)                   = 12<br>close(2)                                = 0<br>fcntl(12, F_
    SETFD, FD_CLOEXEC)          = 0<br>dup2(3, 2)                              = 2<br>close(3)<br><br>[pid 11689] read(0, &quot;GNU Make 4.1\nBuilt for x86_64-pc&quot;..., 32768) =<br>297<br>[pid 11689] splice(0, NULL, 1, NULL, 32768,
    SPLICE_F_MOVE) = 0<br><br>This suggests that there is something with the &quot;splice(2)&quot; system call.<br><br>I tried with grep_2.25-6 wich was in Stretch before. It works as below:<br><br>[pid 11821] &lt;... read resumed&gt; &quot;GNU Make 4.1\
    nBuilt for x86_64-<br>pc&quot;..., <br>32768) = 297<br>...<br>[pid 11821] read(0, &quot;&quot;, 32768)          = 0<br>[pid 11821] write(1, &quot;GNU Make 4.1\nLicense GPLv3+: GNU&quot;..., 91) = 91<br><br><br>It seems to work because it uses read(0,
    ...) and write(1,...) instead of splice().<br><br>I could temporarily downgrade grep to that version, but I fear that the problem may be of a more general nature.<br><br>yours,<br><br>Lars Bro<br></div>

    --001a113d0ad4005fe8054536ac86--

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Adrian Bunk@21:1/5 to Lars Bro on Sun Jan 15 23:10:02 2017
    On Tue, Jan 03, 2017 at 09:39:59PM +0100, Lars Bro wrote:
    Hi list,

    Hi Lars,

    I am using Debian Stretch, obtained with debootstrap (as of Jan 02 2017). Linux kernel of the host is 4.4.6, and the following is run in a chroot.
    File system is ext4.

    When I try to run "./configure" of one of the applications I use, it fails, claiming that gmake is not present.

    When looking into the "configure script" I find this construct:

    /bin/sh -c 'make --version | grep GNU' >/dev/null 2>&1

    And when I test it, I see this:

    root@mini:/# /bin/sh -c 'make --version | grep GNU' >/dev/null 2>&1 root@mini:/# echo $?
    2
    root@mini:/# /bin/sh -c 'make --version | grep GNU' >/dev/null 2>/dev/null root@mini:/# echo $?
    0
    root@mini:/#
    ...

    thanks for your report, can you submit it as a bug report against the
    grep package?

    Upstream bug report and patch for this issue are at
    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25283

    yours,

    Lars Bro

    Thanks
    Adrian

    --

    "Is there not promise of rain?" Ling Tan asked suddenly out
    of the darkness. There had been need of rain for many days.
    "Only a promise," Lao Er said.
    Pearl S. Buck - Dragon Seed

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)