$MirBSD: Web/pub/openntpd-3.9p1-leapsecs.diff,v 1.2 2006/06/09 21:02:09 tg Exp $ --- openntpd-3.9p1/LICENCE.orig Sun May 14 05:29:00 2006 +++ openntpd-3.9p1/LICENCE Fri Jun 9 20:53:43 2006 @@ -100,4 +100,9 @@ daemon.c, sys-queue.h: The Regents of th * SUCH DAMAGE. */ +Support for leap seconds ("right" timezones, as opposed to "posix" ones) +is an extension by Thorsten Glaser and covered by the MirOS licence, but +available to the OpenBSD project for use in rdate(8), ntpd(8) etc. under +the ISC licence. + $Id: openntpd-3.9p1-leapsecs.diff,v 1.2 2006/06/09 21:02:09 tg Exp $ --- openntpd-3.9p1/Makefile.in.orig Sun May 14 05:29:01 2006 +++ openntpd-3.9p1/Makefile.in Fri Jun 9 20:59:36 2006 @@ -33,9 +33,9 @@ STRIP_OPT=@STRIP_OPT@ PROG= ntpd LIBCOMPAT=openbsd-compat/libopenbsd-compat.a SRCS= ntpd.c buffer.c log.c imsg.c ntp.c ntp_msg.c config.c \ - server.c client.c util.c y.tab.c + server.c client.c util.c y.tab.c ntpleaps.c OBJS= ntpd.o buffer.o log.o imsg.o ntp.o ntp_msg.o config.o \ - server.o client.o util.o y.tab.o + server.o client.o util.o y.tab.o ntpleaps.o YFLAGS= MANPAGES_IN= ntpd.8 ntpd.conf.5 MANPAGES= ntpd.8.out ntpd.conf.5.out @@ -64,7 +64,7 @@ catman-do: $(MANPAGES_IN) nroff -mandoc ntpd.conf.5 | cat -v | sed -e 's/.\^H//g' > ntpd.conf.0 ntpd: ntpd.o buffer.o log.o imsg.o ntp.o ntp_msg.o config.o \ - server.o client.o util.o y.tab.o $(LIBCOMPAT) + server.o client.o util.o y.tab.o ntpleaps.o $(LIBCOMPAT) $(CC) $(CFLAGS) $(LDFLAGS) -o ntpd $(OBJS) $(LIBCOMPAT) $(LIBS) .c.o: --- openntpd-3.9p1/contrib/redhat/openntpd.spec.orig Sun May 14 05:28:57 2006 +++ openntpd-3.9p1/contrib/redhat/openntpd.spec Fri Jun 9 20:53:43 2006 @@ -1,6 +1,6 @@ -Summary: NTP Time Synchronization Client +Summary: NTP Time Synchronisation Client Name: openntpd -Version: 3.7p1 +Version: 3.9p1 Release: 1 Copyright: BSD License Group: Applications/System @@ -13,7 +13,8 @@ Requires: /sbin/chkconfig #Patch1: openntpd-3.6p1-linux-adjtimex3.patch %description -NTP Time Synchronization Client - http://www.openntpd.org +NTP Time Synchronisation Client - http://www.openntpd.org +Enhanced by correct leap second support facility by MirOS %prep %setup -q -n %{name}-%{version} --- openntpd-3.9p1/ntpd.0.orig Sun May 14 05:30:57 2006 +++ openntpd-3.9p1/ntpd.0 Fri Jun 9 20:53:43 2006 @@ -1,4 +1,4 @@ -NTPD(8) OpenBSD System Manager's Manual NTPD(8) +NTPD(8) BSD System Manager's Manual NTPD(8) NAME ntpd - Network Time Protocol daemon @@ -9,9 +9,10 @@ SYNOPSIS DESCRIPTION The ntpd daemon synchronizes the local clock to one or more remote NTP servers, and can also act as an NTP server itself, redistributing the lo- - cal time. It implements the Simple Network Time Protocol version 4, as - described in RFC 2030, and the Network Time Protocol version 3, as de- - scribed in RFC 1305. + cal time. This version of the NTP daemon handles time zones with leap + seconds correctly. It implements the Simple Network Time Protocol version + 4, as described in RFC 2030, and the Network Time Protocol version 3, as + described in RFC 1305. ntpd uses the adjtime(2) system call to correct the local system time without causing time jumps. Adjustments larger than 128ms are logged us- @@ -51,4 +52,4 @@ SEE ALSO HISTORY The ntpd program first appeared in OpenBSD 3.6. -OpenBSD 3.9 July 9, 2004 1 +MirOS BSD #8 July 9, 2004 1 --- openntpd-3.9p1/ntpd.8.orig Sun May 14 05:29:00 2006 +++ openntpd-3.9p1/ntpd.8 Fri Jun 9 20:53:43 2006 @@ -32,6 +32,7 @@ The daemon synchronizes the local clock to one or more remote NTP servers, and can also act as an NTP server itself, redistributing the local time. +This version of the NTP daemon handles time zones with leap seconds correctly. It implements the Simple Network Time Protocol version 4, as described in RFC 2030, and the Network Time Protocol version 3, --- openntpd-3.9p1/ntpd.conf.orig Sun May 14 05:28:58 2006 +++ openntpd-3.9p1/ntpd.conf Fri Jun 9 20:56:17 2006 @@ -3,8 +3,9 @@ # Addresses to listen on (ntpd does not listen by default) #listen on * -#listen on 127.0.0.1 -#listen on ::1 +# Use the lines below (IPv4, IPv6) since the above line does not work reliably +listen on 0.0.0.0 +listen on :: # sync to a single server #server ntp.example.org --- openntpd-3.9p1/ntpleaps.c.orig Thu Jan 1 00:00:00 1970 +++ openntpd-3.9p1/ntpleaps.c Fri Jun 9 20:58:09 2006 @@ -0,0 +1,111 @@ +/* $MirOS: src/usr.sbin/rdate/ntpleaps.c,v 1.6 2006/06/09 20:58:09 tg Exp $ */ + +/*- + * Copyright (c) 2006 + * Thorsten Glaser + * Based upon code placed into the public domain by Dan J. Bernstein. + * + * Licensee is hereby permitted to deal in this work without restric- + * tion, including unlimited rights to use, publicly perform, modify, + * merge, distribute, sell, give away or sublicence, provided all co- + * pyright notices above, these terms and the disclaimer are retained + * in all redistributions or reproduced in accompanying documentation + * or other materials provided with binary redistributions. + * + * Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind, + * express, or implied, to the maximum extent permitted by applicable + * law, without malicious intent or gross negligence; in no event may + * licensor, an author or contributor be held liable for any indirect + * or other damage, or direct damage except proven a consequence of a + * direct error of said person and intended use of this work, loss or + * other issues arising in any way out of its use, even if advised of + * the possibility of such damage or existence of a nontrivial bug. + */ + +#include +#include +#include +#include + +#include "ntpleaps.h" + +#ifndef __RCSID +#define __RCSID(x) static const char __rcsid[] __attribute__((used)) = (x) +#endif + +__RCSID("$MirOS: src/usr.sbin/rdate/ntpleaps.c,v 1.6 2006/06/09 20:58:09 tg Exp $"); + +time_t +tick2utc(time_t kerneltick) +{ + static unsigned long times365[4] = { + 0, 365, 730, 1095 + }; + static unsigned long times36524[4] = { + 0, 36524UL, 73048UL, 109572UL + }; + static unsigned long montab[12] = { + 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337 + }; + + struct tm *tm; + int64_t utc, d = 1900; + int m, y; + + tm = localtime(&kerneltick); + d += tm->tm_year; + + if (d < 0) + ++d; + y = (int)(d % 400LL); + d = 146097LL * (d / 400) + tm->tm_mday - 678882LL; + utc = tm->tm_sec - tm->tm_gmtoff + 60 * (tm->tm_min + 60 * tm->tm_hour); + + while (utc < 0L) { + utc += 86400L; + --d; + } + while (utc > 86400L) { + utc -= 86400L; + ++d; + } + + if ((m = tm->tm_mon) >= 2) { + m -= 2; + } else { + m += 10; + --y; + } + + y += (m / 12); + m %= 12; + if (m < 0) { + m += 12; + --y; + } + d += montab[m]; + + d += 146097LL * (y / 400LL); + y %= 400; + while (y < 0) { + y += 400; + d -= 146097LL; + } + + d += times365[y & 3]; + y /= 4; + + d += 1461LL * (y % 25); + y /= 25; + + d += times36524[y & 3]; + + /* + * d now contains the date part of the MJD + * corresponding to tm / kerneltick; the + * second part is already stored in utc. + */ + + utc += (d - 40587LL) * 86400LL; + return (utc); +} --- openntpd-3.9p1/ntpleaps.h.orig Thu Jan 1 00:00:00 1970 +++ openntpd-3.9p1/ntpleaps.h Fri Jun 9 20:58:10 2006 @@ -0,0 +1,10 @@ +/* $MirOS: src/usr.sbin/rdate/ntpleaps.h,v 1.5 2006/06/09 20:58:10 tg Exp $ */ + +/* + * Converts a time_t measured in kernel ticks into a UTC time_t + * using leap second information stored in /etc/localtime or an + * equivalent indicator (e.g. the TZ environment variable). + * If the kernel time is already measured in UTC instead of TAI + * and a POSIX conformant time zone is set, this is a no-op. + */ +time_t tick2utc(time_t); --- openntpd-3.9p1/util.c.orig Sun May 14 05:29:00 2006 +++ openntpd-3.9p1/util.c Fri Jun 9 20:59:33 2006 @@ -20,6 +20,7 @@ #include #include "ntpd.h" +#include "ntpleaps.h" double gettime(void) @@ -29,7 +30,7 @@ gettime(void) if (gettimeofday(&tv, NULL) == -1) fatal("gettimeofday"); - return (tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec); + return (tick2utc(tv.tv_sec) + JAN_1970 + 1.0e-6 * tv.tv_usec); }