Bug 155 - tzset not called frequently enough by localtime() and friends
Summary: tzset not called frequently enough by localtime() and friends
Status: RESOLVED DUPLICATE of bug 154
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.2
: P2 normal
Target Milestone: ---
Assignee: GOTO Masanori
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-12 01:09 UTC by Bruce Allen
Modified: 2019-04-10 11:54 UTC (History)
1 user (show)

See Also:
Host: i386-redhat-linux-gnu
Target: i386-redhat-linux-gnu
Build: i386-redhat-linux-gnu
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bruce Allen 2004-05-12 01:09:15 UTC
Suppose that a daemon logs information every ten minutes using syslog(3).
Part of the syslog output includes a timestamp, in the local time zone.
Now suppose that the user takes the machine (laptop) and flies to a new
timezone, then changes /etc/localtime to reflect the new timezone.  The daemon
(which has not been stopped and is still running) will continue to make syslog
entries using the OLD timezone.

This is because localtime() calls tzset on first invocation to learn the
timezone but then caches that information.  However it's not enough to see if
the TZ variable changes.  If TZ is not set then one also needs to check
/etc/localtime before each call to see if THAT has changed.

See bug number 48184 at http://bugs.debian.org for a similar report.

To reproduce the bug:

(1) unset TZ environment variable in shell
(2) run program below
(3) while program is running, change /etc/localtime to a new timezone.
    Note that localtime printed does NOT reflect this change.

#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main() {
  time_t epochnow;
  struct tm *timenow;	
  
  if (getenv("TZ")) {
    fprintf(stderr,"To demonstrate this bug, you must unset the TZ environment
variable\n");
    return 1;
  }

  while (1) {
    time(&epochnow);
    timenow=localtime(&epochnow);
    printf("Time is %s", asctime(timenow));
    sleep(5);   
  }  
  return 0;
}
Comment 1 Bruce Allen 2004-05-12 01:10:51 UTC

*** This bug has been marked as a duplicate of 154 ***