Reopening stdin
Maarten Litmaath
maart at cs.vu.nl
Wed Jan 9 06:17:01 AEST 1991
In article <5208 at trantor.harris-atd.com>,
chuck at trantor.harris-atd.com (Chuck Musciano) writes:
)...
)> main()
)> {
)> int fd, i;
)>
)> close(0);
)> fd = open("/etc/passwd", 0);
)> dup2(fd, 0);
)> i = system("cat");
)> exit(i & 0377 ? i | 0200 : i >> 8);
)> }
)...
) I checked dup2(), and it is returning 0, as you would expect. In the
)case of dup2(0, 0), I tried closing stdin, calling open(), and verified
)that I got 0 as the descriptor. I then skipped the dup2 call, called
)system(), and it still failed!
What about this: note that in the example I forgot a close(fd) statement
after the dup2() call; now I expect that you did _not_ forget it in _your_
program, in which case you are closing stdin yourself again!
If this still doesn't explain it, could you post or email a minimal
piece of code that shows the problem?
--
nlp at berlin.mt.cs.cmu.edu: "I heard that an Awk was spotted in Sherwood forest."
rmk at frog.UUCP (Rick Kelly): "It was seen running in the background."
More information about the Comp.unix.questions
mailing list