develooper Front page | perl.perl5.porters | Postings from December 2011

[perl #10006] STDIN inaccessable after undef'ing it

Thread Previous
From:
James E Keenan via RT
Date:
December 31, 2011 06:04
Subject:
[perl #10006] STDIN inaccessable after undef'ing it
Message ID:
rt-3.6.HEAD-14510-1325340236-1106.10006-15-0@perl.org
On Fri Jun 28 01:38:02 2002, d@niel-berlin.de wrote:
> To: perlbug@perl.org
> Subject: STDIN inaccessable after undef'ing it
> Reply-To: fw8y079@public.uni-hamburg.de
> 
> This is a bug report for perl from fw8y079@public.uni-hamburg.de,
> generated with the help of perlbug 1.33 running under perl v5.6.1.
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> # This works:
> #
> open (FH, '</proc/meminfo') || die;                 # opens that file
> 
> print `ls -l /proc/$$/fd | grep -v total`;            # output ok
> undef *FH;                                                    # close
_and_
> undef FH
> print `echo;ls -l /proc/$$/fd | grep -v total`;    # output ok
> 
> #------------------------------
> 
> # This makes *STDIN inaccessable without closing it:
> #
> undef *STDIN;
> print `ls -l /proc/$$/fd | grep -v total`;
> 
> # Output #1
> #lrwx------ 1 root root 64 Jun 28 17:20 0 -> /dev/tty3
> #lrwx------ 1 root root 64 Jun 28 17:20 1 -> /dev/tty3
> #lrwx------ 1 root root 64 Jun 28 17:20 2 -> /dev/tty3
> #lr-x------ 1 root root 64 Jun 28 17:20 3 -> pipe:[17052169]
> #lr-x------ 1 root root 64 Jun 28 17:20 5 -> pipe:[17052170]
> 
> close (STDIN);
> print `echo; ls -l /proc/$$/fd | grep -v total`;
> 
> # Output #2
> #lrwx------ 1 root root 64 Jun 28 17:20 0 -> /dev/tty3
> #lrwx------ 1 root root 64 Jun 28 17:20 1 -> /dev/tty3
> #lrwx------ 1 root root 64 Jun 28 17:20 2 -> /dev/tty3
> #lr-x------ 1 root root 64 Jun 28 17:20 3 -> pipe:[17052173]
> 
> #----------------------
> 
> # If STDIN is dup'ed before ('' open (FH, '<&=STDIN'); ''),
> # then ''close (FH)'' closes FD 0 !
> # Else it's - imho - impossible to access FD 0...
> 
> Thx,
> Daniel Berlin
> 

Reviewing this older ticket today, I could not reproduce the original
poster's results for the second part of his example.

I used the following for the second part of the example, and ran it on
perl 5, version 14, subversion 0 (v5.14.0) built for i686-linux:

#####
$ cat 10006b.pl
#!/usr/local/bin/perl
use strict;
use warnings;

undef *STDIN;
print `ls -l /proc/$$/fd | grep -v total`;

close (STDIN);
print `echo; ls -l /proc/$$/fd | grep -v total`;
#####

Output:

#####
$ perl 10006b.pl
lrwx------ 1 jimk jimk 64 Dec 31 08:59 0 -> /dev/pts/0
lrwx------ 1 jimk jimk 64 Dec 31 08:59 1 -> /dev/pts/0
lrwx------ 1 jimk jimk 64 Dec 31 08:59 2 -> /dev/pts/0
lr-x------ 1 jimk jimk 64 Dec 31 08:59 3 -> pipe:[101535898]
close() on unopened filehandle STDIN at 10006b.pl line 8.

lrwx------ 1 jimk jimk 64 Dec 31 08:59 0 -> /dev/pts/0
lrwx------ 1 jimk jimk 64 Dec 31 08:59 1 -> /dev/pts/0
lrwx------ 1 jimk jimk 64 Dec 31 08:59 2 -> /dev/pts/0
lr-x------ 1 jimk jimk 64 Dec 31 08:59 3 -> pipe:[101535912]
#####

However, I don't understand the problem well enough to say whether this
difference supports or refutes the poster's contention.  Thoughts?

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=10006

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About