Hi gnuliebers,First a disclaimer: I'm far from being fluent with fd business, I'm probably asking newbie questions...
We, at Bison Corp., have some bug occurring on Tru64 (http://lists.gnu.org/archive/html/bug-bison/2009-06/msg00004.html ) that seems to be related with our piping into GNU M4. Bison basically reads its input, feeds m4 with various files, and "parses" the output of m4 before producing the expected files.
Currently, we use code from Paul Eggert, subpipe.[hc], attached below. The code works well (and is simple!), but I moved to using gnulib's equivalent piece of code, create_pipe_bidi, to see if it cures our problems. It works well (on my platform) except for one problem: in the test suite, Paul added a test case where bison's stdout is closed. Using the old code, it works well, using create_pipe_bidi, the test fails:
$ make -s check TESTSUITEFLAGS='-v 39' ... 39. output.at:45: testing ... ../../../tests/output.at:45: bison -dv foo.y >&- --- /dev/null 2009-07-15 14:25:13.000000000 +0200+++ /Users/akim/src/kernel/bison/_build/debug/tests/testsuite.dir/at- groups/39/stderr 2009-07-15 14:25:14.000000000 +0200@@ -0,0 +1,2 @@+/opt/local/bin/gm4:/Users/akim/src/kernel/bison/_build/debug/../../ data/yacc.c:172: ERROR: copying inserted file: Bad file descriptor+/opt/local/bin/gm4: write error: Bad file descriptor 39. output.at:45: FAILED (output.at:45)
Reading the code, I don't see why the child should be affected here, but it is.
I have tried to write a small test case for gnulib (made to be eventually included there, at least it would be a useful sample). It shows the same problem, although somewhat differently.
$ ./src/test-pipe; echo $? 0 $ ./src/test-pipe >&-; echo $? ./src/test-pipe: fgets 1 $ ./src/test-pipe <&-; echo $? 141
Sources are attached too.The attempt to use create-pipe-bidi is pushed in Bison's branch candidates/create-pipe-bidi, if some wants to play with it. The test case is compiled as src/test-pipe.
Any help greatly appreciated.
test-pipe.c
Description: Binary data
subpipe.c
Description: Binary data
subpipe.h
Description: Binary data