Rational behind lcl_is_set?

John Hawkinson jhawk at mit.edu
Wed Mar 29 07:36:31 UTC 2000


[ If you could cc me on replies until my subscription request is
processed, I'd appreciate it. ]

I recently made the oberservation that tzset() seems to keep state on
whether it has read the system localtime file and if so, subsequent
invokations of tzset() do not re-read the file.

This seems to prevent applications which call tzset() from obtaining
new time zone information should the system change.

For instance, my laptop recently travelled through:

US/Eastern -> US/Central -> US/Pacific -> Pacific/Gambier -> Pacific/Honolulu
 -> Pacific/Midway -> Pacific/Fiji -> Pacific/Auckland -> Pacific/Kosrae
 -> Australia/Sydney -> Australia/Adelaide

during which time my /etc/localtime file changed as appropriate.  It
would have been nice if, had my MUA called tzset() across each time
zone, times would have been correct.

But tzset() seems to cache old data. In my case, $TZ is unset
so tzsetwall() is called, and it's first act is:

        if (lcl_is_set < 0)
                return;
        lcl_is_set = -1;

So there seems to be no hope of causing tzset() to re-read this
data. Ironically enough, it seems that if the value of TZ changes,
tzset() will change state. This seems odd as it seems far more likely
that the system's /etc/localtime file will change, than a process will
actually change its own TZ environment variable in mid-flight.

I presume that this caching was added as an optimization
since strftime() calls tzset() during each invokations.

Is there no way around it, short of changing the API and
adding some function to reload timezone data, or giving up
the caching and having tzset() reread localtime each time?
The presence of STD_INSPIRED implies that new functions could be
added, but I presume there's a relatively high hurdle to doing so.

Incidently, tzset() seems a bit underdocumented. Specifically
newtzset(3) fails to indicate whether programs should call tzset()
by hand, or whether they should never bother, etc., etc. If I
knew the answer I would offer a patch.

Thanks.

--jhawk

p.s.: You're free to tell me that I'm foolish for wanting my time
to change accurately on transoceanic flighs, but it is terribly nice to
have one's mail timestamped appropriate, at the very least.



More information about the tz mailing list