[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [mp2] [question] $ENV{PATH} changes not taking effect?


There's a thread from December that would seem to be related.  From that thread:

---------- Forwarded message ----------
From: Michael Schout <suppressed>
Date: Dec 28, 2007 9:12 PM
Subject: Re: mod_perl, ENV{'TZ'}, and localtime
To: Kirk Noda <suppressed>
Cc: suppressed


Kirk Noda wrote:
> The thread seemed to die off.  Still, is there a way to use $ENV{TZ} to
> modify the behavior of localtime?

The reason this does not work under modperl version 2.0 is because under
handler "perl-script", %ENV is untied from the C environment.  The
localtime() function is implemented in C, and as a result, it will never
see the changes you made to $ENV{TZ} from mod_perl.

The way I got around this was to use Env::C, and override
CORE::localtime() with something like:

package MyLocaltime;

use Env::C;

sub import {
    my $class = shift;
    $class->export('CORE::GLOBAL', 'localtime');
}

sub localtime {
    my $time = shift;
    $time = time unless defined $time;

    my $orig_tz = Env::C::getenv('TZ');
    Env::C::setenv('TZ', $ENV{TZ}, 1);

    my @ret = CORE::localtime($time);

    Env::C::setenv('TZ', $orig_tz, 1);

    return @ret;
}

The real problem is that this is only safe under a prefork MPM because
it is not thread safe.  There really ought to be an option (IMO) where
you can make the untie of %ENV under perl-script to be optional.  Maybe
something like PerlOptions +NoUntieEnv or something so that if you are
running under a prefork MPM, you do not need to resort to tactics like
the above.

Regards,
Michael Schout


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.