Re: IPC::Open3 and MP

Torsten Förtsch <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.