IPC::Open3 and MP

IPC::Open3 and MP

am 19.01.2010 23:11:37 von rjray

--0016e68dd7abe71867047d8bc0ea
Content-Type: text/plain; charset=UTF-8

I have some code that uses IPC::Open3, and I've discovered (the hard way)
that it doesn't work under MP2 and Apache 2.2.6. What is the "best
practices" way of doing this under MP2?

eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 30; # 30 seconds is more than enough for bogofilter to run
$child = open3($ichld, $ochld, undef, @cmd);
print $ichld $param->{'message'}, "\n";
close($ichld);
@response = <$ochld>;
waitpid $child, 0;
alarm 0;
};

I would prefer a solution that doesn't require adding a new CPAN module to
our dependencies list, but if that's the only way, then I'll do it. This has
to run in both MP2 and non-MP environments, so Apache::SubProcess probably
isn't going to help me...

Thanks in advance for any suggestions!

Randy
--
Randy J. Ray / randy.j.ray@gmail.com
Silicon Valley Scale Modelers: http://www.svsm.org
Sunnyvale, CA

--0016e68dd7abe71867047d8bc0ea
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I have some code that uses IPC::Open3, and I've discovered (the hard wa=
y) that it doesn't work under MP2 and Apache 2.2.6. What is the "b=
est practices" way of doing this under MP2?

    =
eval {
        local $SIG{ALRM} =3D sub { =
die "alarm\n" };

        alarm 30; # 30 seconds is more than e=
nough for bogofilter to run
        $child=
=3D open3($ichld, $ochld, undef, @cmd);
      =
  print $ichld $param->{'message'}, "\n";
=C2=
 Â Â=A0     close($ichld);

        @response =3D <$ochld>;
=C2=
 Â Â=A0     waitpid $child, 0;
   =
    alarm 0;
    };

I would prefer=
a solution that doesn't require adding a new CPAN module to our depend=
encies list, but if that's the only way, then I'll do it. This has =
to run in both MP2 and non-MP environments, so Apache::SubProcess probably =
isn't going to help me...


Thanks in advance for any suggestions!

Randy
--
Randy J. =
Ray / >Silicon Valley Scale Modelers: http://www.=
svsm.org


Sunnyvale, CA


--0016e68dd7abe71867047d8bc0ea--

Re: IPC::Open3 and MP

am 20.01.2010 12:17:25 von Clinton Gormley

On Tue, 2010-01-19 at 14:11 -0800, Randy J. Ray wrote:
> I have some code that uses IPC::Open3, and I've discovered (the hard
> way) that it doesn't work under MP2 and Apache 2.2.6. What is the
> "best practices" way of doing this under MP2?

I use IPC::Run, which works in mod_perl and non-mod_perl environments.

clint

>
> eval {
> local $SIG{ALRM} = sub { die "alarm\n" };
> alarm 30; # 30 seconds is more than enough for bogofilter to
> run
> $child = open3($ichld, $ochld, undef, @cmd);
> print $ichld $param->{'message'}, "\n";
> close($ichld);
> @response = <$ochld>;
> waitpid $child, 0;
> alarm 0;
> };
>
> I would prefer a solution that doesn't require adding a new CPAN
> module to our dependencies list, but if that's the only way, then I'll
> do it. This has to run in both MP2 and non-MP environments, so
> Apache::SubProcess probably isn't going to help me...
>
> Thanks in advance for any suggestions!
>
> Randy
> --
> Randy J. Ray / randy.j.ray@gmail.com
> Silicon Valley Scale Modelers: http://www.svsm.org
> Sunnyvale, CA

Re: IPC::Open3 and MP

am 20.01.2010 13:54:17 von torsten.foertsch

On Tuesday 19 January 2010 23:11:37 Randy J. Ray wrote:
> I have some code that uses IPC::Open3, and I've discovered (the hard way)
> that it doesn't work under MP2 and Apache 2.2.6. What is the "best
> practices" way of doing this under MP2?
>
I don't see the problem. This code works here (curl output see below):

use IPC::Open3;
my ($ip, $op);
my $pid=open3 $ip, $op, undef, qw/bash -c/, 'ls -l; echo ====; cat -n; echo
>&2 =====; exit 249';
print $ip "hugo\n"x15; close $ip;
local $/;
my $doc=readline $op;
waitpid $pid, 0;

$doc.="\nRC=$?\n";

The only IPC::Open3 related problem that I see is that it calls exit() if
exec() fails and POSIX::exit is not available. I think that happens quite
seldom.

It even works after adding the timeout stuff. (needs prefork MPM)

I see however several problems with your code:

- what happens if $param->{message} is too large for the pipe buffer? The
print statement will block and you get a deadlock if the child wants to write
something to the parent.

- open3 can die(). In this case the alarm is not reset and the apache will get
a SIGALRM when it is not expecting it.

Torsten

------------------------------------------------------------ -------
< HTTP/1.1 200 OK
< Date: Wed, 20 Jan 2010 11:07:00 GMT
< Server: Apache/2.2.14 (Unix) proxy_html/3.0.1 mod_ssl/2.2.14 OpenSSL/0.9.8k
DAV/2 mod_apreq2-20090110/2.7.1 mod_perl/2.0.5threading3 Perl/v5.10.0
< Content-Length: 1242
< Content-Type: text/plain
<
total 107
drwxr-xr-x 2 root root 4096 Dec 11 18:12 PELMEN
drwxr-xr-x 2 root root 4096 Dec 17 17:50 bin
drwxr-xr-x 4 root root 3072 Jan 5 11:18 boot
drwxr-xr-x 17 root root 3740 Jan 20 10:13 dev
drwxr-xr-x 114 root root 12288 Jan 20 10:14 etc
drwxr-xr-x 10 root root 4096 Dec 12 23:06 home
drwxr-xr-x 13 root root 4096 Jan 15 10:24 lib
drwxr-xr-x 8 root root 12288 Jan 15 10:24 lib64
drwx------ 2 root root 16384 Dec 6 21:01 lost+found
drwxr-xr-x 2 root root 4096 Jan 6 10:18 media
drwxr-xr-x 2 root root 4096 Oct 24 05:08 mnt
drwxr-xr-x 8 root root 4096 Dec 10 18:07 opt
dr-xr-xr-x 217 root root 0 Jan 20 10:13 proc
drwx------ 36 root root 4096 Jan 15 14:27 root
drwxr-xr-x 3 root root 12288 Jan 8 18:47 sbin
drwxr-xr-x 2 root root 4096 Oct 24 05:08 selinux
drwxr-xr-x 4 root root 4096 Nov 3 00:43 srv
drwxr-xr-x 12 root root 0 Jan 20 10:13 sys
drwxrwxrwt 53 root root 4096 Jan 20 12:00 tmp
drwxr-xr-x 13 root root 4096 Nov 3 01:51 usr
drwxr-xr-x 16 root root 4096 Dec 6 21:09 var
====
1 hugo
2 hugo
3 hugo
4 hugo
5 hugo
6 hugo
7 hugo
8 hugo
9 hugo
10 hugo
11 hugo
12 hugo
13 hugo
14 hugo
15 hugo
=====

RC=63744