Date: Fri, 7 Aug 2009 13:35:30 -0700 From: "Peter Steele" <psteele@webmail.maxiscale.com> To: <freebsd-hackers@freebsd.org> Subject: How to signal a time zone change? Message-ID: <B8A480488C0C6849826655761349EA431F716A@owa.webmail.maxiscale.com>
next in thread | raw e-mail | index | archive | help
We have a suite of applications with a Java GUI controlling everything. One of the actions the user can perform is to set the time zone. We do this through our Java application and update the /etc/localtime as required. We also make an API call to tell the JVM that the time zone as changed, and from the perspective of the Java app, the time zone is changed correctly (the timestamps for example in our log files reflect the change). Likewise, after the user performs this action, running "date" on one of our systems shows that the time zone has been changed as requested.=20 =20 The problem is with our C applications. They continue to operate with the old time zone, so things like timestamps in log files are not in sync with the timestamps in the Java app log files. If we stop and restart the C apps they pick up the time zone change. However, we don't want to take this extreme approach. We want the Java app to signal to the C applications that the time zone has changed. However, I've experimented with the various time zone related calls and I cannot figure out what call is needed to make the C applications pick up the time zone change. I've tried setting the environment variable TZ to the new time zone and this doesn't seem to work, and I've tried calling tzset() and tzsetwall(). In each case after I make these calls the function "localtime()" does not return the same time base as the Java application. =20 Based on what I've read, I would think that the following steps would do the trick on the C side after the Java app changes time zone and updates /etc/localtime: =20 time_t date =3D time(NULL); unsetenv("TZ"); tzset(); printf("time zone is %s/%s", tzname[0], tzname[1]); struct tm* locTime =3D localtime(&date); printf("%02d:%02d:%02d", locTime->tm_hour, locTime->tm_min, locTime->tm_sec); =20 The time printed in this example however is still based on the old time zone. The tzname variable that is set by tzset() still shows for example EDT even if I have just changed the time zone to PDT. If I stop and restart the C app, the time is correct, and tzname is then PDT instead of EDT. =20 I'm very puzzled on what I'm supposed to do to kick start the time zone change in C. We do not want to have to restart our C apps for something as trivial as this. I posted this originally to the questions list but didn't get much traction. I'm hoping someone on this list can point me in the right direction. =20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B8A480488C0C6849826655761349EA431F716A>