bug-m4
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: failure with HEAD: stdin seekable


From: Eric Blake
Subject: Re: failure with HEAD: stdin seekable
Date: Sat, 16 Dec 2006 12:42:19 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Ralf Wildenhues on 12/16/2006 8:00 AM:
> Hi Eric, all,
> 
> This new test fails for me on GNU/Linux x86 (Debian testing).
> 
> Cheers,
> Ralf
> 
> #                             -*- compilation -*-
> 63. others.at:458: testing ...
> ../../m4/tests/others.at:466: m4 -b -d  < in.m4
> ../../m4/tests/others.at:473: (m4; cat) < in.m4
> --- - 2006-12-15 11:20:25.790977000 +0100
> +++ /tmp/build/tests/testsuite.dir/at-stdout  2006-12-15 11:20:25.000000000 
> +0100
> @@ -1,2 +1 @@
> -trailing data

Solaris 8 gets this particular test correct, as does CVS cygwin.  So your
failure report means that we have just uncovered a glibc bug.  POSIX
requires the following behavior when stdin is seekable:

$ echo 1 2 3 | tr ' ' '\n' > file
$ (sed -ne 1q; cat) < file
2
3

But glibc mistakenly optimizes exit() and fails to close stdin:

$ strace sed -ne 1q < file 2>&1 | tail
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0xb7db9000
read(0, "1\n2\n3\n", 4096)              = 6
open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=21544, ...}) = 0
mmap2(NULL, 21544, PROT_READ, MAP_SHARED, 3, 0) = 0xb7db3000
close(3)                                = 0
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
Process 11905 detached

Oops - fd 0 was never closed, let alone reset to the last unbuffered
offset, so the cat process is starting from the wrong offset.  It is this
same bug that is breaking the m4 test.  I will file a glibc bug report.

In the meantime, gnulib can probably work around this bug.  m4 already
uses the closeout module.  I think close_stdout be updated to flush and
close stdin for the benefit of implementations (like glibc, or like cygwin
1.5.22 and earlier) where exit() is broken because it fails to reset the
fd offset of seekable stdin.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFhEwb84KuGfSFAYARApFgAJ4lwD3R7oIrdmHMbpblNY1emAyBGQCfUoQM
deH6nC9zy7SoJoGeEd0JPCs=
=8Nd6
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]