Re: How to signal a time zone change?

2009-08-10 Thread Brian Somers
On Fri, 7 Aug 2009 15:08:16 -0700 Peter Steele 
pste...@webmail.maxiscale.com wrote:
 What's the value of the TZ environment variable for the C apps? You may
 need to have them read the new value from somewhere, and then rerun
 tzset().
 
 The default value of the TZ environment variable is null. I just tried
 passing the explicitly time zone value to the C app and setting TZ to
 that value and that seemed to work. I would think that that I should be
 able to retrieve that value from /etc/localtime as the docs imply. Guess
 not. If I have to pass the time zone to the C app, then I guess that's
 what I'll do...

This doesn't work because of two bugs in localtime.c.  The first is what
you're hitting where tzset() calls tzset_basic() which calls tzsetwall_basic()
which says:

if (lcl_is_set  0) {
if (!rdlocked)
_RWLOCK_UNLOCK(lcl_rwlock);
return;
}

If you were to have your own TZ setting and wanted to modify the
file referred to by that, you'd bump into this bug in tzset_basic():

if (lcl_is_set  0  strcmp(lcl_TZname, name) == 0) {
if (!rdlocked)
_RWLOCK_UNLOCK(lcl_rwlock);
return;
}

Roughly translated, localtime.c goes out of its way to never re-read the
same zone file twice in a row.  This is just a mistake.

As you discovered, altering TZ before calling tzset() is the best way to
make it work right now.  If you really want to ensure that you're reading
/etc/localtime, this bit of hackery works too:

putenv(TZ=/dev/null);
tzset();
unsetenv(TZ);
tzset();

If you raise a PR and let me know the number, I'd be happy to fix this.


-- 
Brian Somers  br...@awfulhak.org
Don't _EVER_ lose your sense of humour !   br...@freebsd.org


signature.asc
Description: PGP signature


How to signal a time zone change?

2009-08-07 Thread Peter Steele
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. 

 

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.

 

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:

 

time_t date = time(NULL);

unsetenv(TZ);

tzset();

printf(time zone is %s/%s, tzname[0], tzname[1]);

struct tm* locTime = localtime(date);

printf(%02d:%02d:%02d, locTime-tm_hour,
locTime-tm_min, locTime-tm_sec);

 

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.

 

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.

 

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: How to signal a time zone change?

2009-08-07 Thread Julian Elischer

Peter Steele wrote:

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. 

 


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


You need to signal your app in some way.. Assuming you have source for 
the app then you can monitor /etc/localtime (or /etc) for change with

kevent.




___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


RE: How to signal a time zone change?

2009-08-07 Thread Peter Steele
You need to signal your app in some way.. Assuming you have source for
the app then you can monitor /etc/localtime (or /etc) for change with
kevent.

Signaling our C apps aren't the problem. We have an IPC framework in
place and we can easily tell the C apps when the user has changed the
time zone via the GUI. The problem is I can't figure out what C calls
are needed to instantiate the time zone change. Based on the
documentation, I would think that tzset() would do the trick once
/etc/localtime has been updated by the Java app, but this does not work.
The only way I've discovered that works is to restart our C apps and we
want to avoid that.

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


RE: How to signal a time zone change?

2009-08-07 Thread Peter Steele
What's the value of the TZ environment variable for the C apps? You may
need to have them read the new value from somewhere, and then rerun
tzset().

The default value of the TZ environment variable is null. I just tried
passing the explicitly time zone value to the C app and setting TZ to
that value and that seemed to work. I would think that that I should be
able to retrieve that value from /etc/localtime as the docs imply. Guess
not. If I have to pass the time zone to the C app, then I guess that's
what I'll do...

 

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org