From owner-freebsd-questions Wed Aug 5 06:16:25 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id GAA11869 for freebsd-questions-outgoing; Wed, 5 Aug 1998 06:16:25 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from lucy.bedford.net (lucy.bedford.net [206.99.145.54]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA11858 for ; Wed, 5 Aug 1998 06:16:22 -0700 (PDT) (envelope-from listread@lucy.bedford.net) Received: (from listread@localhost) by lucy.bedford.net (8.8.8/8.8.8) id JAA19803; Wed, 5 Aug 1998 09:16:03 -0400 (EDT) (envelope-from listread) Message-Id: <199808051316.JAA19803@lucy.bedford.net> Subject: Re: How do I close inherited descriptors? In-Reply-To: <35C7D0B9.F3DF2306@infowest.com> from "Aaron D. Gifford" at "Aug 4, 98 09:25:45 pm" To: agifford@infowest.com (Aaron D. Gifford) Date: Wed, 5 Aug 1998 09:16:03 -0400 (EDT) Cc: freebsd-questions@FreeBSD.ORG X-no-archive: yes Reply-to: djv@bedford.net From: CyberPeasant X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Aaron D. Gifford wrote: > Hello, > > I have a C program I've been working on that will be called by a PHP/FI > 2.0 script (www.php.net) which runs as an Apache web module. I have > discovered that PHP/FI 2.0's PassThru() function (which calls my C > program) does not appear close descriptors that Apache has open (1 per > LISTEN per virtual host, all the log file descriptors per virtual host, > etc.). What I want to do is close all of these unnecessary descriptors > in my own C program before it then execve()'s yet a third program, a > program that should NOT get access to these descriptors. > > Here's what I'm using right now to close everything execpt STDIN, > STDOUT, and STDERR (filenum()s 0, 1, and 2): > > for(fds = getdtablesize(), f=3; f < fds; f++) { > close(f); > } > > It seems to work just fine, but this sure seems an inelegant solution. > What is the "correct" way to discover what descriptors are open and > available and then close them appropriately? Am I missing something > vital here? No, I think this is 'the true way'. Stevens uses it, for example. Suppose there were a kernel call or library routine to do this... how would it be different? about the only increase in elegance would be to make it a function of its own. > Sorry if you see this message twice. I posted it yesterday and it seems > it got eaten by a roving quantum black hole. That was the same one that brushed by the US stock market, I guess. [the party's over, time to pay the piper, blah blah...] Dave -- Bedford County, PA -- 47,000 polite, friendly Appalachians, 4,000 of whom have concealed-carry permits. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message