On Tue, Nov 02, 2010 at 09:59:12PM -0400, Uri Guttman wrote:
> well, perl keeps it open so it can be used by anyone reading from
> DATA. you can check for it specially with some code i got from
> someone. it is special in that it is NOT tainted while all other handles
> are.
Without delving further into whether or not it was appropriate for
me to close the descriptor for DATA, I'm still curious about what
I had originally written about: should closing a descriptor have
caused the associated file handle to close?
It was pointed out that this list strips attachments, so here is
my code.
I had described my symptoms in my original post, if any of this is
still of any interest to this list.
8<--------------------------- cut here ----------------------------
#!/usr/bin/perl
# env PERL5LIB=. ./bar.pl
use strict;
use warnings;
use Foo;
# works as expected
Foo::info;
Foo::print_end_data;
Foo::close_fds;
#Foo::seek_data(); # insufficient
Foo::_init_DATA; # sufficient
Foo::info;
Foo::print_end_data;
8<--------------------------- cut here ----------------------------
package Foo;
use strict;
use warnings;
use Sys::Syslog;
use POSIX qw(:limits_h);
use Cwd qw(abs_path);
my $_DATA_src=abs_path(__FILE__);
my $_DATA_pos=tell(DATA);
my @_DATA_stat=stat(DATA);
sub out_syslog
{
openlog $0, 'cons,pid', 'user';
my @str = map { defined $_ ? $_ : '<undefined>' } @_;
syslog 'info', '%s', "[". join("][", @str) . "]";
closelog;
}
sub _init_DATA
{
if ( ! stat(DATA) )
{
open(DATA, '<', $_DATA_src ); # ignore error?
}
seek DATA, $_DATA_pos, 0;
}
sub info
{
my $res;
# out_syslog ("info", "_DATA_stat", join(',', @_DATA_stat) );
# out_syslog ("info", "_DATA_pos", $_DATA_pos );
out_syslog ("info", "fileno", $res = fileno(DATA), $res );
out_syslog ("info", "tell", $res = tell(DATA), $res );
out_syslog ("info", "eof", $res = eof(DATA), $res );
my @stat = stat(DATA);
out_syslog ("info", "stat", join(',', @stat), $#stat );
}
sub close_fds
{
out_syslog ("close_fds");
foreach my $fd (0 .. POSIX::sysconf(&POSIX::_SC_OPEN_MAX))
{
my $res = POSIX::close $fd;
}
}
sub seek_data
{
my $pos = shift;
my $new = defined $pos ? $pos : $_DATA_pos ;
out_syslog ("seek_data", $new);
seek DATA, $pos, 0;
}
sub print_end_data
{
my $line;
my $pos = tell(DATA);
while(<DATA>) { $line = $_; }
out_syslog ("print_end_data", $line );
}
1;
__DATA__
Random text; don't mind me...
8<--------------------------- cut here ----------------------------
--
Brian Reichert <[email protected]>
55 Crystal Ave. #286
Derry NH 03038-1725 USA BSD admin/developer at large
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm