TZ cache on some Linux kernels

J

Jon

While doing some time/date functions I had to change the timezone used
(by changing the ENV{TZ}) twice in one script. However, it seems the
kernel cached the last zone and failed to open or change to the new
one. I confirmed this using strace, as you could see it only opened
the one file. The code I used is as follows.

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/London';

$time = time();

($sec,$min,$hour,$day,$mon,$this_year,$wday,$yday,$isdst) =
localtime($time);
print "$hour:$min\n";

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';

($sec,$min,$hour,$day,$mon,$this_year,$wday,$yday,$isdst) =
localtime($time);
print "$hour:$min\n";

Is the code I used. The times should be out by an hour (Paris is one
hour ahead of London), however for me they both show the same time,
which is within the London (GMT+1) timezone. The results were
different on another server.

Linux 2.4.20 complied from source, Perl 5.8.0 (RedHat RPM) - failed.
Linux 2.4.7 RedHat supplied, Perl 5.6.0 (RedHat RPM) - worked.

I should really repeat the tests with the same version of Perl on both
kernels, this time I will build Perl myself, I will try that later
today, but I wonder if anyone else can confirm this issue or maybe
point me in the direction of the problem.

Jon.
 
D

David Efflandt

While doing some time/date functions I had to change the timezone used
(by changing the ENV{TZ}) twice in one script. However, it seems the
kernel cached the last zone and failed to open or change to the new
one. I confirmed this using strace, as you could see it only opened
the one file. The code I used is as follows.

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/London';

$time = time();

($sec,$min,$hour,$day,$mon,$this_year,$wday,$yday,$isdst) =
localtime($time);
print "$hour:$min\n";

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';

($sec,$min,$hour,$day,$mon,$this_year,$wday,$yday,$isdst) =
localtime($time);
print "$hour:$min\n";

Is the code I used. The times should be out by an hour (Paris is one
hour ahead of London), however for me they both show the same time,
which is within the London (GMT+1) timezone. The results were
different on another server.

Linux 2.4.20 complied from source, Perl 5.8.0 (RedHat RPM) - failed.
Linux 2.4.7 RedHat supplied, Perl 5.6.0 (RedHat RPM) - worked.

man tzslect (to see what to use for TZ). Try:

$ENV{TZ} = 'Europe/London';
$time = time();
print scalar localtime($time)."\n";
$ENV{TZ} = 'Europe/Paris';
print scalar localtime($time)."\n";
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Jon
While doing some time/date functions I had to change the timezone used
(by changing the ENV{TZ}) twice in one script. However, it seems the
kernel cached the last zone and failed to open or change to the new
one. I confirmed this using strace, as you could see it only opened
the one file. The code I used is as follows.

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/London';

Check whether tzset() is required on your system... It is a Perl bug
that it does not call tzset() when/if required.

In principle, tzset() is available in POSIX.

Hope this helps,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Am I on the right track - timezones 4
localtime(time()) 16
time format +1 hour 15
localtime and mktime 2
tape rotations and tape autoloaders 9
Date Problem 6
Need some help... 14
TimeDate conversion to string. 8

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top