commit 4fd65aec913a1b99e8d748a7a82c150b8f7ee510
parent 131a18f68dc73f208bb76a944fc6d42c86cfad3b
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Fri, 2 Jan 2015 10:15:29 +0000
Remove the --enable-right-tz configure option.
Make it a run-time autodetection instead.
Update doc.
Thanks to Paul Jarc for the suggestion.
Diffstat:
12 files changed, 63 insertions(+), 115 deletions(-)
diff --git a/COPYING b/COPYING
@@ -1,4 +1,4 @@
-Copyright (c) 2011-2014 Laurent Bercot <ska-skaware@skarnet.org>
+Copyright (c) 2011-2015 Laurent Bercot <ska-skaware@skarnet.org>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/configure b/configure
@@ -41,7 +41,6 @@ skalibs options:
--disable-ipv6 do not build IPv6 support [enabled]
--enable-iopause-select prefer select() over poll() for iopause implementation [disabled]
--enable-tai-clock assume the system clock is TAI-10 instead of UTC [disabled]
- --enable-right-tz assume the timezone is Olson's right/ instead of posix/ [disabled]
--enable-clock use clock_gettime() instead of gettimeofday() [disabled]
--enable-monotonic count time with CLOCK_MONOTONIC instead of CLOCK_REALTIME
--enable-force-devr assume /dev/random exists and is valid [autodetection takes time]
@@ -187,7 +186,6 @@ egd=
ipv6=true
select=false
taiclock=false
-righttz=false
clockrt=false
clockmon=false
forcedevr=false
@@ -237,8 +235,6 @@ for arg ; do
--disable-iopause-select|--enable-iopause-select=no) select=false ;;
--enable-tai-clock|--enable-tai-clock=yes) taiclock=true ;;
--disable-tai-clock|--enable-tai-clock=no) taiclock=false ;;
- --enable-right-tz|--enable-right-tz=yes) righttz=true ;;
- --disable-right-tz|--enable-right-tz=no) righttz=false ;;
--enable-clock|--enable-clock=yes) clockrt=true ;;
--disable-clock|--enable-clock=no) clockrt=false ;;
--enable-monotonic|--enable-monotonic=yes) clockmon=true ;;
@@ -562,11 +558,6 @@ if $taiclock ; then
else
echo "#undef ${package_macro_name}_FLAG_CLOCKISTAI"
fi
-if $righttz ; then
- echo "#define ${package_macro_name}_FLAG_TZISRIGHT"
-else
- echo "#undef ${package_macro_name}_FLAG_TZISRIGHT"
-fi
if $clockrt ; then
echo "#define ${package_macro_name}_FLAG_USERT"
else
diff --git a/doc/flags.html b/doc/flags.html
@@ -71,7 +71,7 @@ tested, so it's usually safe, and faster, to stick to the default.
<a name="clockistai"><h3> --enable-tai-clock </h3></a>
<p>
- To understand what this flag is about - and the next three flags too - you
+ To understand what this flag is about - and the next two flags too - you
should start by reading
<a href="http://www.madore.org/~david/computers/unix-leap-seconds.html">this
page about Unix time</a>,
@@ -105,10 +105,13 @@ and makes event loop handling (with functions such as
<li> ↑ skalibs uses TAI internally; setting your system clock to TAI-10
saves a lot of conversions and makes time computations with skalibs more
efficient. </li>
- <li> → In order to display GMT or local time properly, you have to
-use the <tt>right/</tt> timezones from Arthur David Olson's timezone
-library. If your libc does not support them, see the
-<a href="#tzisright">next flag</a>. </li>
+ <li> → skalibs-aware software will display GMT or local time properly in
+every case, but you have to
+use the <tt>right/</tt> timezones, from Arthur David Olson's timezone
+library, to prevent your other software from being confused by a TAI-10 system clock.
+If you do not use <tt>right/</tt> timezones, utilities such as <tt>date</tt>
+will not compute the proper time - they will have an offset of 24 seconds
+or so. </li>
<li> ↓ This setup is arguably not SUSv4 conformant (a strict
interpretation of Single Unix requires the system clock to be set to UTC). </li>
<li> ↓ This setup is <em>not</em> compatible with
@@ -126,7 +129,8 @@ POSIX setup:
<li> ↑ This is strictly SUSv4-compliant. Most Unix machines all over
the world are set up like this. </li>
<li> ↑ This is compatible with ntpd. </li>
- <li> → You should not use Olson's time library in that case. </li>
+ <li> → You should use <tt>posix/</tt> time zones in that case,
+not <tt>right/</tt> time zones. </li>
<li> ↓ skalibs time computations will take a bit more processing power. </li>
<li> ↓ Most importantly, you forsake all linearity - and even monotonicity
- on your system clock, which can now only be used as a wall clock,
@@ -154,48 +158,6 @@ POSIX freak, or your Unix distribution is running ntpd for you, or
other software is assuming you're on UTC. This is the default.
</p>
-
-<a name="tzisright"><h3> --enable-right-tz </h3>
-
-<p>
- This option instructs skalibs that you're using Olson's time
-library, i.e. "right/" timezones.
-</p>
-
-<p>
- Normally, if you set <a href="#clockistai">--enable-tai-clock</a>, you
-<em>should</em> also set up your timezone to a "right/" one, and
-set <tt>flag-tzisright</tt>. And if you don't use
-<a href="#clockistai">--enable-tai-clock</a>, you should also use a POSIX
-timezone, and NOT use <tt>--enable-right-tz</tt>. Those two options
-should always be used together.
-</p>
-
-<p>
- <em>But</em> some C libraries do not support the Olson time library's
-timezone format, and just do not provide the "right/" timezones! For
-instance, <a href="http://musl-libc.org/">musl</a>,
-an alternative libc for Linux, only supports POSIX timezones. And you
-might want to use such a libc, and <em>still</em> set up your clock to
-TAI-10, for instance in embedded environments where accurate timekeeping
-is important. In such cases, you'll set up a POSIX timezone, and use the
-<tt>--enable-tai-clock</tt> option without the <tt>--enable-right-tz</tt> one.
-</p>
-
-<p>
- Be aware that setting your system clock to TAI-10 without having a
-"right/" timezone will cause non-skalibs-using software to display
-local time incorrectly; in such a setup, only skalibs-using software
-will understand what is going on and do the proper computations to
-display the correct local time. Keep your settings as consistent as
-possible.
-</p>
-
-<p>
- By default, skalibs will consider you are using POSIX timezones (as well
-as a UTC system clock).
-</p>
-
<a name="usert"><h3> --enable-clock </h3></a>
<p>
diff --git a/doc/libstddjb/djbtime.html b/doc/libstddjb/djbtime.html
@@ -107,15 +107,10 @@ error occurs (for instance: the leap second table cannot be found).
<p>
The following functions convert time between an internal representation
-and a broken-down <tt>struct tm</tt>. The
-<a href="../flags.html#tzisright">--enable-right-tz</a> configure option is used in
-determining how the conversion should proceed. If the <tt>--enable-tai-clock</tt>
-and <tt>--enable-right-tz</tt> configure options have been both enabled
-or both disabled, everything is naturally
-converted as it should be. If only one of them has been enabled,
-unholy magic happens here
-to get the correct broken-down time despite the timezone definition being
-wrong.
+and a broken-down <tt>struct tm</tt>. Conversions are performed to
+get leap seconds handling right, depending on whether skalibs has been
+configured for a TAI-10 or a UTC system clock, and on whether the current
+timezone takes leap seconds into account or not.
</p>
<p>
diff --git a/doc/libstddjb/tai.html b/doc/libstddjb/tai.html
@@ -55,7 +55,7 @@ on time</a>. It's outdated (there was a leap second in 2009), but complete. </li
<a href="http://www.madore.org/~david/computers/unix-leap-seconds.html">page
about leap seconds, UTC and TAI</a>. </li>
<li> The skalibs <a href="../flags.html#clockistai">--enable-tai-clock</a>
-and <a href="../flags.html#tzisright">--enable-right-tz</a> documentation. </li>
+documentation. </li>
<li> <a href="http://cr.yp.to/proto/utctai.html">Dan J. Bernstein's page
on UTC, TAI and Unix time</a>. </li>
</ul>
diff --git a/package/deps.mak b/package/deps.mak
@@ -403,8 +403,8 @@ src/libstddjb/long_fmt.o src/libstddjb/long_fmt.lo: src/libstddjb/long_fmt.c src
src/libstddjb/long_scan.o src/libstddjb/long_scan.lo: src/libstddjb/long_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/ulong.h
src/libstddjb/ltm64_from_localtm.o src/libstddjb/ltm64_from_localtm.lo: src/libstddjb/ltm64_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
src/libstddjb/ltm64_from_sysclock.o src/libstddjb/ltm64_from_sysclock.lo: src/libstddjb/ltm64_from_sysclock.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
-src/libstddjb/ltm64_from_tai.o src/libstddjb/ltm64_from_tai.lo: src/libstddjb/ltm64_from_tai.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
-src/libstddjb/ltm64_from_utc.o src/libstddjb/ltm64_from_utc.lo: src/libstddjb/ltm64_from_utc.c src/include/skalibs/config.h src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/uint64.h
+src/libstddjb/ltm64_from_tai.o src/libstddjb/ltm64_from_tai.lo: src/libstddjb/ltm64_from_tai.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
+src/libstddjb/ltm64_from_utc.o src/libstddjb/ltm64_from_utc.lo: src/libstddjb/ltm64_from_utc.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/uint64.h
src/libstddjb/mininetstring_read.o src/libstddjb/mininetstring_read.lo: src/libstddjb/mininetstring_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/mininetstring.h src/include/skalibs/stralloc.h src/include/skalibs/uint32.h
src/libstddjb/mininetstring_write.o src/libstddjb/mininetstring_write.lo: src/libstddjb/mininetstring_write.c src/include/skalibs/allreadwrite.h src/include/skalibs/mininetstring.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h
src/libstddjb/ndelay_off.o src/libstddjb/ndelay_off.lo: src/libstddjb/ndelay_off.c src/include/skalibs/djbunix.h
@@ -492,6 +492,7 @@ src/libstddjb/siovec_seek.o src/libstddjb/siovec_seek.lo: src/libstddjb/siovec_s
src/libstddjb/skagetln.o src/libstddjb/skagetln.lo: src/libstddjb/skagetln.c src/include/skalibs/buffer.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h
src/libstddjb/skagetln_nofill.o src/libstddjb/skagetln_nofill.lo: src/libstddjb/skagetln_nofill.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h
src/libstddjb/skagetlnsep.o src/libstddjb/skagetlnsep.lo: src/libstddjb/skagetlnsep.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h
+src/libstddjb/skalibs_tzisright.o src/libstddjb/skalibs_tzisright.lo: src/libstddjb/skalibs_tzisright.c src/libstddjb/djbtime-internal.h
src/libstddjb/skasig_dfl.o src/libstddjb/skasig_dfl.lo: src/libstddjb/skasig_dfl.c src/include/skalibs/sig.h
src/libstddjb/skasigaction.o src/libstddjb/skasigaction.lo: src/libstddjb/skasigaction.c src/include/skalibs/sig.h src/include/skalibs/sysdeps.h
src/libstddjb/slurp.o src/libstddjb/slurp.lo: src/libstddjb/slurp.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h
@@ -575,7 +576,7 @@ src/libstddjb/sysclock_get.o src/libstddjb/sysclock_get.lo: src/libstddjb/sysclo
src/libstddjb/sysclock_set.o src/libstddjb/sysclock_set.lo: src/libstddjb/sysclock_set.c src/include/skalibs/config.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h
src/libstddjb/tai_add.o src/libstddjb/tai_add.lo: src/libstddjb/tai_add.c src/include/skalibs/tai.h
src/libstddjb/tai_from_localtm.o src/libstddjb/tai_from_localtm.lo: src/libstddjb/tai_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
-src/libstddjb/tai_from_ltm64.o src/libstddjb/tai_from_ltm64.lo: src/libstddjb/tai_from_ltm64.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
+src/libstddjb/tai_from_ltm64.o src/libstddjb/tai_from_ltm64.lo: src/libstddjb/tai_from_ltm64.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h
src/libstddjb/tai_from_sysclock.o src/libstddjb/tai_from_sysclock.lo: src/libstddjb/tai_from_sysclock.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h
src/libstddjb/tai_from_timespec.o src/libstddjb/tai_from_timespec.lo: src/libstddjb/tai_from_timespec.c src/include/skalibs/tai.h
src/libstddjb/tai_from_timeval.o src/libstddjb/tai_from_timeval.lo: src/libstddjb/tai_from_timeval.c src/include/skalibs/tai.h
diff --git a/src/include/skalibs/djbtime.h b/src/include/skalibs/djbtime.h
@@ -27,7 +27,7 @@ extern int tain_from_ntp (tain_t *, uint64) ;
/* localtime handling - replaces caltimedate functions */
-/* ltm64 can be either TAI-10 or UTC depending on --enable-right-tz */
+/* ltm64 can be either TAI-10 or UTC depending on the current timezone */
/* normally ltm64 is the same as sysclock, but we allow it to be different */
/* for instance for musl TAI-10 systems */
diff --git a/src/libstddjb/djbtime-internal.h b/src/libstddjb/djbtime-internal.h
@@ -6,7 +6,7 @@
#include <skalibs/uint64.h>
-/* Leap second handling, for UTC <--> TAI conversions */
+ /* Leap second handling, for UTC <--> TAI conversions */
#define LEAPSECS_MAX 39
#define LEAPSECS_FILE SKALIBS_ETC "/leapsecs.dat"
@@ -20,4 +20,8 @@ extern int leapsecs_sub_r (uint64 *, char const *, uint64 *) ;
#define leapsecs_sub(t) leapsecs_sub_r((t), LEAPSECS_FILE, leapsecs_here)
+ /* Run-time test: does the current timezone handle leap seconds ? */
+
+extern int skalibs_tzisright (void) ;
+
#endif
diff --git a/src/libstddjb/ltm64_from_tai.c b/src/libstddjb/ltm64_from_tai.c
@@ -1,23 +1,16 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/tai.h>
#include <skalibs/djbtime.h>
-
-#ifdef SKALIBS_FLAG_TZISRIGHT
+#include "djbtime-internal.h"
int ltm64_from_tai (uint64 *u, tai_t const *t)
{
- *u = t->x - 10U ;
- return 1 ;
+ switch (skalibs_tzisright())
+ {
+ case 1 : *u = t->x - 10U ; return 1 ;
+ case 0 : return utc_from_tai(u, t) ;
+ default : return 0 ;
+ }
}
-
-#else
-
-int ltm64_from_tai (uint64 *u, tai_t const *t)
-{
- return utc_from_tai(u, t) ;
-}
-
-#endif
diff --git a/src/libstddjb/ltm64_from_utc.c b/src/libstddjb/ltm64_from_utc.c
@@ -1,23 +1,15 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/djbtime.h>
#include "djbtime-internal.h"
-#ifdef SKALIBS_FLAG_TZISRIGHT
-
int ltm64_from_utc (uint64 *u)
{
- return (leapsecs_add(u, 0) >= 0) ;
+ switch (skalibs_tzisright())
+ {
+ case 1 : return leapsecs_add(u, 0) >= 0 ;
+ case 0 : return 1 ;
+ default : return 0 ;
+ }
}
-
-#else
-
-int ltm64_from_utc (uint64 *u)
-{
- (void)u ;
- return 1 ;
-}
-
-#endif
diff --git a/src/libstddjb/skalibs_tzisright.c b/src/libstddjb/skalibs_tzisright.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <time.h>
+#include "djbtime-internal.h"
+
+int skalibs_tzisright ()
+{
+ static int tzisright = -1 ;
+ if (tzisright < 0)
+ {
+ struct tm tm ;
+ time_t t = 78796800 ;
+ if (localtime_r(&t, &tm)) tzisright = tm.tm_sec == 60 ;
+ }
+ return tzisright ;
+}
diff --git a/src/libstddjb/tai_from_ltm64.c b/src/libstddjb/tai_from_ltm64.c
@@ -1,23 +1,16 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/tai.h>
#include <skalibs/djbtime.h>
-
-#ifdef SKALIBS_FLAG_TZISRIGHT
+#include "djbtime-internal.h"
int tai_from_ltm64 (tai_t *t, uint64 u)
{
- tai_u64(t, u + 10U) ;
- return 1 ;
+ switch (skalibs_tzisright())
+ {
+ case 1 : tai_u64(t, u + 10U) ; return 1 ;
+ case 0 : return tai_from_utc(t, u) ;
+ default : return 0 ;
+ }
}
-
-#else
-
-int tai_from_ltm64 (tai_t *t, uint64 u)
-{
- return tai_from_utc(t, u) ;
-}
-
-#endif