Re: IPC::Open2 under mod_perl in Mac OS X

2002-06-30 Thread John Siracusa

On 6/30/02 2:06 AM, Stas Bekman wrote:
 John Siracusa wrote:
 (I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
 it to both lists.  Redirect follow-ups as appropriate.)
 
 open2() doesn't seem to work for me when running under mod_perl in Mac OS X.
 
 It's not a bug in MacOSX, it simply doesn't work with mod_perl.

I can't post a direct example now (because I don't have access to the
machine from here), but I'm pretty sure I do have an example of open2()
working under mod_perl in Linux--in a perl that is not compiled with sfio.
That's why I thought it was a Mac OS X bug.

The mod_perl guide talks about the output from system(), exec(), and open(F,
| ...) not being sent to the browser, but it doesn't mention open2().  In
the case of open2(), the input and output is supposed to be tied to
filehandles that I supply, not connected to mod_perl's (tied?) STDOUT that
eventually goes to the browser.

So could you clarify why open2() is not expected to work under mod_perl, and
why it seems to work for me in Linux?  (I'll post the working Linux example
once I can confirm it on Monday.)

-John




Re: IPC::Open2 under mod_perl in Mac OS X

2002-06-30 Thread Stas Bekman

John Siracusa wrote:
 On 6/30/02 2:06 AM, Stas Bekman wrote:
 
John Siracusa wrote:

(I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
it to both lists.  Redirect follow-ups as appropriate.)

open2() doesn't seem to work for me when running under mod_perl in Mac OS X.

It's not a bug in MacOSX, it simply doesn't work with mod_perl.
 
 
 I can't post a direct example now (because I don't have access to the
 machine from here), but I'm pretty sure I do have an example of open2()
 working under mod_perl in Linux--in a perl that is not compiled with sfio.
 That's why I thought it was a Mac OS X bug.
 
 The mod_perl guide talks about the output from system(), exec(), and open(F,
 | ...) not being sent to the browser, but it doesn't mention open2().  In
 the case of open2(), the input and output is supposed to be tied to
 filehandles that I supply, not connected to mod_perl's (tied?) STDOUT that
 eventually goes to the browser.
 
 So could you clarify why open2() is not expected to work under mod_perl, and
 why it seems to work for me in Linux?  (I'll post the working Linux example
 once I can confirm it on Monday.)

I should have said that your example doesn't work on linux with mod_perl 
with sfio-enabled perl, since I've tried it and it didn't work. That's 
why I've assumed that it's not MacOSX problem.

I really didn't have a chance to investigate why it doesn't work. I've 
just tried other alternatives which worked so I've posted them, since I 
thought that it was important to you to have a working solution. Feel 
free to debug the whole thing and post the details of what exactly 
doesn't work and if possible how to fix that.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




IPC::Open2 under mod_perl in Mac OS X

2002-06-29 Thread John Siracusa

(I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
it to both lists.  Redirect follow-ups as appropriate.)

open2() doesn't seem to work for me when running under mod_perl in Mac OS X.
Here's the test case:

In /usr/local/bin/upcase

#!/usr/bin/perl
$buf .= $_ while(STDIN);
print uc $buf;

Example usage from the command line:

% echo hello | upcase
HELLO

Now here's the CGI script that uses open2() to talk to the upcase program:

#!/usr/bin/perl
use strict;
use CGI qw(:standard);
use IPC::Open2;

open2(\*READ, \*WRITE, '/usr/local/bin/upcase');

print WRITE Hello;
close(WRITE);

my $res;
$res .= $_  while(READ);
close(READ);

print header(), Got: $res

Running it under plain CGI shows the expected output:

Got: HELLO

But running it under Apache::PerlRun or Apache::Registry shows:

Got:

Any ideas?  (Some more verbose configuration information is included below.)

-John

% perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
osname=darwin, osvers=1.4, archname=darwin
uname='darwin localhost 1.4 darwin kernel version 1.4: sun sep 9
15:39:59 pdt 2001; root:xnuxnu-201.obj~1release_ppc power macintosh powerpc
'
config_args='-des -Dfirstmakefile=GNUmakefile -Dldflags=-flat_namespace'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
cc='cc', ccflags ='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE
-fno-strict-aliasing -I/usr/local/include',
optimize='-O3',
cppflags='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE -fno-strict-aliasing
-I/usr/local/include'
ccversion='', gccversion='Apple devkit-based CPP 6.0', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
ld='cc', ldflags ='-flat_namespace -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-lm -lc
perllibs=-lm -lc
libc=/System/Library/Frameworks/System.framework/System, so=dylib,
useshrplib=true, libperl=libperl.dylib
  Dynamic Linking:
dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-flat_namespace -bundle -undefined suppress
-L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: USE_LARGE_FILES
  Built under darwin
  Compiled at 01/26/02 17:02:40
  %ENV:
PERL_READLINE_NOWARN=
  INC:
/System/Library/Perl/darwin
/System/Library/Perl
/Library/Perl/darwin
/Library/Perl
/Library/Perl
/Network/Library/Perl/darwin
/Network/Library/Perl
/Network/Library/Perl
.

% uname -a
Darwin xxx.com 5.5 Darwin Kernel Version 5.5: Thu May 30 14:51:26 PDT 2002;
root:xnu/xnu-201.42.3.obj~1/RELEASE_PPC  Power Macintosh powerpc


Apache/1.3.23 (Darwin) mod_perl/1.26
(I've also tried this with apache 1.3.26 and got the same results)

% httpd -V
Server version: Apache/1.3.23 (Darwin)
Server built:   02/16/02 15:51:05
Server's Module Magic Number: 19990320:11
Server compiled with
 -D HAVE_MMAP
 -D USE_MMAP_SCOREBOARD
 -D USE_MMAP_FILES
 -D HAVE_FCNTL_SERIALIZED_ACCEPT
 -D HAVE_FLOCK_SERIALIZED_ACCEPT
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D HTTPD_ROOT=/usr/local/apache
 -D SUEXEC_BIN=/usr/local/apache/bin/suexec
 -D DEFAULT_PIDLOG=logs/httpd.pid
 -D DEFAULT_SCOREBOARD=logs/httpd.scoreboard
 -D DEFAULT_LOCKFILE=logs/httpd.lock
 -D DEFAULT_XFERLOG=logs/access_log
 -D DEFAULT_ERRORLOG=logs/error_log
 -D TYPES_CONFIG_FILE=conf/mime.types
 -D SERVER_CONFIG_FILE=conf/httpd.conf
 -D ACCESS_CONFIG_FILE=conf/access.conf
 -D RESOURCE_CONFIG_FILE=conf/srm.conf

% httpd -l
Compiled-in modules:
  http_core.c
  mod_env.c
  mod_log_config.c
  mod_mime.c
  mod_negotiation.c
  mod_status.c
  mod_include.c
  mod_autoindex.c
  mod_dir.c
  mod_cgi.c
  mod_asis.c
  mod_imap.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_access.c
  mod_auth.c
  mod_setenvif.c
  mod_perl.c
suexec: disabled; invalid wrapper /usr/local/apache/bin/suexec




Re: IPC::Open2 under mod_perl in Mac OS X

2002-06-29 Thread Stas Bekman

John Siracusa wrote:
 (I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
 it to both lists.  Redirect follow-ups as appropriate.)
 
 open2() doesn't seem to work for me when running under mod_perl in Mac OS X.

It's not a bug in MacOSX, it simply doesn't work with mod_perl. the 
piped program ('upcase' in your example) never sees any input. There are 
at least two working alternatives:

1) use IPC::Run:

#!/usr/bin/perl
use strict;
use CGI qw(:standard);
use IPC::Run qw(start finish) ;

local $ENV{PATH};
print header();

my @cmd = qw(/tmp/upcase) ;
my $h = start \@cmd,
 'pipe', \*IN,
 'pipe', \*OUT,
 '2pipe', \*ERR
 or die @cmd returned $? ;
print IN Perl::Run and Barrie rule!;
close IN;
print OUT, ERR;
finish $h ;

the upcase program without any change:

 #!/usr/bin/perl
 $buf .= $_ while(STDIN);
 print uc $buf;

2) use Apache::SubProcess:

use Apache::SubProcess ();
my $r = shift;
$r-send_http_header('text/plain');

use vars qw($input);
$input = Apache::SubProcess rules too!;
my($out, $in, $err) = $r-spawn_child(\upcase);
print $out $input;
$r-send_fd($in);

sub upcase {
 my $r = shift;
 $r-subprocess_env(CONTENT_LENGTH = length $input);
 $r-filename(/tmp/upcase);
 $r-call_exec;
}

notice that the upcase script will be different from yours in this case, 
it looks like:

#!/usr/bin/perl
read STDIN, $buf, $ENV{CONTENT_LENGTH};
print uc $buf;

As this module lacks any docs, you can find them here:
http://perl.apache.org/release/docs/1.0/guide/modules.html#Apache__SubProcess

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com