develooper Front page | perl.perl5.porters | Postings from February 2013

Re: [perl #116659] closing STDIN causes warning when openingunrelated file

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
February 7, 2013 20:32
Subject:
Re: [perl #116659] closing STDIN causes warning when openingunrelated file
Message ID:
CAHAeAG7kkDv+srPTA+cEdLjxBy-osmDyyBGx3NGQ8_Zcke=yHQ@mail.gmail.com
On Thu, Feb 7, 2013 at 8:54 PM, David Golden <xdg@xdg.me> wrote:

> On Thu, Feb 7, 2013 at 9:47 AM, Eirik Berg Hanssen
> <Eirik-Berg.Hanssen@allverden.no> wrote:
> >   (What might break?  Do some system prevent output on file handle 0?
>  Could
> > a child process inherit this fd0, and blow up since it is opened, but not
> > for reading?)
>
> * You close STDIN (for whatever reason)
> * You require a module that has a __DATA__ section
> * You launch a process... and it's STDIN is in the __DATA__ section.
>
> Example:
>
> # Foo.pm
> package Foo;
> 1;
> __DATA__
> Just another perl hacker
>
> ###########
>
> # run.pl
> use v5.10;
> use strict;
> use warnings;
> use lib '.';
>
> close STDIN;
> require Foo;
> say `/bin/cat`;
>
> ###########
>
> $ perl run.pl
> Just another perl hacker
>

  That seems like a perfectly good answer – to a different question. ;-)

  Thanks, but you're not reopening fd0 for writing, and so don't even get
the warning.

  What you have done (by way of require) is open fd0 for reading.  Valid
gotcha, but not relevant to this warning.

  If anything, this would suggest a warning when reopening fd0 for
reading.  Maybe there should be ... maybe at least require should just not
do it ... or maybe this is another case of not keeping people from doing
clever things. ;-)

  On my current system, I don't get a warning when I'm reopening fd0 for
reading.  Why do I get one when reopening fd0 for writing?

  (And vice-versa for fd1 and fd2, of course.)


Eirik

Thread Previous | Thread Next


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