Messages in this thread | | | From | Linus Torvalds <> | Date | Sun, 1 Apr 2012 10:20:59 -0700 | Subject | Re: [PATCH] nextfd(2) |
| |
On Sun, Apr 1, 2012 at 5:57 AM, Alexey Dobriyan <adobriyan@gmail.com> wrote: > > BSD added closefrom(fd) which is OK for this exact purpose but suboptimal > on the bigger scale. closefrom(2) does only close(2) (obviously :-) > closefrom(2) siletly ignores errors from close(2) which in theory is not OK > for userspace. > > So, don't add closefrom(2), add nextfd(2).
I don't disagree with this, but I don't think it's worth a new file of its own - I think it should go next to dup() and friends (currently in fs/fcntl.h).
Also, I think you should:
(a) at a minimum use the bitmap. It's easy:
struct fdtable *fdt;
rcu_read_lock(); fdt = files_fdtable(current->files); .. maximum fd in fdt->max_fds ... .. you have the bitmap in fdt->open_fds ..
(b) I'd also suggest you add a "flag" argument and have at least one bit option for "search for next *free* file table entry". I'm not sure anybody wants it, but it is kind of the same operation, and having a "flags" field means that it's extensible in the future if people want to find the next cloexec fd or whatever. Or if they just want to find the *last* fd, or something.
But I think the concept makes sense.
Linus
| |