Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Aug 1998 09:16:03 -0400 (EDT)
From:      CyberPeasant <djv@bedford.net>
To:        agifford@infowest.com (Aaron D. Gifford)
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: How do I close inherited descriptors?
Message-ID:  <199808051316.JAA19803@lucy.bedford.net>
In-Reply-To: <35C7D0B9.F3DF2306@infowest.com> from "Aaron D. Gifford" at "Aug 4, 98 09:25:45 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808051316.JAA19803>