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: Passing CGI environment to subprograms
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. Which one do you have the trouble with? if with 1.0, check: Or may be you are using PerlSetEnv Off? http://perl.apache.org/docs/1.0/guide/config.html#PerlSetupEnv __ 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
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
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
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