We have been struggling for a week on an issue involving open3 in several modules that are run out of mod_perl. A rough version of the code is shown below, but it is important to note that it WORKS, at least for some people.

Each developer runs their own sandbox under RedHat Linux, comprising the code and apache. For some folks, these modules work fine. For others, the sysread always returns 0 bytes, with no warnings or errors. The difference is in who starts apache/mod_perl.

We became desperate enough wrap the called utility in strace, and the one clue we've found is a difference in fstat64 calls. The users whose modules work see:

fstat64(1, . . . st_mode=S_IFIFO . . .) = 0;
For users whose calls fail:
fstat64(1, . . . st_mode=S_IFSOCK . . .) = 0;

We've compared profiles, environment variables, and version numbers and see no differences.

In addition, users whose modules don't work from inside mod_perl can run standalone scripts like this with no problems.

Has anyone encountered anything like this? Thanks in advance.

use IPC::Open3; use Symbol qw /gensym /; use IO::File; use IO::Select; my $pid; my ($in,$out,$err) = map gensym, 1..3; eval { $pid = open3($in,$out,$err,"/usr/bin/<utility>",("/home/me/infile")) +; }; die "Bad error" if ($@); my $sel = IO::Select->new(); $sel->add($out); $sel->add($err); while (my @ready = $sel->can_read(5)) { for my $handle (@ready) { my $buf; if ($handle == $out) { my $bytes = sysread($handle,$buf,1024); if ($bytes == 0) { $sel->remove($handle); next; } $results .= $buf; } } } if (length($results) > 0) { waitpid($pid); } else { kill(9,$pid); }

In reply to Yet another Open3 issue . . . or is it? by johnevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.