You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Balázs Szabó (dLux)" <dl...@dlux.hu> on 2005/10/31 19:12:28 UTC
TZ variable and mod_perl
Hi,
I am the author of the Class::Date module, which can be found in CPAN,
and i had a complaint about timezone handling in perl.
I tried to debug it, and I have found that mod_perl uses the TZ
environment somehow differently.
What I did in my module is the following:
delete $ENV{TZ};
tzset();
($a, $b) = tzname();
$a should contain the local timezone (according to the documentation of
the tzset manual), although it is UTC always. What I suspect is that
when I delete the TZ variable from the environment, it does not really
delete it.
How I can make sure that this variable is deleted?
Do you know any other way to get the timezone which is guessed by
tzset() in case of the TZ environment variable does not work?
I have tested this in gentoo linux with perl 5.8.6 + mod_perl 2.0.1 and
on Centos 4 with perl 5.8.6 + mod_perl 1.99.16.
This error did not occur on Centos 4 with perl 5.8.5 +mod_perl 1.99.16
though, and did not occur in a non mod_perl environment either!
Any clue where I can go now? :-)
Thanks in advance,
--
Szabó Balázs (dLux)
-- -- - - - -- -
Re: TZ variable and mod_perl
Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2005-11-01 at 14:09 +0100, "Balázs Szabó (dLux)" wrote:
> As I read the perlthrtut, it seems that using this module is most
> probably will change the whole process' environment, so another
> paralelly served request can be affected as well, right?
It depends. Take a look at this:
http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code
- Perrin
Re: TZ variable and mod_perl
Posted by "Balázs Szabó (dLux)" <dl...@dlux.hu>.
Hi,
Tyler, thank you for the answer, I tried it, and it worked!
Although I am a little bit worried about the ithreads issues with this.
As I read the perlthrtut, it seems that using this module is most
probably will change the whole process' environment, so another
paralelly served request can be affected as well, right? I am asking it,
because I don't know how mod_perl works.
If the user uses a non-threaded MPM, then even if the libperl uses
ithreads, then I guess one apache process only serves one request, so it
must not be a problem, right?
But I guesst with a threaded MPM, setting the TZ environment variable is
not a good idea, since it can affect other running requests.
Are my assumptions right? Can someone confirm them? I would like to put
some warning to the documentation of my module, and tweak it to use as
less tzset as possible...
Thanks in adnvance,
Balázs
Tyler MacDonald wrote:
> I had to use Env::C to accomplish this;
>
>sub set_tz_env {
> my($class, $tz) = @_;
> Env::C::setenv('TZ', $tz);
> $ENV{TZ} = $tz;
> POSIX::tzset();
>}
>
>
--
Szabó Balázs (dLux)
-- -- - - - -- -
Re: TZ variable and mod_perl
Posted by Tyler MacDonald <ty...@ActiveState.com>.
"Balázs Szabó (dLux)" <dl...@dlux.hu> wrote:
> What I did in my module is the following:
>
> delete $ENV{TZ};
> tzset();
> ($a, $b) = tzname();
>
> $a should contain the local timezone (according to the documentation of
> the tzset manual), although it is UTC always. What I suspect is that
> when I delete the TZ variable from the environment, it does not really
> delete it.
>
> How I can make sure that this variable is deleted?
I had to use Env::C to accomplish this;
sub set_tz_env {
my($class, $tz) = @_;
Env::C::setenv('TZ', $tz);
$ENV{TZ} = $tz;
POSIX::tzset();
}
Cheers,
Tyler
Re: TZ variable and mod_perl
Posted by "JupiterHost.Net" <ml...@jupiterhost.net>.
Balázs Szabó (dLux) wrote:
> Hi,
Hello,
> I am the author of the Class::Date module, which can be found in CPAN,
> and i had a complaint about timezone handling in perl.
>
> I tried to debug it, and I have found that mod_perl uses the TZ
> environment somehow differently.
>
> What I did in my module is the following:
>
> delete $ENV{TZ};
> tzset();
> ($a, $b) = tzname();
>
> $a should contain the local timezone (according to the documentation of
Oi! nor sure where to start,
1)
use strict;
use warnings;
2) don't use $a and $b
- they are special
- they are super ambiguouse
3) use good names so you and we know what you're smoking...
> delete $ENV{TZ};
> tzset();
POSIX POD: "tzset() for setting the current timezone based on the
environment variable TZ"
If you just deleted it how can it use it?
> ($a, $b) = tzname();
my($standard_timezone, $summer_timezone) = tzname();
> the tzset manual), although it is UTC always. What I suspect is that
> when I delete the TZ variable from the environment, it does not really
> delete it.
>
> How I can make sure that this variable is deleted?
if(defined $ENV{TZ}) {
print "TZ: $ENV{TZ}\n";
}
else {
print "TZ is not defined in my ENV\n";
}
maybe check the system's with `printenv`...
> Do you know any other way to get the timezone which is guessed by
> tzset() in case of the TZ environment variable does not work?
`man tzset` says:
If TZ does not appear in the environment, the best available
approxima-
tion to local wall clock time, as specified by the
tzfile(5)-format file
/etc/localtime is used.
If TZ appears in the environment but its value is a null string,
Coordi-
nated Universal Time (UTC) is used (without leap second correction).
If TZ appears in the environment and its value begins with a colon
(`:'),
the rest of its value is used as a pathname of a tzfile(5)-format file
from which to read the time conversion information. If the first
charac-
ter of the pathname is a slash (`/') it is used as an absolute
pathname;
otherwise, it is used as a pathname relative to the system time
conver-
sion information directory.
If its value does not begin with a colon, it is first used as the
path-
name of a file (as described above) from which to read the time
conver-
sion information. If that file cannot be read, the value is then
inter-
preted as a direct specification (the format is described below)
of the
time conversion information.
If the TZ environment variable does not specify a tzfile(5)-format
file
and cannot be interpreted as a direct specification, UTC is used.
Re: TZ variable and mod_perl
Posted by Stas Bekman <st...@stason.org>.
Balázs Szabó (dLux) wrote:
> Hi,
>
> I am the author of the Class::Date module, which can be found in CPAN,
> and i had a complaint about timezone handling in perl.
>
> I tried to debug it, and I have found that mod_perl uses the TZ
> environment somehow differently.
>
> What I did in my module is the following:
>
> delete $ENV{TZ};
> tzset();
> ($a, $b) = tzname();
>
> $a should contain the local timezone (according to the documentation of
> the tzset manual), although it is UTC always. What I suspect is that
> when I delete the TZ variable from the environment, it does not really
> delete it.
>
> How I can make sure that this variable is deleted?
http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code
--
_____________________________________________________________
Stas Bekman mailto:stas@stason.org http://stason.org/
MailChannels: Assured Messaging(TM) http://mailchannels.com/
The "Practical mod_perl" book http://modperlbook.org/
http://perl.apache.org/ http://perl.org/ http://logilune.com/