Bug 5186 - localtime does not handle changed /etc/localtime
Summary: localtime does not handle changed /etc/localtime
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.6
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-16 07:02 UTC by Andy Isaacson
Modified: 2014-07-04 07:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Isaacson 2007-10-16 07:02:25 UTC
Running "2.3.6.ds1-8" from Debian unstable on x86_64, libc does not seem to
correctly update its idea of localtime when /etc/localtime changes.

adi@xxxxx:~/tmp$ cat localtime-relink.c
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char b1[40], b2[40];
    time_t t;
    struct tm tm1, tm2;

    system("ln -snf /usr/share/zoneinfo/PST8PDT /etc/localtime");
    system("ls -l /etc/localtime");

    t = 1192516347;
    strftime(b1, sizeof(b1), "%F %T %Z", localtime_r(&t, &tm1));

    system("ln -snf /usr/share/zoneinfo/EST5EDT /etc/localtime");
    system("ls -l /etc/localtime");

    t = 1192516347;
    strftime(b2, sizeof(b2), "%F %T %Z", localtime_r(&t, &tm2));

    printf("b1 = %s\n", b1);
    printf("b2 = %s\n", b2);

    return 0;
}
adi@xxxxx:~/tmp$ cc -Wall -g localtime-relink.c
adi@xxxxx:~/tmp$ sudo ./a.out
lrwxrwxrwx 1 root root 27 2007-10-15 23:56 /etc/localtime ->
/usr/share/zoneinfo/PST8PDT
lrwxrwxrwx 1 root root 27 2007-10-16 02:56 /etc/localtime ->
/usr/share/zoneinfo/EST5EDT
b1 = 2007-10-15 23:32:27 PDT
b2 = 2007-10-15 23:32:27 PDT

Note that the ls output does have the proper timezone offset, but the two calls
to localtime_r return the same 'struct tm' values.  Inspecting with gdb shows
that all fields are the same.
Comment 1 Andy Isaacson 2007-10-16 08:01:45 UTC
(In reply to comment #0)
> Running "2.3.6.ds1-8" from Debian unstable on x86_64, libc does not seem to
> correctly update its idea of localtime when /etc/localtime changes.

Note that this is reproducable even with an empty environment.

adi@xxxxx:~/tmp$ sudo env -i env
adi@xxxxx:~/tmp$ sudo env -i ./a.out
lrwxrwxrwx 1 root root 27 Oct 16 01:00 /etc/localtime -> /usr/share/zoneinfo/PST8PDT
lrwxrwxrwx 1 root root 27 Oct 16 04:00 /etc/localtime -> /usr/share/zoneinfo/EST5EDT
b1 = 2007-10-15 23:32:27 PDT
b2 = 2007-10-15 23:32:27 PDT
Comment 2 Ulrich Drepper 2007-10-17 20:23:10 UTC
Your test case is wrong since localtime_r does not have to (nor should)
implicitly call tzset.  That's necessary to enable parallelism.

But there was a problem with using localtime after a file change.  This is now
fixed.
Comment 3 Dhinakaran K. 2007-12-14 09:09:15 UTC
Drepper,
(In reply to comment #2)
> Your test case is wrong since localtime_r does not have to (nor should)
> implicitly call tzset.  That's necessary to enable parallelism.
> But there was a problem with using localtime after a file change.  This is 
now
> fixed.

  Looks like, its a problem with localtime() even. 

Can I know, from which version on, localtime() can handle change 
in /etc/localtime. 

Thanks
dhina