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; }
*** This bug has been marked as a duplicate of 154 ***