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
POSIX::close() bug? #16966
Comments
From felipe@cpanel.netHello, Todd Rinaldo and I were talking today about this: perl -MPOSIX= -e' close $out; # XXX: a no-op, because Perl still has $r4 open? sysread( $in, my $buf, 512 ); # hangs We’re wondering if the above constitutes something that would reasonably be considered a bug in Perl, and/or something that could be accommodated anyway. I’m guessing that the fact that close() is a no-op (i.e., it doesn’t close any FDs) is because PerlIO never knew about the POSIX::close() call against FD 4 and so it tracks both $r4 and $out as referring to FD 4; thus, it won’t do anything when $out is close()d because it still has another filehandle that refers to that FD. When pipe() gives FD 4, shouldn’t PerlIO set that reference counter to 1? Or should it maybe warn() that there’s a file descriptor conflict? Thank you! -Felipe Gasper |
From @tonycozOn Wed, 17 Apr 2019 10:14:47 -0700, felipe@cpanel.net wrote:
As discussed on IRC, you're pretty much getting expected behaviour - it's consequence of bypassing Perl's I/O abstraction for a Perl file handle. I don't see a simple solution to forcing the reference count for new fds (as opposed to fdopen()) to 1 for pipe(). From further discussion in IRC it looks like what you were after was a way to close all open file handles so a child that drops privileges after a fork doesn't retain access to any files that may have required elevated privileges to access. We could modify perl to track all new SV file handles, but XS code could still create them bypassing such tracking (unless it was in sv_upgrade(), I guess, but that would retain closed handles until the SV was destroyed. And it could really only track the handles in the current thread (the SV handles from other threads aren't usable in the current thread.) I don't see a simple solution. Tony |
The RT System itself - Status changed from 'new' to 'open' |
|
Yeah, Frankly, you just shouldn't use
That's slightly tricky because there are valid reasons for that counter not to be 1 (in particular, |
It was just for pure-Perl demonstration purposes. The “real-life” circumstance was I think:
|
Some daemonization code does that, I would highly recommend against doing that in Perl. |
Migrated from rt.perl.org#134042 (status was 'open')
Searchable as RT134042$
The text was updated successfully, but these errors were encountered: