I know this has been discussed a little before, but the Test.pm
PerlHandler I've attached does not work as expected.  The reason being
that dup-ing a read filehandle to STDIN overwrote STDOUT instead (well,
actually both, since apache apparently uses the same handle for 
input and output).  Anyway, this actually worked in RH 6.x, but stopped
working when I installed 7.1.  My guess is that for whatever versions are
in 6.x STDIN and STDOUT were only tied for registry scripts, but in 7.x
they got tied for regular content handlers as well.

Currently, I'm working around it by putting

untie(*STDIN);
untie(*STDOUT);

at the beginning of my handler.  Is that the best way to go?  I tried
sticking it in the initialization part of the module, but that didn't
work.  Why is that?

Anyway, if anyone has additional questions about what I'm doing here, let
me know.  The example is quite contrived, but it does affect a real-world
situation.

The actual problem line is open(STDIN, "<&RD"), which dups RD onto
filehandle 1 (STDOUT) instead of 0 (STDIN).  Later, when '/bin/ls' is
exec-d, when it tries to write to STDOUT, it gets EBADF because there's a
read file handle there.

Anyway, the script can be installed with

PerlRequire Test.pm
<location /mytest/>
SetHandler perl-script
PerlHandler WRI::Test::handler
</location>

Anyway, let me know if there is a better way of handling the situation.

Jon

-- 
PGP information is available at http://members.wri.com/johnnyb/about/
package WRI::Test;

sub handler
{
        my $r = shift;
        my $testfh;
        my $line;

        $r->send_http_header('text/html');

        $r->print(<<EOF);
<html>
<head>
<title>
My Test Page
</title
</head>
<body>
<pre>
EOF

        $testfh = runtest();

        while($line = <$testfh>)
        {
                $r->print($line);
        }

        $r->print(<<EOF);
</pre>
</body>
</html>
EOF

        return OK;
}

sub runtest
{
        pipe(RD, WR);

        unless(open(MYHANDLE, "-|"))
        {
                close(WR);
                open(STDIN, "<&RD");

                exec('/bin/ls');
        }

        close(RD);

        close(WR);

        return \*MYHANDLE;
}

1;

Reply via email to