net-misc/omnisync: fix bugs, allow multiple instances
authorRobin H. Johnson <robbat2@gentoo.org>
Fri, 1 Jun 2018 21:48:45 +0000 (14:48 -0700)
committerRobin H. Johnson <robbat2@gentoo.org>
Fri, 1 Jun 2018 21:51:46 +0000 (14:51 -0700)
Code bugs:
- Fix --help display
- Raise SHM unit limit
- getopt loop failed to apply stats_file setting.

Init improvement:
- allow multiple instances.
- write pidfile
- declare that we use DNS (in case it starts before local resolver)

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Package-Manager: Portage-2.3.33, Repoman-2.3.9

net-misc/omnisync/files/omnisync-1.0-help.patch [new file with mode: 0644]
net-misc/omnisync/files/omnisync-1.0-maxshm.patch [new file with mode: 0644]
net-misc/omnisync/files/omnisync-1.0-statfile.patch [new file with mode: 0644]
net-misc/omnisync/files/omnisync.initd
net-misc/omnisync/omnisync-1.0-r1.ebuild [new file with mode: 0644]

diff --git a/net-misc/omnisync/files/omnisync-1.0-help.patch b/net-misc/omnisync/files/omnisync-1.0-help.patch
new file mode 100644 (file)
index 0000000..47ff520
--- /dev/null
@@ -0,0 +1,16 @@
+main: fix help missing newline
+
+Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
+
+diff -Nuar --exclude '*~' omnisync-1.0.orig/main.c omnisync-1.0/main.c
+--- omnisync-1.0.orig/main.c   2009-01-02 01:03:20.000000000 -0800
++++ omnisync-1.0/main.c        2018-06-01 14:31:25.720686155 -0700
+@@ -139,7 +139,7 @@
+       printf("-c x   community (snmp only)\n");
+       printf("-h x   host to connect to\n");
+       printf("-u x   ntpd shared memory unit\n");
+-      printf("-z x   do an initial step, to speed up syncing, parameter is number of samples");
++      printf("-z x   do an initial step, to speed up syncing, parameter is number of samples\n");
+       printf("-S x   write measurements to file x\n");
+       printf("-n     do NOT submit to NTPd/set clock, query only (use in combination with -v and -f)\n");
+       printf("-f     do not fork\n");
diff --git a/net-misc/omnisync/files/omnisync-1.0-maxshm.patch b/net-misc/omnisync/files/omnisync-1.0-maxshm.patch
new file mode 100644 (file)
index 0000000..678c6e0
--- /dev/null
@@ -0,0 +1,18 @@
+main: raise SHM unit limit
+
+Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
+
+diff -Nuar --exclude '*~' omnisync-1.0.orig/main.c omnisync-1.0/main.c
+--- omnisync-1.0.orig/main.c   2009-01-02 01:03:20.000000000 -0800
++++ omnisync-1.0/main.c        2018-06-01 14:32:34.630066839 -0700
+@@ -346,8 +346,8 @@
+                               unit_nr = atoi(optarg);
+                               if (unit_nr < 0)
+                                       error_exit("-u requires a positive value\n");
+-                              if (unit_nr > 3)
+-                                      error_exit("NTPd normally supports only 4 shared memory devices, still continuing though\n");
++                              if (unit_nr > 254)
++                                      error_exit("NTPd normally supports only 254 shared memory devices\n");
+                               break;
+                       case 'v':
diff --git a/net-misc/omnisync/files/omnisync-1.0-statfile.patch b/net-misc/omnisync/files/omnisync-1.0-statfile.patch
new file mode 100644 (file)
index 0000000..972316a
--- /dev/null
@@ -0,0 +1,18 @@
+main: wire up stats_file variable
+
+Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
+
+diff -Nuar --exclude '*~' omnisync-1.0.orig/main.c omnisync-1.0/main.c
+--- omnisync-1.0.orig/main.c   2009-01-02 01:03:20.000000000 -0800
++++ omnisync-1.0/main.c        2018-06-01 14:39:22.115229735 -0700
+@@ -358,6 +358,10 @@
+                               version();
+                               return 0;
++                      case 'S':
++                              stats_file = optarg;
++                              break;
++
+                       default:
+                               help();
+                               return 1;
index 7820af6e94e3a7cedeb22060340182117a2da617..c71e63d4d3e38c0e6a18ee1419de83d6b6636a56 100644 (file)
@@ -3,11 +3,18 @@
 # Distributed under the terms of the GNU General Public License v2
 
 depend() {
-       use net
+       use net dns
 }
 
+INSTANCE=${SVCNAME#*.}
+if [ -n "${INSTANCE}" ] && [ ${SVCNAME} != "omnisync" ]; then
+    pidfile="/var/run/omnisync.${INSTANCE}.pid"
+else
+    pidfile="/var/run/omnisync.pid"
+fi
+
 command="/usr/sbin/omnisync"
-command_args="-M ${OMNISYNC_MODE} ${OMNISYNC_ARGS}"
+command_args="-P ${pidfile} -M ${OMNISYNC_MODE} ${OMNISYNC_ARGS}"
 
 start_pre() {
        if [ -z "${OMNISYNC_MODE}" ] ; then
diff --git a/net-misc/omnisync/omnisync-1.0-r1.ebuild b/net-misc/omnisync/omnisync-1.0-r1.ebuild
new file mode 100644 (file)
index 0000000..5875550
--- /dev/null
@@ -0,0 +1,48 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+inherit toolchain-funcs
+
+DESCRIPTION="A driver for NTPd for people who are firewall-challenged"
+HOMEPAGE="https://www.vanheusden.com/time/omnisync"
+LICENSE="GPL-2"
+SRC_URI="https://www.vanheusden.com/time/${PN}/${P}.tgz"
+
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE="debug"
+
+RDEPEND="dev-libs/openssl:0= net-analyzer/net-snmp:="
+DEPEND="${RDEPEND}"
+DOCS=( readme.txt Changes )
+PATCHES=(
+       "${FILESDIR}"/omnisync-1.0-help.patch
+       "${FILESDIR}"/omnisync-1.0-maxshm.patch
+       "${FILESDIR}"/omnisync-1.0-statfile.patch
+)
+
+src_prepare() {
+       default
+       tc-export CC
+       sed -i \
+               -e 's/-O2 -Wall/-Wall/' \
+               -e 's/-lsnmp/-lnetsnmp/' \
+               "${S%/}/Makefile" || die
+       use debug ||  sed -i -e 's/$(DEBUG)//' "${S%/}/Makefile" || die
+}
+
+src_install() {
+       dosbin omnisync
+       newinitd "${FILESDIR%/}/${PN}.initd" ${PN}
+       newconfd "${FILESDIR%/}/${PN}.confd" ${PN}
+       einstalldocs
+}
+
+pkg_postinst() {
+       local isConfigured=$(grep 'OMNISYNC_MODE=""' "${ROOT%/}/etc/conf.d/${PN}")
+       if [[ -n "${isConfigured}" ]] ; then
+               elog "Be sure to configure ${PN} in ${ROOT%/}/etc/conf.d before trying to start the service"
+       fi
+}