Date: Sat, 27 Jan 2001 01:44:23 -0500 From: Garance A Drosihn <drosih@rpi.edu> To: mouss <usebsd@free.fr>, hackers@FreeBSD.ORG Cc: Garrett Wollman <wollman@khavrinen.lcs.mit.edu> Subject: Re: [kernel patch] fcntl(...) to close many descriptors Message-ID: <p05010400b6981565909b@[128.113.24.47]> In-Reply-To: <4.3.0.20010126193228.06e2a200@bluesun> References: <4.3.0.20010126193228.06e2a200@bluesun>
next in thread | previous in thread | raw e-mail | index | archive | help
At 7:32 PM +0100 1/26/01, mouss wrote: >Hi, > >I've modified the kernel to add F_CLOSEM functionality to fcntl. >(I've seen this in some AIX docs). > >The purpose is allow a process to close all its filedescriptors >starting from a given value without issuing thousands of close() >syscalls. This may be used for programs that daemonize themselves >(or one of their children) after some amount of work, when many >fd's has been opened. The program would simply call > fcntl(minclose, F_CLOSEM, 0); > >The patch concerns /sys/kern/kern_descriptors.c and fcntl.h >(and of course the corresponding manpage). > >Is this functionality worth inclusion in the kernel (or should >I throw away the patch)? are there any kind souls to review the >patch? In a number of programs, I've seen references to a "closeallfds" routine, which seems to do this. Right now (at 1am), the only program I can think of which did this is 'lpr', and it has it's own implementation of closeallfds. So in that case it isn't a system routine, and it just loops thru getdtablesize() fd's closing them all. On the other hand, I seem to remember this being done (in some other program, if not in lpr) because closeallfds *is* a system routine in some place or another. The intent of closeallfds is the same as what you have implemented, as it is: void closeallfds(int start); While I understand that defining a new routine is more work than just adding a parameter to an existing routine, I do think it is more appropriate to have that new routine than to use fcntl for this. The description for fcntl says the first parameter is: a descriptor to be operated on by 'cmd' as described below. For the proposed F_CLOSEM command, it does not operate on the GIVEN fd, it operates on a whole bunch of OTHER fd's. This means that a program which calls fcntl with a cmd-argument which is different than the programmer thinks is being passed could cause some pretty painful-to-debug errors in sections of the program which have nothing to do with the section that has the bug. Of the various operating systems I use, none of them seem to actually have a closeallfds, but maybe someone else will remember where it comes from. Certainly it would be nice to have this capability implemented somewhere in the system level, where some useful optimization could be done. -- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05010400b6981565909b>