Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Leaking a file descriptor into a child to use with /proc/self/fd/3

by Fletch (Bishop)
on Feb 25, 2020 at 14:26 UTC ( [id://11113406]=note: print w/replies, xml ) Need Help??


in reply to Leaking a file descriptor into a child to use with /proc/self/fd/3

Might also want to look at $^F (see perlvar) and/or explicitly clearing CLOEXEC on the descriptor with fcntl.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Leaking a file descriptor into a child to use with /proc/self/fd/3
by ewheeler (Novice) on Feb 26, 2020 at 23:46 UTC

    Perfect, that fixed the problem. I did not realize Perl closed FDs on exec (or maybe that is an OS thing).

      The Perl process essentially goes away by replacing itself when you exec. So, it might feel surprising but it seems sensible/intuitive that any FDs opened in Perl would close.

      This worked:

      open(my $in, '/etc/passwd'); my $flags = fcntl($in, F_GETFD, 0); fcntl($in, F_SETFD, $flags & (~FD_CLOEXEC)) or die "Can't set flags: $ +!\n"; if (!fork()) { exec("grep", "root", "/proc/self/fd/" . fileno($in)); } close($in);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11113406]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found