Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 04 Aug 1998 21:25:45 -0600
From:      "Aaron D. Gifford" <agifford@infowest.com>
To:        freebsd-questions@FreeBSD.ORG
Subject:   How do I close inherited descriptors?
Message-ID:  <35C7D0B9.F3DF2306@infowest.com>

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

Sorry if you see this message twice.  I posted it yesterday and it seems
it got eaten by a roving quantum black hole.  Hopefully this posting
will have enough momentum to skirt around the edge and escape without
being caught.

Wondering,
Aaron out.
www.eq.net

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?35C7D0B9.F3DF2306>