Article 9028 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:9028
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.utdallas.edu!corpgate!bnrgate!bnr.co.uk!uknet!pipex!howland.reston.ans.net!agate!boulder!wraeththu.cs.colorado.edu!tchrist
From: Tom Christiansen <[email protected]>
Subject: Re: How to close an unknown descriptor from a perl script
Message-ID: <[email protected]>
Originator: [email protected]
Sender: [email protected] (USENET News System)
Reply-To: [email protected] (Tom Christiansen)
Organization: University of Colorado, Boulder
References: <[email protected]>
Date: Sun, 19 Dec 1993 16:43:25 GMT
Lines: 34

:-> In comp.lang.perl, [email protected] writes:
:    I figure the only way this could be happening is if a descriptor
:to the client is inadvertently kept open by httpd and passed to the
:perl script.  So how can the perl script guarantee that it has closed
:ALL descriptors.  A C program could just call close on descriptors
:0 to n where n is big enough and ignore all errors on non-opened
:descriptors.

Probably the easiest way is

   require 'syscall.ph';
   for ($fd = 3; $fd < 200; $fd++) {
       syscall(&SYS_close, $fd);
   }

But if your C library doesn't support syscall(), you'll have to do it
differently.  I'll assume that you aren't putting file handles into
other packages:

   foreach $symname ( keys %_main ) {
       next unless defined fileno($symname);
       next if $symname =~ /^STD(IN|OUT|ERR)$/;
       close($symname);
   }

You might also look into $^F.

--tom


--
   Tom Christiansen      [email protected]
     "Will Hack Perl for Fine Food and Fun"
       Boulder Colorado  303-444-3212