Messages in this thread | | | Subject | Re: modutils (Re: cipe 1.2.0 & kernel 2.2.x) | Date | Thu, 25 Mar 1999 16:50:00 +0000 (GMT) | From | Malcolm Beattie <> |
| |
Y2K writes: > On Thu, 25 Mar 1999, Malcolm Beattie wrote: > > I wonder if it's worth having a closefdset() syscall used as follows: > > fd_set most; > > FD_ZERO(&most); > > for (i=getdtablesize()-1; i>2; --i) > > FD_SET(i, &most); > > closefdset(&most); [...] > maybe a better solution would be a getopenfdset(fdset *set); > > so in bad pseudo c: > long n; > int bad=0; > fdset all; > getopenfdset(&all); > FD_CLR(0,&all); FD_CLR(1,&all); FD_CLR(2,&all); > while ( notempty(&all)&&(!bad) ) bad=close( firstfd(&all) );
Excellent suggestion. Moreover, we now no longer a new system call. In pseudo C mixed with pseudo Perl
DIR *dir = opendir("/proc/$$/fd"); while (d = readdir(dir)) { close(atoi(d->d_name)); /* and handle error */ }
Hurray, no new sys call needed. It scales nicely and may even be faster on systems with only 256 descriptors since it replaces 253 close() syscalls with 1 open plus 1 getdents + n(open_files) closes. One of the original messages said perl did the "lots of closes" thing but it doesn't. It just sets close-on-exec on all descriptors above the last "system" descriptor, changeable by the special $^F variable or $SYSTEM_FD_MAX is you're "use English"-inclined. It's mainly things like login, daemons and security-related code which close everything. Getting them all to change, assuming I haven't missed anything and assuming that the benefit outweighs the loss of portability (which it might not), is going to be non-trivial though. But this is all now off-topic for linux-kernel so I'll stop there.
--Malcolm
-- Malcolm Beattie <mbeattie@sable.ox.ac.uk> Unix Systems Programmer Oxford University Computing Services
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |