Fw: Passing CGI environment to subprograms

2003-01-16 Thread Erich Oliphant

- Original Message -
From: Erich Oliphant [EMAIL PROTECTED]
To: Stas Bekman [EMAIL PROTECTED]
Sent: Wednesday, January 15, 2003 9:21 PM
Subject: Re: Passing CGI environment to subprograms


 Duh :)  Sorry, I thought I included the rev in my original post, yes I am
 using 2.0.  Hmm, and no hacks or workarounds at this point?  That sucks ;)
 Well I will poke around the code and see if I can help out.

 Also, are the probs I described with getting the output of
spawn_proc_prog()
 known?  As I indicated that approach did set the env vars correctly, but I
 was not able to read the output handle per the example.

 Thanks!!!


 - Original Message -
 From: Stas Bekman [EMAIL PROTECTED]
 Cc: Erich Oliphant [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Wednesday, January 15, 2003 7:59 PM
 Subject: Re: Passing CGI environment to subprograms


  Stas Bekman wrote:
   Erich Oliphant wrote:
  
   Thanks for the reply, just getting back from a short vacation...
  
   My test programs:
  
   first.pl
   ---
   #!/export/home/eoliphan/gnu/bin/perl -w
   use strict;
   my $key;
   open(LOG, /tmp/firstdebug.log);
   foreach $key (keys %ENV)
   {
   print LOG $key = $ENV{$key} \n;
   }
  
   `/export/home/eoliphan/gnu/cgi-bin/dump_vars.pl`;
   close (LOG);
   ---
  
   dump_vars.pl has the same foreach loop and dumps to a different log
 file.
   The 'firstdebug.log' has the required CGI vars.  The log generated by
   dump_vars.pl has what appears to be the enviroment of the httpd
   executable
   and no CGI vars.
  
  
   It works for me with mod_perl 1.0 and doesn't with 2.0.
 
  BTW, the 2.0 issue is known. And should be resolved at some point.
 
  Here is a quote from modperl_env.c
 
  /*
* XXX: what we do here might change:
*  - make it optional for %ENV to be tied to r-subprocess_env
*  - make it possible to modify environ
*  - we could allow modification of environ if mpm isn't threaded
*  - we could allow modification of environ if variable isn't a
CGI
*variable (still could cause problems)
*/
  /*
* problems we are trying to solve:
*  - environ is shared between threads
*  + Perl does not serialize access to environ
*  + even if it did, CGI variables cannot be shared between
 threads!
* problems we create by trying to solve above problems:
*  - a forked process will not inherit the current %ENV
*  - C libraries might rely on environ, e.g. DBD::Oracle
*/
 
  Meanwhile I'll add a note to the compat.pod, to avoid bug reports.
 
  __
  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
 
 






Re: Fw: Passing CGI environment to subprograms

2003-01-16 Thread Stas Bekman
Erich Oliphant wrote:

- Original Message -
From: Erich Oliphant [EMAIL PROTECTED]
To: Stas Bekman [EMAIL PROTECTED]
Sent: Wednesday, January 15, 2003 9:21 PM
Subject: Re: Passing CGI environment to subprograms




Duh :)  Sorry, I thought I included the rev in my original post, yes I am
using 2.0.  Hmm, and no hacks or workarounds at this point?  That sucks ;)
Well I will poke around the code and see if I can help out.


I think the suggestion was to enable this feature for non-threaded mpms. 
But what we are trying to achieve is that any module will run identically 
on threaded and non-threaded mpms (the same reason why Registry modules 
don't chdir to the script's dir).

Also, are the probs I described with getting the output of


spawn_proc_prog()


known?  As I indicated that approach did set the env vars correctly, but I
was not able to read the output handle per the example.


It's quite possible that there is a bug. Can you please send a test case 
to reproduce the problem? Thanks.

__
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



Re: Passing CGI environment to subprograms

2003-01-15 Thread Erich Oliphant
Thanks for the reply, just getting back from a short vacation...

My test programs:

first.pl
---
#!/export/home/eoliphan/gnu/bin/perl -w
use strict;
my $key;
open(LOG, /tmp/firstdebug.log);
foreach $key (keys %ENV)
{
print LOG $key = $ENV{$key} \n;
}

`/export/home/eoliphan/gnu/cgi-bin/dump_vars.pl`;
close (LOG);
---

dump_vars.pl has the same foreach loop and dumps to a different log file.
The 'firstdebug.log' has the required CGI vars.  The log generated by
dump_vars.pl has what appears to be the enviroment of the httpd executable
and no CGI vars.

Erich

- Original Message -
From: Stas Bekman [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, January 09, 2003 10:01 PM
Subject: Re: Passing CGI environment to subprograms


 I don't see any reason why your `` invoked process doesn't see the CGI
 env vars. For example:

 #!/usr/bin/perl
 print Content-type: text/plain\n\n;
 $ENV{'PATH'} = '/bin:/usr/bin';
 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
 print qx{printenv |grep REMOTE_ADDR};

 prints:
 REMOTE_ADDR=127.0.0.1

 So as you can see, it works. The problem is probably in your external
 program, since the env vars are all there.

 Or may be you are using PerlSetEnv Off?
 http://perl.apache.org/docs/1.0/guide/config.html#PerlSetupEnv

  I've now located and tried the subprocess_env() in conjunction w/
  spawn_proc_prog().  I just do a foreach on the ENV hash and stuff
  the values
  into subprocess_env().  That works (I have a test perl subprogram
  that just
  dumps the ENV), but now I am not able to get the output of the program.
  I
  pasted in the read_data() func from the example and I have a single
  scalar
  accepting the return value from spawn_proc_prog() per the example
  and that
  is supposed to give me the output filehandle.

 Can you post a simple test program that reproduces the problem?

 Also it'd be really useful if somebody could add a test suite for
 Apache::Subprocess for (mod_perl 1.0). You can look at the
 t/apr/subprocess test in mod_perl 2.0 to a basic example. It's a good
 way to learn how to use Apache::Test, which is covered here:
 http://perl.apache.org/docs/general/testing/testing.html

 __
 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







Re: Passing CGI environment to subprograms

2003-01-09 Thread Stas Bekman
I don't see any reason why your `` invoked process doesn't see the CGI 
env vars. For example:

#!/usr/bin/perl
print Content-type: text/plain\n\n;
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
print qx{printenv |grep REMOTE_ADDR};

prints:
REMOTE_ADDR=127.0.0.1

So as you can see, it works. The problem is probably in your external 
program, since the env vars are all there.

Or may be you are using PerlSetEnv Off?
http://perl.apache.org/docs/1.0/guide/config.html#PerlSetupEnv

I've now located and tried the subprocess_env() in conjunction w/
spawn_proc_prog().  I just do a foreach on the ENV hash and stuff 
the values
into subprocess_env().  That works (I have a test perl subprogram 
that just
dumps the ENV), but now I am not able to get the output of the program.
I
pasted in the read_data() func from the example and I have a single 
scalar
accepting the return value from spawn_proc_prog() per the example 
and that
is supposed to give me the output filehandle.

Can you post a simple test program that reproduces the problem?

Also it'd be really useful if somebody could add a test suite for 
Apache::Subprocess for (mod_perl 1.0). You can look at the 
t/apr/subprocess test in mod_perl 2.0 to a basic example. It's a good 
way to learn how to use Apache::Test, which is covered here:
http://perl.apache.org/docs/general/testing/testing.html

__
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



Passing CGI environment to subprograms

2003-01-08 Thread Erich Oliphant
Hi,
I have a mod_perl script that exec's (via backticks) another program.
This program actually needs the CGI enviroment variables to perform 
correctly (it's a proprietary program, it was actually called by 
shell CGI initially, this approach cuts our exec's in half until 
we get an alternative for the subprogram).  

Based on some stuff in the list archive, I thought that Apache::SubProcess 
would handle this but it appears to just be a cleaner way to get 
the output of the called program as opposed to setting it's environment.


Any help 









Re: Passing CGI environment to subprograms

2003-01-08 Thread Erich Oliphant
I've now located and tried the subprocess_env() in conjunction w/
spawn_proc_prog().  I just do a foreach on the ENV hash and stuff 
the values
into subprocess_env().  That works (I have a test perl subprogram 
that just
dumps the ENV), but now I am not able to get the output of the program.
I
pasted in the read_data() func from the example and I have a single 
scalar
accepting the return value from spawn_proc_prog() per the example 
and that
is supposed to give me the output filehandle.

Any suggestions?


- Original Message -
From: Erich Oliphant [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, January 08, 2003 4:46 PM
Subject: Passing CGI environment to subprograms


 Hi,
 I have a mod_perl script that exec's (via backticks) another program.
 This program actually needs the CGI enviroment variables to perform
 correctly (it's a proprietary program, it was actually called by
 shell CGI initially, this approach cuts our exec's in half until
 we get an alternative for the subprogram).

 Based on some stuff in the list archive, I thought that Apache:
:SubProcess
 would handle this but it appears to just be a cleaner way to get
 the output of the called program as opposed to setting it's environment.



 Any help