From 4fd65aec913a1b99e8d748a7a82c150b8f7ee510 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 2 Jan 2015 10:15:29 +0000 Subject: Remove the --enable-right-tz configure option. Make it a run-time autodetection instead. Update doc. Thanks to Paul Jarc for the suggestion. --- COPYING | 2 +- configure | 9 ------ doc/flags.html | 58 +++++++-------------------------------- doc/libstddjb/djbtime.html | 13 +++------ doc/libstddjb/tai.html | 2 +- package/deps.mak | 7 +++-- src/include/skalibs/djbtime.h | 2 +- src/libstddjb/djbtime-internal.h | 6 +++- src/libstddjb/ltm64_from_tai.c | 21 +++++--------- src/libstddjb/ltm64_from_utc.c | 20 ++++---------- src/libstddjb/skalibs_tzisright.c | 17 ++++++++++++ src/libstddjb/tai_from_ltm64.c | 21 +++++--------- 12 files changed, 63 insertions(+), 115 deletions(-) create mode 100644 src/libstddjb/skalibs_tzisright.c diff --git a/COPYING b/COPYING index 63309ba..a49b1ca 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2011-2014 Laurent Bercot +Copyright (c) 2011-2015 Laurent Bercot 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 index 389b31b..a946138 100755 --- 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 index a7bdab8..f519685 100644 --- 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.

--enable-tai-clock

- 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 this page about Unix time, @@ -105,10 +105,13 @@ and makes event loop handling (with functions such as

  • ↑ skalibs uses TAI internally; setting your system clock to TAI-10 saves a lot of conversions and makes time computations with skalibs more efficient.
  • -
  • → In order to display GMT or local time properly, you have to -use the right/ timezones from Arthur David Olson's timezone -library. If your libc does not support them, see the -next flag.
  • +
  • → skalibs-aware software will display GMT or local time properly in +every case, but you have to +use the right/ 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 right/ timezones, utilities such as date +will not compute the proper time - they will have an offset of 24 seconds +or so.
  • ↓ This setup is arguably not SUSv4 conformant (a strict interpretation of Single Unix requires the system clock to be set to UTC).
  • ↓ This setup is not compatible with @@ -126,7 +129,8 @@ POSIX setup:
  • ↑ This is strictly SUSv4-compliant. Most Unix machines all over the world are set up like this.
  • ↑ This is compatible with ntpd.
  • -
  • → You should not use Olson's time library in that case.
  • +
  • → You should use posix/ time zones in that case, +not right/ time zones.
  • ↓ skalibs time computations will take a bit more processing power.
  • ↓ 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.

    - -

    --enable-right-tz

    - -

    - This option instructs skalibs that you're using Olson's time -library, i.e. "right/" timezones. -

    - -

    - Normally, if you set --enable-tai-clock, you -should also set up your timezone to a "right/" one, and -set flag-tzisright. And if you don't use ---enable-tai-clock, you should also use a POSIX -timezone, and NOT use --enable-right-tz. Those two options -should always be used together. -

    - -

    - But some C libraries do not support the Olson time library's -timezone format, and just do not provide the "right/" timezones! For -instance, musl, -an alternative libc for Linux, only supports POSIX timezones. And you -might want to use such a libc, and still 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 ---enable-tai-clock option without the --enable-right-tz one. -

    - -

    - 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. -

    - -

    - By default, skalibs will consider you are using POSIX timezones (as well -as a UTC system clock). -

    -

    --enable-clock

    diff --git a/doc/libstddjb/djbtime.html b/doc/libstddjb/djbtime.html index 45876c8..2fa3071 100644 --- 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).

    The following functions convert time between an internal representation -and a broken-down struct tm. The ---enable-right-tz configure option is used in -determining how the conversion should proceed. If the --enable-tai-clock -and --enable-right-tz 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 struct tm. 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.

    diff --git a/doc/libstddjb/tai.html b/doc/libstddjb/tai.html index 3524c05..3617959 100644 --- a/doc/libstddjb/tai.html +++ b/doc/libstddjb/tai.html @@ -55,7 +55,7 @@ on time. It's outdated (there was a leap second in 2009), but complete.

  • page about leap seconds, UTC and TAI.
  • The skalibs --enable-tai-clock -and --enable-right-tz documentation.
  • +documentation.
  • Dan J. Bernstein's page on UTC, TAI and Unix time.
  • diff --git a/package/deps.mak b/package/deps.mak index 66c0fb2..41a36a2 100644 --- 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 index 8aace55..7e60cd4 100644 --- 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 index 26ffc81..819b88a 100644 --- a/src/libstddjb/djbtime-internal.h +++ b/src/libstddjb/djbtime-internal.h @@ -6,7 +6,7 @@ #include -/* 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 index c0650c5..9161a79 100644 --- a/src/libstddjb/ltm64_from_tai.c +++ b/src/libstddjb/ltm64_from_tai.c @@ -1,23 +1,16 @@ /* ISC license. */ -#include #include #include #include - -#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 index 8d66813..28907c9 100644 --- a/src/libstddjb/ltm64_from_utc.c +++ b/src/libstddjb/ltm64_from_utc.c @@ -1,23 +1,15 @@ /* ISC license. */ -#include #include #include #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 new file mode 100644 index 0000000..f8414a6 --- /dev/null +++ b/src/libstddjb/skalibs_tzisright.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include +#include +#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 index 2538c00..12a7394 100644 --- a/src/libstddjb/tai_from_ltm64.c +++ b/src/libstddjb/tai_from_ltm64.c @@ -1,23 +1,16 @@ /* ISC license. */ -#include #include #include #include - -#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 -- cgit v1.2.3