Shutting down fds prior to execvpe in rainbow/inject.py: joyride 247 under Qemu

Marcus Leech mleech at nortel.com
Wed Nov 7 07:56:33 EST 2007


Albert Cahalan wrote:
> 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.
>
>   
Yes, you're quite right.   Late-night fuzzy thinking on my part.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
URL: <http://lists.laptop.org/pipermail/devel/attachments/20071107/309b7efb/attachment.sig>


More information about the Devel mailing list