Stumped: returning a read pipe from a function

B

Ben Morrow

Quoth (e-mail address removed):
As long as only one part of the code is being clever, you are OK.
But when many parts of the code are being clever, they start tripping
over each other. IO::Unread hiddenly ties and unties file handles (at
least in some situations),

It only uses a tie implementation under 5.6. Not that I'd necessarily
recommend its use: it was more-or-less written as a proof of concept...
:)

Ben (author of IO::Unread).
 
C

comp.llang.perl.moderated

I think you previously said that /some/command can legitimately
produce no output under some non-error conditions. If so, that means you
have to do something more than just check eof $rdr before dying, you also
need to check $err or $?. Assuming $? doesn't tell you anything you need
to know and $err tells it all, then something like:

if (eof $rdr) {
return $rdr if eof $err; # no error message, means no error
waitpid $pid,0; # avoid zombies if die isn't really fatal
die <$err>;
};
return $rdr;





Since you die on errors, rather than logging and going on (well,
you could be invoking this from an eval {} and doing logging from
outside, so maybe the die doesn't really mean die...) I was kind of
hoping this was a single-use program and you could just forget about
zombies.

Maybe you could double-fork so the OS cleans up zombies automatically,
although it isn't obvious to me how to do that cleanly and simply with
Open3. Or you could set $SIG{CHLD} to "IGNORE", but that might screw up
other parts of your code if those parts also use fork, system, etc. and are
expecting $SIG{CHLD} to stay at its default.
....

An asynchronous wait would be another possibility
although, if there're other forks in the program,
unexpected reaping may occur:

use POSIX ':sys_wait_h';
....

END { 1 while waitpid(-1, WNOHANG) != -1; }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,808
Messages
2,569,686
Members
45,453
Latest member
RamonMcCom

Latest Threads

Top