Shutting down fds prior to execvpe in rainbow/inject.py: joyride 247 under Qemu
Albert Cahalan
acahalan at gmail.com
Wed Nov 7 01:09:29 EST 2007
Marcus Leech writes:
> I experimentally put some code just before the execvpe() in
> inject.py to close FDs >= 3 and <= 10. I picked 10 out of
> the air, but I wouldn't expect there to be many open file
> descriptors at that point. Actually, given the semantics of dup(),
> you could use it to probe what the maximum FD number is just before
> execvpe(), so the terminating condition could be something
> like <= dup(0).
I don't see how dup() would help you. Remember, you could get
back fd 123 even if fd 12345 was the last one allocated and is
still in use. You get the lowest free fd.
You can do readdir() on /proc/self/fd to list them, being
careful to not close the fd used for reading the directory
until you have read the whole directory.
More information about the Devel
mailing list