07-28-04 11:19 PM
Viktor Lofgren wrote:
> On Sun, 25 Jul 2004 00:08:29 -0700, Lev Walkin wrote:
>
>
>
>
> Baad programming habits.
>
> Much better to keep track of what you've opened, or use clone().
If we're talking about programming practices, it might be even better
to use fcntl(, F_SETFD, &FD_CLOEXEC), in cases where exec() is planned
down the road.
However, neither "tracking what you've opened", nor "habitually setting
close-on-exec flag" are universally applicable in the real world programming
.
The things is, many libraries (including libc) open file descriptors
"behind the scenes". If a program does not depend on any third-party
libraries and does not use certain libc functions (such as
openlog(3)/syslog(3), getpwnam(3), etc), then yes, keeping track is key.
Otherwise, just closing every possible file descriptor is just plain
better than closing certain ones which are accounted for, and hoping that
accounting was right and no other library opened shadow fds behind
the scenes.
--
Lev Walkin
vlm@lionet.info
[ Post a follow-up to this message ]
|