Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Environment variable problem in mod_perl 2

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


sgifford at suspectclass

Jun 2, 2009, 11:58 PM

Post #1 of 3 (442 views)
Permalink
Environment variable problem in mod_perl 2

[ also posted on PerlMonks ]

I'm working on porting some code that's been running on mod_perl 1 for
a very long time to mod_perl 2. Mostly things have gone smoothly, but
I'm having trouble with environment variables. Sometimes my scripts go
off and run other scripts, and expect to be able to set things like
$ENV{PATH} for the child processes. However, for some reason under
mod_perl 2, my environment variables aren't getting passed to child
processes! Quite bizarre.

Here's an example:

#!/usr/bin/perl -T

use strict;
use warnings;

print "Content-type: text/plain\n\n";

$ENV{PATH}="/usr/bin";

print "PARENT: PATH is $ENV{PATH}\n";
print " CHILD: PATH is ",`echo \$PATH`,"\n";

The proper output seems pretty obvious, right? And that's what it does
when I run it from the command-line. But under mod_perl 2, instead I
see:

PARENT: PATH is /usr/bin
CHILD: PATH is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin

I'm using Ubuntu 8.04 and its default Perl (5.8.8), Apache (2.2.8),
and mod_perl (2.0.3). My Apache configuration looks roughly like this:

<Location /cgi-perl>
Options +ExecCGI
PerlSendHeader On
SetHandler perl-script
PerlHandler ModPerl::Registry
PerlOptions +SetupEnv
allow from all
</Location>

Any suggestions would be appreciated!

----Scott.


sgifford at suspectclass

Jun 3, 2009, 11:50 AM

Post #2 of 3 (405 views)
Permalink
Re: Environment variable problem in mod_perl 2 [In reply to]

Paul Silevitch <paul[at]silevitch.com> writes:

> Scott,
>
> I had a similar problem and I used Env::C to get around it. Definitely read
> the perldoc to see the gotchas with this module.
>
> Let me know if it works for you,

Yeah, Env::C was the solution, thanks!

It would be very nice to make this clearer in the docs, especially the
migration guide on the Web site. Mentioning clearly that %ENV is no
longer tied the to the real environment, that this affects child
processes (not just C code), and that Env::C offers a solution would
have saved me several hours. I would be happy to provide some
suggested text for:

http://perl.apache.org/docs/2.0/user/porting/compat.html#Issues_with_Environment_Variables

if it would be helpful.

----Scott.


> On Wed, Jun 3, 2009 at 2:58 AM, Scott Gifford <sgifford[at]suspectclass.com>
> wrote:
>
> [ also posted on PerlMonks ]
>
> I'm working on porting some code that's been running on mod_perl 1 for
> a very long time to mod_perl 2. Mostly things have gone smoothly, but
> I'm having trouble with environment variables. Sometimes my scripts go
> off and run other scripts, and expect to be able to set things like
> $ENV{PATH} for the child processes. However, for some reason under
> mod_perl 2, my environment variables aren't getting passed to child
> processes! Quite bizarre.

[...]


gozer at ectoplasm

Jun 3, 2009, 12:41 PM

Post #3 of 3 (404 views)
Permalink
Re: Environment variable problem in mod_perl 2 [In reply to]

On 03/06/09 02:58 , Scott Gifford wrote:
> [ also posted on PerlMonks ]
>
> I'm working on porting some code that's been running on mod_perl 1 for
> a very long time to mod_perl 2. Mostly things have gone smoothly, but
> I'm having trouble with environment variables. Sometimes my scripts go
> off and run other scripts, and expect to be able to set things like
> $ENV{PATH} for the child processes. However, for some reason under
> mod_perl 2, my environment variables aren't getting passed to child
> processes! Quite bizarre.

Have you tried using $r->subprocess_env ?

http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_subprocess_env_

--
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
Attachments: signature.asc (0.18 KB)

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.