Right. This is expected (and defined) behaviour. But do you have
_any_ example where this is used for fds > 2? I can't remember.
And IMHO that would be pretty fragile too. Shell scripts sometimes
open temporary fds > 2 and these are passed to called programs. I.e.
#!/bin/sh
exec 3>log
echo >&3 "script started"
ls /proc/self/fd # gets fd3 already opened
ls /proc/self/fd 4</dev/null # now 3 and 4 already in use...
# or look into any configure script...
So, IMHO as long as some library does not mess with fds 0, 1, and 2
it should be ok [1]. Yes, it would be against the standard but I
still have to find some code where this semantic is used for fds > 2.
Ciao, ET.
PS: I would prefer to keep the standard semantics but the reasons
for that are pretty weak ... ;-)
PPS: Even your sample code is fragile. It breaks if I start it
with ./a.out <&- ;-) (the close(0) is likely to close one end
of the pipe)
[1] Unintentionally setting the controlling tty may be a problem.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/