Source: ntp
Version: 1:4.2.8p10+dfsg-1
Severity: wishlist
I posted a question to debian-users
(https://lists.debian.org/debian-user/2017/03/msg00591.html) and
nobody said "This already works" or "This is a bad idea", so I'm
filing this bug.
It would be nice if clock_gettime(CLOCK_TAI, ...) would give the
correct answer either with no special configuration or with very
little extra reconfiguration. This would probably be achieved by
downloading a table of leap seconds so it is related to #851096.
See also:
https://superuser.com/questions/1156693/is-there-a-way-of-getting-correct-clock-tai-on-linux
A test program to print out the difference between CLOCK_TAI and
CLOCK_UTC or CLOCK_REALTIME is attached. (Right-justification of
this bug report happened by accident.)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifndef CLOCK_TAI
# error CLOCK_TAI is not defined. Your C library is too old.
#endif
#ifndef CLOCK_UTC
# warning CLOCK_UTC is not defined, no surprise. Using CLOCK_REALTIME instead.
# define CLOCK_UTC CLOCK_REALTIME
#endif
int main()
{
struct timespec ts_utc1, ts_tai, ts_utc2;
long long diff1, diff2;
if (clock_gettime(CLOCK_UTC, &ts_utc1)) {
printf("clock_gettime(CLOCK_UTC, ...) failed\n");
exit(1);
}
if (clock_gettime(CLOCK_TAI, &ts_tai)) {
printf("clock_gettime(CLOCK_TAI, ...) failed\n");
exit(1);
}
if (clock_gettime(CLOCK_UTC, &ts_utc2)) {
printf("clock_gettime(CLOCK_UTC, ...) failed\n");
exit(1);
}
diff1 = ((ts_tai.tv_nsec - ts_utc1.tv_nsec) +
(ts_tai.tv_sec - ts_utc1.tv_sec ) * 1000000000LL);
diff2 = ((ts_tai.tv_nsec - ts_utc2.tv_nsec) +
(ts_tai.tv_sec - ts_utc2.tv_sec ) * 1000000000LL);
printf("Expected (TAI - UTC) in 2017:\n");
printf("%16lld\n", 37 * 1000000000LL);
printf("Difference between CLOCK_TAI and CLOCK_UTC is in range:\n");
printf("%16lld\n", diff2);
printf("%16lld\n", diff1);
return 0;
}