[OT] figuring out which files have F_CLOEXEC
perl at aaroncrane.co.uk
Fri Mar 27 16:51:36 GMT 2009
Peter Corlett writes:
> open() with ">&" does dup(2) under the hood. Without testing, I'd
> have assumed that when the new filehandle is closed, it won't close
> the duped file handle. I can't recall whether the close-on-exec flag
> is passed through on duping though.
Unfortunately, dup(2) (and dup2(2)) give you a new fd that doesn't
share fd flags with the original. (That's the thing that distinguishes
fd flags (of which FD_CLOEXEC is probably the only one) from other fd
metadata like seek position and O_* mode.)
It's a tricky problem, and even if it can be done, I don't think it
can be done easily. I think you'd need to be able to swap in a
replacement fd for a filehandle without closing the original fd, or
some such; and I can't see a way of doing that.
Nick, what would be bad in your situation about fork/execing a script
which prints out all file descriptors that were open when it started?
Aaron Crane ** http://aaroncrane.co.uk/
More information about the london.pm