New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perlio handling of dup when some STD streams are closed is messed up #7105
Comments
From stas@stason.orgCreated by stas@rabbit.stason.orgperlio handling of dup when some STD streams are closed is messed up. Consider % perl -wle 'close STDOUT; open my $fh, "<&STDIN" or die;' % perl -wle 'close STDIN; open my $fh, ">&STDOUT" or die;' % perl -wle 'close STDIN; open my $fh, ">&STDERR" or die;' % perl -wle 'close STDIN; open my All these bogus warnings are coming from doio.c:539 538 if (ckWARN(WARN_IO)) { all these cases suffer from the same problem. A dup was taking over one of the A possible solution is try and avoid taking over STD slots by dupping at most Perl Info
|
From nick.ing-simmons@elixent.comStas Bekman <perl5-porters@perl.org> writes:
$fh now has fd=1 and _is_ stdout and hence STDOUT.
They are NOT bogus.
Yes. But it isn't just dup but other open()s as well.
There is a lot of legacy code that relies on taking over STD slots.
Patches that don't break 'make test' on any of |
The RT System itself - Status changed from 'new' to 'open' |
From perl5-porters@ton.iguana.beFor what it's worth, I've ran into this warning several times and it But skipping the STD handles could be even worse. In e.g. the qmail |
From stas@stason.orgNick Ing-Simmons via RT wrote:
I understand, Nick But take the last test case: % perl -wle 'close STDIN; open my and move that 'close STDIN' out. Which leaves us with a perfectly valid code, open my Now if some other code (which I have no control of) closes STDIN, my perfectly So may be the warnings are not bogus, but the dup function is. __________________________________________________________________ |
From nick.ing-simmons@elixent.comStas Bekman <stas@stason.org> writes:
There are lots of other things code you have no control over can do
Find the person that wrote the code that closed STDIN without reopening Perhaps run foreach my $fh ((\*STDIN,\*STDOUT,\*STDERR)) After dubious code is allowed to run? The snag is we can't warn on close(STD*) as that is normal. Perhaps we could warn on leaving scope with STD* closed? {
In your example it is the open() not the dup that is warning. perl -wle 'close STDIN; open my |
From @rgsNick Ing-Simmons wrote:
I wholehearledly agree (from personal experience as a C coder...) |
From stas@stason.orgNick Ing-Simmons via RT wrote:
That person could be me ;) I remember reading a lot about always closing STD* And it must be File::Spec->devnull() ;) So should I fix the fork examples to reopen the streams to /dev/null? I've grepped the perl pod dir and haven't found any problematic cases. The use warnings; But consider this: use warnings; prints: 1 As you can see $fh got fd 1, which is STDOUT. Though $fh is open for RDONLY. The following is unclear: use warnings; it prints: foo why 4 and not 0? after all I have closed STDIN and then re-opened it using an
I guess that's doable if you are unfortunate to find yourself in this kind of
Could you look at GP and if its name is not STD, do another open and then
That sounds like a good idea to me. What about entering a new scope with STDs
Yes, yes, you are right. As usual, Thanks a lot, Nick! __________________________________________________________________ |
Migrated from rt.perl.org#26670 (status was 'open')
Searchable as RT26670$
The text was updated successfully, but these errors were encountered: