summaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorDan Theisen <djt@hxx.in>2018-06-26 04:28:07 -0700
committerDan Theisen <djt@hxx.in>2018-06-26 18:44:39 -0700
commitb00cda0fc4fbeb6c64801e8180c2a2feeb288766 (patch)
tree8f376def6b56eebebfbefb2208118925b4001622 /user
parent586c518d3cdca10f7c83ca73efd2a41a1f295d4a (diff)
downloadpackages-b00cda0fc4fbeb6c64801e8180c2a2feeb288766.tar.gz
packages-b00cda0fc4fbeb6c64801e8180c2a2feeb288766.tar.bz2
packages-b00cda0fc4fbeb6c64801e8180c2a2feeb288766.tar.xz
packages-b00cda0fc4fbeb6c64801e8180c2a2feeb288766.zip
user/chrony: new package, import from alpine, clean up
Diffstat (limited to 'user')
-rw-r--r--user/chrony/APKBUILD99
-rw-r--r--user/chrony/chrony.conf10
-rw-r--r--user/chrony/chrony.logrotate12
-rw-r--r--user/chrony/chrony.pre-install6
l---------user/chrony/chrony.pre-upgrade1
-rw-r--r--user/chrony/chronyd.confd15
-rw-r--r--user/chrony/chronyd.initd71
-rw-r--r--user/chrony/fix-tests.patch12
-rw-r--r--user/chrony/max_resolve_interval.patch13
-rw-r--r--user/chrony/timepps.h216
10 files changed, 455 insertions, 0 deletions
diff --git a/user/chrony/APKBUILD b/user/chrony/APKBUILD
new file mode 100644
index 000000000..494b70946
--- /dev/null
+++ b/user/chrony/APKBUILD
@@ -0,0 +1,99 @@
+# Contributor: Łukasz Jendrysik
+# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
+# Contributor: Natanael Copa <ncopa@alpinelinux.org>
+# Maintainer: Dan Theisen <djt@hxx.in>
+pkgname=chrony
+pkgver=3.3
+pkgrel=0
+_ver=${pkgver/_/-}
+pkgdesc="NTP client and server programs"
+url="https://chrony.tuxfamily.org"
+pkgusers="$pkgname"
+pkggroups="$pkgname"
+arch="all"
+license="GPL-2.0-only"
+install="$pkgname.pre-install $pkgname.pre-upgrade"
+depends=""
+makedepends="asciidoctor libcap-dev texinfo"
+checkdepends="bash"
+subpackages="$pkgname-doc $pkgname-openrc"
+source="https://download.tuxfamily.org/$pkgname/$pkgname-$_ver.tar.gz
+ fix-tests.patch
+ max_resolve_interval.patch
+ chronyd.confd
+ chronyd.initd
+ chrony.logrotate
+ chrony.conf
+ timepps.h
+ "
+builddir="$srcdir/$pkgname-$_ver"
+
+prepare() {
+ default_prepare
+
+ # We copy timepps.h to the local build directory instead of
+ # creating a pps-tools-dev package for ppstime.h
+ # (See https://github.com/ago/pps-tools)
+ #
+ # Adelie TODO: This is originally an Alpine hack, however it looks like
+ # the pps-tools upstream is currently dead, we should determine if this
+ # is the right solution going forward.
+ mkdir -p pps-tools/sys
+ cp "$srcdir"/timepps.h pps-tools/sys/
+}
+
+build() {
+ cd "$builddir"
+ CPPFLAGS="$CPPFLAGS -I./pps-tools/" ./configure \
+ --prefix=/usr \
+ --infodir=/usr/share/info \
+ --mandir=/usr/share/man \
+ --sysconfdir=/etc/$pkgname \
+ --disable-readline \
+ --with-user=$pkgname \
+ --with-sendmail=/usr/sbin/sendmail \
+ --enable-ntp-signd
+ make all docs
+}
+
+check() {
+ cd "$builddir"
+ make check
+}
+
+package() {
+ cd "$builddir"
+ make DESTDIR="$pkgdir" install
+
+ mkdir -p "$pkgdir"/etc/logrotate.d
+ install -Dm644 "$srcdir"/chrony.logrotate "$pkgdir"/etc/logrotate.d/chrony
+
+ mkdir -p "$pkgdir"/usr/share/doc/chrony
+ install -m644 examples/*.example "$pkgdir"/usr/share/doc/chrony/
+ install -Dm755 "$srcdir"/chronyd.initd "$pkgdir"/etc/init.d/chronyd
+ install -Dm644 "$srcdir"/chronyd.confd "$pkgdir"/etc/conf.d/chronyd
+
+ mkdir -p "$pkgdir"/var/lib/chrony \
+ "$pkgdir"/etc/chrony
+
+ # allow chrony to write logs, and wheel users to read them
+ install -dm2750 -o $pkgusers -g wheel "$pkgdir"/var/log/chrony
+
+ # chrony shouldn't be able to modify its own config
+ chown $pkgusers:$pkggroups "$pkgdir"/etc/chrony
+ install -m644 -o root -g root "$srcdir"/chrony.conf \
+ "$pkgdir"/etc/chrony/chrony.conf
+
+ # chrony.drift must be writable by chrony user
+ touch "$pkgdir"/var/lib/chrony/chrony.drift
+ chown -R $pkgusers:$pkggroups "$pkgdir"/var/lib/chrony
+}
+
+sha512sums="36975d863599141e8e5b071d35cf67326b27f5b0da7ec942dbb4530377d10472b0729eea632e0702718b515cb2d5fd41a7eba158e6dade7f05adfb1bdffa5df0 chrony-3.3.tar.gz
+067d47224a8c075ec8f63ffc58e65b030fdf228a72c4f03d50a2f2c17414da65bb5d27c7c2e4ba99e909f452041db83eaebe3c9e34c0c8fce18e05ebb489735e fix-tests.patch
+b26581ed32680585edea5b8163a0062a87f648394c0f363c77a7d01a36608fcf4d005d9e6ab179ed2827b8a08f598f7bad4801bb5e135cad5107eb77fb19b247 max_resolve_interval.patch
+1ebb72341b4421060a43d6db164d743de9144f1c23370e052f0db92a17e5e34f24ac98baddeb5dbfef27f67479142d448c4401d927394e55024760730a27e8de chronyd.confd
+9a18c9744d7b78d9b9be3f0ae0b43cb988b294c342764802e0d5df835d450e748584c0b345f7161f14d84e15c8bbd491514ee9dc45e4a65f1276c52124d2e312 chronyd.initd
+ab38f06bf45888846778ad935e24abb30d13b6805e9a750bc694ff953695fa8c5b33aac560f5f7f96dc46031c1a38660e5c418b6fce6fb34a87908a9a3c99357 chrony.logrotate
+e2699b8b023e3a4e3d1304296c605842669b9daa275927d8c12caf30dd859c53ab3dab4efe96f2572d70044234a1f352ef917668507d0e72de9f5cdc8fb37d1a chrony.conf
+eb11fc19243d1789016d88eb7645bfe67c46304547781489bf36eb1dd4c252d523681ff835a6488fa0ef62b6b9e2f781c672279f4439f5d5640a3f214a113048 timepps.h"
diff --git a/user/chrony/chrony.conf b/user/chrony/chrony.conf
new file mode 100644
index 000000000..e2d26cd62
--- /dev/null
+++ b/user/chrony/chrony.conf
@@ -0,0 +1,10 @@
+# default config
+# TODO: update pools to adelie vendor zone when it is assigned
+pool pool.ntp.org iburst
+initstepslew 10 pool.ntp.org
+driftfile /var/lib/chrony/chrony.drift
+rtcsync
+
+# check /etc/conf.d/chrony if you want daemon logs to go to syslog
+# this setting specifies where statistics go
+logdir /var/log/chrony
diff --git a/user/chrony/chrony.logrotate b/user/chrony/chrony.logrotate
new file mode 100644
index 000000000..4461a3063
--- /dev/null
+++ b/user/chrony/chrony.logrotate
@@ -0,0 +1,12 @@
+/var/log/chrony/*.log {
+ missingok
+ sharedscripts
+ postrotate
+ PASSWORD=`awk '$1 ~ /^1$/ {print $2; exit}' /etc/chrony/chrony.keys`
+ cat << EOF | /usr/bin/chronyc | sed '/^200 OK$/d'
+ password $PASSWORD
+ cyclelogs
+EOF
+ endscript
+}
+
diff --git a/user/chrony/chrony.pre-install b/user/chrony/chrony.pre-install
new file mode 100644
index 000000000..897fb74cc
--- /dev/null
+++ b/user/chrony/chrony.pre-install
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+addgroup -S chrony 2>/dev/null
+adduser -S -D -h /var/log/chrony -s /sbin/nologin -G chrony -g chrony chrony 2>/dev/null
+
+exit 0
diff --git a/user/chrony/chrony.pre-upgrade b/user/chrony/chrony.pre-upgrade
new file mode 120000
index 000000000..ff5c83698
--- /dev/null
+++ b/user/chrony/chrony.pre-upgrade
@@ -0,0 +1 @@
+chrony.pre-install \ No newline at end of file
diff --git a/user/chrony/chronyd.confd b/user/chrony/chronyd.confd
new file mode 100644
index 000000000..18bc673cf
--- /dev/null
+++ b/user/chrony/chronyd.confd
@@ -0,0 +1,15 @@
+# /etc/conf.d/chronyd
+
+CFGFILE="/etc/chrony/chrony.conf"
+
+# Configuration dependant options :
+# -s - Set system time from RTC if rtcfile directive present
+# -r - Reload sample histories if dumponexit directive present
+#
+# The combination of "-s -r" allows chronyd to perform long term averaging of
+# the gain or loss rate across system reboots and shutdowns.
+#
+# -l <file> - specifies a file which should be used for logging instead
+# of syslog or terminal
+
+ARGS="-l /var/log/chrony/daemon.log"
diff --git a/user/chrony/chronyd.initd b/user/chrony/chronyd.initd
new file mode 100644
index 000000000..771bb5b53
--- /dev/null
+++ b/user/chrony/chronyd.initd
@@ -0,0 +1,71 @@
+#!/sbin/openrc-run
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/net-misc/chrony/files/chronyd.rc,v 1.8 2007/03/22 14:32:09 tove Exp $
+
+description="NTP daemon"
+
+depend() {
+ need net
+ after firewall
+ provide ntp-client ntp-server
+ use dns
+}
+
+checkconfig() {
+ # Note that /etc/chrony/chrony.keys is *NOT* checked. This
+ # is because the user may have specified another key
+ # file, and we don't want to force the user to use that
+ # exact name for the key file.
+ if [ ! -f "${CFGFILE}" ] ; then
+ eerror "Please create ${CFGFILE} and the"
+ eerror "chrony key file (usually /etc/chrony/chrony.keys)"
+ eerror "by using the"
+ eerror ""
+ eerror " chrony.conf.example"
+ eerror " chrony.keys.example"
+ eerror ""
+ eerror "files (from the documentation directory)"
+ eerror "as templates."
+ return 1
+ else
+ # Actually, I tried it, and chrony seems to ignore the pidfile
+ # option. I'm going to leave it here anyway, since you never
+ # know if it might be handy
+ PIDFILE=`awk '/^ *pidfile/{print $2}' "${CFGFILE}"`
+ fi
+ return 0
+}
+
+setxtrarg() {
+ if [ -c /dev/rtc ]; then
+ grep -q '^rtcfile' "${CFGFILE}" && ARGS="${ARGS} -s"
+ fi
+ grep -q '^dumponexit$' "${CFGFILE}" && ARGS="${ARGS} -r"
+ return 0
+}
+
+start() {
+ checkconfig || return $?
+ setxtrarg
+
+ [ -n "${PIDFILE}" ] || PIDFILE=/var/run/chronyd.pid
+
+ ebegin "Starting chronyd"
+ start-stop-daemon --start --quiet \
+ --exec /usr/sbin/chronyd \
+ --pidfile "${PIDFILE}" \
+ -- -f "${CFGFILE}" ${ARGS}
+ eend $? "Failed to start chronyd"
+}
+
+stop() {
+ checkconfig || return $?
+
+ [ -n "${PIDFILE}" ] || PIDFILE=/var/run/chronyd.pid
+
+ ebegin "Stopping chronyd"
+ start-stop-daemon --stop --quiet \
+ --pidfile "${PIDFILE}"
+ eend $? "Failed to stop chronyd"
+}
diff --git a/user/chrony/fix-tests.patch b/user/chrony/fix-tests.patch
new file mode 100644
index 000000000..6291fb046
--- /dev/null
+++ b/user/chrony/fix-tests.patch
@@ -0,0 +1,12 @@
+diff -upr chrony-3.2.orig/test/unit/test.c chrony-3.2/test/unit/test.c
+--- chrony-3.2.orig/test/unit/test.c 2017-11-29 11:32:23.610059580 +0100
++++ chrony-3.2/test/unit/test.c 2017-11-29 11:32:51.213742887 +0100
+@@ -23,6 +23,8 @@
+ #include <logging.h>
+ #include <localp.h>
+
++#include <sys/param.h>
++
+ #include "test.h"
+
+ void
diff --git a/user/chrony/max_resolve_interval.patch b/user/chrony/max_resolve_interval.patch
new file mode 100644
index 000000000..6343d9122
--- /dev/null
+++ b/user/chrony/max_resolve_interval.patch
@@ -0,0 +1,13 @@
+Try fix behaviour when network is not available at bootup
+
+--- ./ntp_sources.c.orig
++++ ./ntp_sources.c
+@@ -87,7 +85,7 @@
+
+ #define RESOLVE_INTERVAL_UNIT 7
+ #define MIN_RESOLVE_INTERVAL 2
+-#define MAX_RESOLVE_INTERVAL 9
++#define MAX_RESOLVE_INTERVAL 6
+ #define MIN_REPLACEMENT_INTERVAL 8
+
+ static struct UnresolvedSource *unresolved_sources = NULL;
diff --git a/user/chrony/timepps.h b/user/chrony/timepps.h
new file mode 100644
index 000000000..8c3bd835d
--- /dev/null
+++ b/user/chrony/timepps.h
@@ -0,0 +1,216 @@
+/*
+ * timepps.h -- PPS API main header
+ *
+ * Copyright (C) 2005-2007 Rodolfo Giometti <giometti@linux.it>
+ * Copyright (C) 2009-2011 Alexander Gordeev <alex@gordick.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Source: https://github.com/ago/pps-tools/ - Retreived Dec 2013
+ */
+
+#ifndef _SYS_TIMEPPS_H_
+#define _SYS_TIMEPPS_H_
+
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <linux/types.h>
+#include <linux/pps.h>
+
+#define LINUXPPS 1 /* signal we are using LinuxPPS */
+
+/*
+ * New data structures
+ */
+
+struct ntp_fp {
+ unsigned int integral;
+ unsigned int fractional;
+};
+
+union pps_timeu {
+ struct timespec tspec;
+ struct ntp_fp ntpfp;
+ unsigned long longpad[3];
+};
+
+struct pps_info {
+ unsigned long assert_sequence; /* seq. num. of assert event */
+ unsigned long clear_sequence; /* seq. num. of clear event */
+ union pps_timeu assert_tu; /* time of assert event */
+ union pps_timeu clear_tu; /* time of clear event */
+ int current_mode; /* current mode bits */
+};
+
+struct pps_params {
+ int api_version; /* API version # */
+ int mode; /* mode bits */
+ union pps_timeu assert_off_tu; /* offset compensation for assert */
+ union pps_timeu clear_off_tu; /* offset compensation for clear */
+};
+
+typedef int pps_handle_t; /* represents a PPS source */
+typedef unsigned long pps_seq_t; /* sequence number */
+typedef struct ntp_fp ntp_fp_t; /* NTP-compatible time stamp */
+typedef union pps_timeu pps_timeu_t; /* generic data type for time stamps */
+typedef struct pps_info pps_info_t;
+typedef struct pps_params pps_params_t;
+
+#define assert_timestamp assert_tu.tspec
+#define clear_timestamp clear_tu.tspec
+
+#define assert_timestamp_ntpfp assert_tu.ntpfp
+#define clear_timestamp_ntpfp clear_tu.ntpfp
+
+#define assert_offset assert_off_tu.tspec
+#define clear_offset clear_off_tu.tspec
+
+#define assert_offset_ntpfp assert_off_tu.ntpfp
+#define clear_offset_ntpfp clear_off_tu.ntpfp
+
+/*
+ * The PPS API
+ */
+
+static __inline int time_pps_create(int source, pps_handle_t *handle)
+{
+ int ret;
+ struct pps_kparams dummy;
+
+ if (!handle) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* First we check if current device is a valid PPS one by
+ * doing a dummy PPS_GETPARAMS...
+ */
+ ret = ioctl(source, PPS_GETPARAMS, &dummy);
+ if (ret) {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
+
+ /* ... then since in LinuxPPS there are no differences between a
+ * "PPS source" and a "PPS handle", we simply return the same value.
+ */
+ *handle = source;
+
+ return 0;
+}
+
+static __inline int time_pps_destroy(pps_handle_t handle)
+{
+ return close(handle);
+}
+
+static __inline int time_pps_getparams(pps_handle_t handle,
+ pps_params_t *ppsparams)
+{
+ int ret;
+ struct pps_kparams __ppsparams;
+
+ ret = ioctl(handle, PPS_GETPARAMS, &__ppsparams);
+
+ ppsparams->api_version = __ppsparams.api_version;
+ ppsparams->mode = __ppsparams.mode;
+ ppsparams->assert_off_tu.tspec.tv_sec = __ppsparams.assert_off_tu.sec;
+ ppsparams->assert_off_tu.tspec.tv_nsec = __ppsparams.assert_off_tu.nsec;
+ ppsparams->clear_off_tu.tspec.tv_sec = __ppsparams.clear_off_tu.sec;
+ ppsparams->clear_off_tu.tspec.tv_nsec = __ppsparams.clear_off_tu.nsec;
+
+ return ret;
+}
+
+static __inline int time_pps_setparams(pps_handle_t handle,
+ const pps_params_t *ppsparams)
+{
+ struct pps_kparams __ppsparams;
+
+ __ppsparams.api_version = ppsparams->api_version;
+ __ppsparams.mode = ppsparams->mode;
+ __ppsparams.assert_off_tu.sec = ppsparams->assert_off_tu.tspec.tv_sec;
+ __ppsparams.assert_off_tu.nsec = ppsparams->assert_off_tu.tspec.tv_nsec;
+ __ppsparams.clear_off_tu.sec = ppsparams->clear_off_tu.tspec.tv_sec;
+ __ppsparams.clear_off_tu.nsec = ppsparams->clear_off_tu.tspec.tv_nsec;
+
+ return ioctl(handle, PPS_SETPARAMS, &__ppsparams);
+}
+
+/* Get capabilities for handle */
+static __inline int time_pps_getcap(pps_handle_t handle, int *mode)
+{
+ return ioctl(handle, PPS_GETCAP, mode);
+}
+
+static __inline int time_pps_fetch(pps_handle_t handle, const int tsformat,
+ pps_info_t *ppsinfobuf,
+ const struct timespec *timeout)
+{
+ struct pps_fdata __fdata;
+ int ret;
+
+ /* Sanity checks */
+ if (tsformat != PPS_TSFMT_TSPEC) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (timeout) {
+ __fdata.timeout.sec = timeout->tv_sec;
+ __fdata.timeout.nsec = timeout->tv_nsec;
+ __fdata.timeout.flags = ~PPS_TIME_INVALID;
+ } else
+ __fdata.timeout.flags = PPS_TIME_INVALID;
+
+ ret = ioctl(handle, PPS_FETCH, &__fdata);
+
+ ppsinfobuf->assert_sequence = __fdata.info.assert_sequence;
+ ppsinfobuf->clear_sequence = __fdata.info.clear_sequence;
+ ppsinfobuf->assert_tu.tspec.tv_sec = __fdata.info.assert_tu.sec;
+ ppsinfobuf->assert_tu.tspec.tv_nsec = __fdata.info.assert_tu.nsec;
+ ppsinfobuf->clear_tu.tspec.tv_sec = __fdata.info.clear_tu.sec;
+ ppsinfobuf->clear_tu.tspec.tv_nsec = __fdata.info.clear_tu.nsec;
+ ppsinfobuf->current_mode = __fdata.info.current_mode;
+
+ return ret;
+}
+
+#ifdef PPS_KC_BIND
+
+static __inline int time_pps_kcbind(pps_handle_t handle,
+ const int kernel_consumer,
+ const int edge, const int tsformat)
+{
+ struct pps_bind_args __bind_args;
+
+ __bind_args.tsformat = tsformat;
+ __bind_args.edge = edge;
+ __bind_args.consumer = kernel_consumer;
+
+ return ioctl(handle, PPS_KC_BIND, &__bind_args);
+}
+
+#else /* !PPS_KC_BIND */
+
+static __inline int time_pps_kcbind(pps_handle_t handle,
+ const int kernel_consumer,
+ const int edge, const int tsformat)
+{
+ /* LinuxPPS doesn't implement kernel consumer feature */
+ errno = EOPNOTSUPP;
+ return -1;
+}
+
+#endif /* PPS_KC_BIND */
+
+#endif /* _SYS_TIMEPPS_H_ */