Looks like mod_perl scripts execute the line that changes $ENV{PATH},
but when a qx() back-tick command is executed, that command is executed
under the value of the original path.

The docs seem to suggest that that changes to %ENV should work fine:
  http://perl.apache.org/docs/2.0/user/coding/coding.html
>mod_perl passes (exports) the following shell environment variables
(if they are set) :
>   *      PATH - Executables search path.
>   *      TZ - Time Zone.
>Any of these environment variables can be accessed via %ENV

Maybe the docs need to be changed to say that while mod_perl passes these
values to the script, it does not pass them on to any qx() executions.
Would be best if mod_perl code can be fixed to allow this, though.

Related threads in mod_perl mailing list:
    How to change $ENV{PATH} for a specific script?
http://mail-archives.apache.org/mod_mbox/perl-modperl/200801.mbox/[EMAIL 
PROTECTED]

    mod_perl, ENV{'TZ'}, and localtime
    http://mail-archives.apache.org/mod_mbox/perl-modperl/200712.mbox/[EMAIL 
PROTECTED]

---
Here's a simple test on Fedora FC7 system (more version info at end):
#!/usr/bin/perl -Tw
print "Content-type: text/plain\n\n";

my $command = "basename";
foreach ( "/bin:", "/invalid/dir:" ) {
    $ENV{PATH} = $_;
    print "------ Testing command '$command', path $ENV{PATH}\n";
    my $string = `$command testing` || '';
    print "    failed to execute '$command', \$? is $?/" . ($? >> 8) . " : $!\n"
        if ($? != 0);
    print "    output \$string is: $string\n";
}

exit(0);
------------------------------------------------
When run from the command line, I get the correct output:
Content-type: text/plain

------ Testing command 'basename', path /bin:
    output $string is: testing

------ Testing command 'basename', path /invalid/dir:
[Wed Jan 16 17:13:39 2008] script.pl: Can't exec "basename": No such
file or directory at /home/cgi/script.pl line 12.
    failed to execute 'basename', $? is -1/16777215 : No such file or directory
    output $string is:
-------------------------------------------------------
But when I run this under Apache and mod_perl, I get this output -
/bin is still in the PATH even after removal:
------ Testing command 'basename', path /bin:
    output $string is: testing

------ Testing command 'basename', path /invalid/dir:
    output $string is: testing

-------------------------------------------------------
/perl-status output snippet:
Embedded Perl version v5.8.8 for Apache/2.2.6
Under the "perl-script" handler, the environment is:
    MOD_PERL = mod_perl/2.0.3
    MOD_PERL_API_VERSION = 2
    PATH = /sbin:/usr/sbin:/bin:/usr/bin

Reply via email to