Fix for mktime() issue

Albrecht Dreß albrecht.dress at arcor.de
Tue Mar 16 19:51:51 CET 2010


Am 16.03.10 10:30 schrieb(en) Ton Voon:
>> The POSIX standard says [1]
>> 
>> <snip>
>> A positive or 0 value for tm_isdst shall cause mktime() to presume initially that Daylight Savings Time, respectively, is or is not in effect for the specified time. A negative value for tm_isdst shall cause mktime() to attempt to determine whether Daylight Savings Time is in effect for the specified time.
>> </snip>
[snip]
>> Note that tm_isdst < 0 has been marked as POSIX extension to ISO 9899

This is actually not true - ISO/IEC 9899:TC2, available from [2], states in section 7.23.2.3, clause 2, exactly the same.  No idea why POSIX states it's an extension.

>> What should be the purpose of a test case if the code strictly follows POSIX?
> 
> Because the test cases proves real-world usage, rather than some spec?

I don't think that POSIX and ISO 9899 are just "some spec".  If my proper usage of a well-defined library function produces weird results, I wouldn't assume that I am right and all those IEEE and ISO people (and glibc coders) are wrong.  The usual approach IMHO would be looking at *my* code, which might be /slightly/ less perfect at second glance...

> What I don't have, are tests for the other 18 cases where is_dst has been initialised, and so I didn't revert those other changes. But my opinion is now that this is too cautious and we should just revert back to Nagios pre-3.2.0 behaviour.

If you don't believe me, run the attached little C test app which takes the current time, simulates your approach of the unitialised field, and converts back, which should of course give the initial value.  For me (CET, no dst in effect) the code always fails (==produces an off-by-one-hour error) if the tm_isdst is > 0.  I don't think you will find any box with time zone != UTC where it doesn't...

Regarding Nagios, I can at least confirm that the wrong usage of the mktime() function (i.e. not initialising the tm_isdst field properly) does lead to time calculation bugs.  See [2. 3] for details.

Best, Albrecht.


[1] <http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf>
[2] <http://article.gmane.org/gmane.network.nagios.user/58359>
[3] <http://article.gmane.org/gmane.network.nagios.user/58392>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mktime-test.c
Type: text/x-csrc
Size: 1190 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20100316/849c32d8/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20100316/849c32d8/attachment.sig>
-------------- next part --------------
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel


More information about the Developers mailing list