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>

Attachment: signature.asc
Description: PGP signature

Reply via email to