Browse Source

reorganize and incorporate debian and gentoo patches

This reworks a few of the common patches on Debian and Gentoo to be a
little nicer, and changes the patches to be per-fix rather than
per-file.
OPENBSD_5_7
Brent Cook 9 years ago
parent
commit
ac6aa84996
21 changed files with 657 additions and 221 deletions
  1. +40
    -0
      patches/0001-include-time.h-for-clock_gettime.patch
  2. +47
    -0
      patches/0002-removed-unused-libevent-header-and-structures.patch
  3. +38
    -0
      patches/0003-Use-LOG_NTP-syslog-facility.patch
  4. +34
    -0
      patches/0004-remove-unused-dns_pid.patch
  5. +21
    -22
      patches/0005-conditionally-fill-in-sin_len-sin6_len-if-they-exist.patch
  6. +34
    -0
      patches/0006-EAI_NODATA-does-not-exist-everywhere.patch
  7. +116
    -0
      patches/0007-check-if-rdomain-support-is-available.patch
  8. +40
    -0
      patches/0008-Handle-IPv6-DNS-records-on-IPv4-networks-more-libera.patch
  9. +53
    -0
      patches/0009-update-ntpd.conf-to-indicate-OS-dependent-options.patch
  10. +150
    -0
      patches/0010-add-p-option-to-create-a-pid-file.patch
  11. +45
    -0
      patches/0011-Fix-DNS-timeout-lookup.patch
  12. +34
    -0
      patches/0012-don-t-be-too-stingy-on-braces.patch
  13. +0
    -28
      patches/patch-client.c
  14. +0
    -23
      patches/patch-log.c
  15. +0
    -20
      patches/patch-ntp.c
  16. +0
    -10
      patches/patch-ntpd.c
  17. +0
    -33
      patches/patch-ntpd.h
  18. +0
    -15
      patches/patch-parse.y
  19. +0
    -53
      patches/patch-server.c
  20. +0
    -13
      patches/patch-util.c
  21. +5
    -4
      update.sh

+ 40
- 0
patches/0001-include-time.h-for-clock_gettime.patch View File

@ -0,0 +1,40 @@
From 53006c85af7c8b69afa3847e12107588c1460c5a Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 08:58:26 -0600
Subject: [PATCH 01/12] include time.h for clock_gettime
---
src/usr.sbin/ntpd/ntpd.c | 1 +
src/usr.sbin/ntpd/util.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c
index 4634fae..17ebf67 100644
--- a/src/usr.sbin/ntpd/ntpd.c
+++ b/src/usr.sbin/ntpd/ntpd.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <err.h>
diff --git a/src/usr.sbin/ntpd/util.c b/src/usr.sbin/ntpd/util.c
index 9d78d6e..638dc92 100644
--- a/src/usr.sbin/ntpd/util.c
+++ b/src/usr.sbin/ntpd/util.c
@@ -17,8 +17,10 @@
*/
#include <sys/time.h>
+
#include <limits.h>
#include <stdio.h>
+#include <time.h>
#include "ntpd.h"
--
1.9.1

+ 47
- 0
patches/0002-removed-unused-libevent-header-and-structures.patch View File

@ -0,0 +1,47 @@
From da6f7a99e25c9fa0fca75576eaf29f0e8fe67441 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 08:59:19 -0600
Subject: [PATCH 02/12] removed unused libevent header and structures
---
src/usr.sbin/ntpd/ntpd.h | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h
index 8095be3..aa9858b 100644
--- a/src/usr.sbin/ntpd/ntpd.h
+++ b/src/usr.sbin/ntpd/ntpd.h
@@ -28,7 +28,6 @@
#include <netdb.h>
#include <pwd.h>
#include <stdarg.h>
-#include <event.h>
#include <poll.h>
#include "ntp.h"
@@ -190,14 +189,6 @@ struct ntpd_conf {
u_int8_t filters;
};
-struct imsgev {
- struct imsgbuf ibuf;
- void (*handler)(int, short, void *);
- struct event ev;
- void *data;
- short events;
-};
-
struct ctl_show_status {
u_int peercnt;
u_int sensorcnt;
@@ -240,7 +231,6 @@ enum blockmodes {
struct ctl_conn {
TAILQ_ENTRY(ctl_conn) entry;
- struct imsgev iev;
struct imsgbuf ibuf;
};
--
1.9.1

+ 38
- 0
patches/0003-Use-LOG_NTP-syslog-facility.patch View File

@ -0,0 +1,38 @@
From 20911c235ab4af36242a9b913bc41a3b1b0958cb Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:00:12 -0600
Subject: [PATCH 03/12] Use LOG_NTP syslog facility.
FreeBSD PR: 114191
Submitted by: Robert Archer <freebsd@deathbeforedecaf.net>
---
src/usr.sbin/ntpd/log.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/usr.sbin/ntpd/log.c b/src/usr.sbin/ntpd/log.c
index 618f4cc..32575e8 100644
--- a/src/usr.sbin/ntpd/log.c
+++ b/src/usr.sbin/ntpd/log.c
@@ -26,6 +26,10 @@
#include "ntpd.h"
+#ifndef LOG_NTP
+#define LOG_NTP LOG_DAEMON
+#endif
+
int debug;
extern int debugsyslog;
@@ -37,7 +41,7 @@ log_init(int n_debug)
debug = n_debug;
if (!debug)
- openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
+ openlog(__progname, LOG_PID | LOG_NDELAY, LOG_NTP);
tzset();
}
--
1.9.1

+ 34
- 0
patches/0004-remove-unused-dns_pid.patch View File

@ -0,0 +1,34 @@
From f67a51ea7b11f1082dac77beb632f4d71f397584 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:01:57 -0600
Subject: [PATCH 04/12] remove unused dns_pid
---
src/usr.sbin/ntpd/ntp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c
index 2eb4285..ddbcedd 100644
--- a/src/usr.sbin/ntpd/ntp.c
+++ b/src/usr.sbin/ntpd/ntp.c
@@ -79,7 +79,7 @@ ntp_main(int pipe_prnt[2], int fd_ctl, struct ntpd_conf *nconf,
u_int pfd_elms = 0, idx2peer_elms = 0;
u_int listener_cnt, new_cnt, sent_cnt, trial_cnt;
u_int ctl_cnt;
- pid_t pid, dns_pid;
+ pid_t pid;
struct pollfd *pfd = NULL;
struct servent *se;
struct listen_addr *la;
@@ -118,7 +118,7 @@ ntp_main(int pipe_prnt[2], int fd_ctl, struct ntpd_conf *nconf,
close(pipe_prnt[0]);
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_dns) == -1)
fatal("socketpair");
- dns_pid = ntp_dns(pipe_dns, nconf, pw);
+ ntp_dns(pipe_dns, nconf, pw);
close(pipe_dns[1]);
if (stat(pw->pw_dir, &stb) == -1)
--
1.9.1

patches/patch-config.c → patches/0005-conditionally-fill-in-sin_len-sin6_len-if-they-exist.patch View File

@ -1,6 +1,19 @@
--- config.orig Sun Dec 28 20:17:46 2014
+++ config.c Sun Dec 28 20:19:48 2014
@@ -75,7 +75,9 @@
From e73468f4e08442681c79e84edc62cf8e9f3b733a Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:02:50 -0600
Subject: [PATCH 05/12] conditionally fill in sin_len/sin6_len if they exist
Should we even be setting these at all? Does anything really rely in
this anymore?
---
src/usr.sbin/ntpd/config.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/usr.sbin/ntpd/config.c b/src/usr.sbin/ntpd/config.c
index d660750..b651c62 100644
--- a/src/usr.sbin/ntpd/config.c
+++ b/src/usr.sbin/ntpd/config.c
@@ -75,7 +75,9 @@ host_v4(const char *s)
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
fatal(NULL);
sa_in = (struct sockaddr_in *)&h->ss;
@ -10,7 +23,7 @@
sa_in->sin_family = AF_INET;
sa_in->sin_addr.s_addr = ina.s_addr;
@@ -97,7 +99,9 @@
@@ -97,7 +99,9 @@ host_v6(const char *s)
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
fatal(NULL);
sa_in6 = (struct sockaddr_in6 *)&h->ss;
@ -20,24 +33,7 @@
sa_in6->sin6_family = AF_INET6;
memcpy(&sa_in6->sin6_addr,
&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
@@ -124,8 +128,14 @@
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM; /* DUMMY */
error = getaddrinfo(s, NULL, &hints, &res0);
- if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME)
- return (0);
+ switch (error) {
+ case EAI_AGAIN:
+#ifdef EAI_NODATA
+ case EAI_NODATA:
+#endif
+ case EAI_NONAME:
+ return (0);
+ }
if (error) {
log_warnx("could not parse \"%s\": %s", s,
gai_strerror(error));
@@ -141,12 +151,16 @@
@@ -141,12 +145,16 @@ host_dns(const char *s, struct ntp_addr **hn)
h->ss.ss_family = res->ai_family;
if (res->ai_family == AF_INET) {
sa_in = (struct sockaddr_in *)&h->ss;
@ -54,3 +50,6 @@
memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
}
--
1.9.1

+ 34
- 0
patches/0006-EAI_NODATA-does-not-exist-everywhere.patch View File

@ -0,0 +1,34 @@
From 447c73c470e1157036d8cfc3d3328a5ba48655f3 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:04:08 -0600
Subject: [PATCH 06/12] EAI_NODATA does not exist everywhere
FreeBSD says it is deprecated and should be removed.
---
src/usr.sbin/ntpd/config.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/usr.sbin/ntpd/config.c b/src/usr.sbin/ntpd/config.c
index b651c62..9fa4c17 100644
--- a/src/usr.sbin/ntpd/config.c
+++ b/src/usr.sbin/ntpd/config.c
@@ -128,8 +128,14 @@ host_dns(const char *s, struct ntp_addr **hn)
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM; /* DUMMY */
error = getaddrinfo(s, NULL, &hints, &res0);
- if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME)
- return (0);
+ switch (error) {
+ case EAI_AGAIN:
+#ifdef EAI_NODATA
+ case EAI_NODATA:
+#endif
+ case EAI_NONAME:
+ return (0);
+ }
if (error) {
log_warnx("could not parse \"%s\": %s", s,
gai_strerror(error));
--
1.9.1

+ 116
- 0
patches/0007-check-if-rdomain-support-is-available.patch View File

@ -0,0 +1,116 @@
From 0ec5710f4872d4feb8ff96b61d4d4a7ca0fa7b09 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:05:46 -0600
Subject: [PATCH 07/12] check if rdomain support is available
---
src/usr.sbin/ntpd/client.c | 4 ++++
src/usr.sbin/ntpd/parse.y | 2 ++
src/usr.sbin/ntpd/server.c | 11 ++++++++++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
index e59112a..9b9b522 100644
--- a/src/usr.sbin/ntpd/client.c
+++ b/src/usr.sbin/ntpd/client.c
@@ -142,10 +142,12 @@ client_query(struct ntp_peer *p)
0)) == -1)
fatal("client_query socket");
+#ifdef SO_RTABLE
if (p->rtable != -1 &&
setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE,
&p->rtable, sizeof(p->rtable)) == -1)
fatal("client_query setsockopt SO_RTABLE");
+#endif
if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
if (errno == ECONNREFUSED || errno == ENETUNREACH ||
errno == EHOSTUNREACH || errno == EADDRNOTAVAIL) {
@@ -248,10 +250,12 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
return (0);
}
+#ifdef SO_RTABLE
if (p->rtable != -1 &&
setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE, &p->rtable,
sizeof(p->rtable)) == -1)
fatal("client_dispatch setsockopt SO_RTABLE");
+#endif
for (cmsg = CMSG_FIRSTHDR(&somsg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&somsg, cmsg)) {
diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
index fb6e2f1..3f4065f 100644
--- a/src/usr.sbin/ntpd/parse.y
+++ b/src/usr.sbin/ntpd/parse.y
@@ -313,10 +313,12 @@ weight : WEIGHT NUMBER {
opts.weight = $2;
}
rtable : RTABLE NUMBER {
+#ifdef RT_TABLEID_MAX
if ($2 < 0 || $2 > RT_TABLEID_MAX) {
yyerror("rtable must be between 1 and RT_TABLEID_MAX");
YYERROR;
}
+#endif
opts.rtable = $2;
}
;
diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c
index 2dbb01f..3c74c24 100644
--- a/src/usr.sbin/ntpd/server.c
+++ b/src/usr.sbin/ntpd/server.c
@@ -39,7 +39,10 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
u_int8_t *a6;
size_t sa6len = sizeof(struct in6_addr);
u_int new_cnt = 0;
- int tos = IPTOS_LOWDELAY, rdomain, fd;
+ int tos = IPTOS_LOWDELAY;
+#ifdef SO_RTABLE
+ int rdomain, fd;
+#endif
TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
switch (lap->sa.ss_family) {
@@ -59,6 +62,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
strlcpy(ifr.ifr_name, ifap->ifa_name,
sizeof(ifr.ifr_name));
+#ifdef SO_RTABLE
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (ioctl(fd, SIOCGIFRDOMAIN,
(caddr_t)&ifr) == -1)
@@ -69,6 +73,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
if (lap->rtable != -1 && rdomain != lap->rtable)
continue;
+#endif
if (sa->sa_family == AF_INET &&
((struct sockaddr_in *)sa)->sin_addr.s_addr ==
@@ -87,7 +92,9 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
fatal("setup_listeners calloc");
memcpy(&la->sa, sa, SA_LEN(sa));
+#ifdef SO_RTABLE
la->rtable = rdomain;
+#endif
TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
}
@@ -132,10 +139,12 @@ setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
log_warn("setsockopt IPTOS_LOWDELAY");
+#ifdef SO_RTABLE
if (la->rtable != -1 &&
setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
sizeof(la->rtable)) == -1)
fatal("setup_listeners setsockopt SO_RTABLE");
+#endif
if (bind(la->fd, (struct sockaddr *)&la->sa,
SA_LEN((struct sockaddr *)&la->sa)) == -1) {
--
1.9.1

+ 40
- 0
patches/0008-Handle-IPv6-DNS-records-on-IPv4-networks-more-libera.patch View File

@ -0,0 +1,40 @@
From c26c6628e7ea92d6f3f1c128db15da199787a1fd Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:10:22 -0600
Subject: [PATCH 08/12] Handle IPv6 DNS records on IPv4 networks more liberally
Rather than fail on IPv4 only networks when seeing an IPv6 DNS record,
just give a warning.
Debian bug ID: 500676.
Original Author: Stefan Praszalowicz <stefan.praszalowicz@avedya.com>
---
src/usr.sbin/ntpd/client.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
index 9b9b522..0271068 100644
--- a/src/usr.sbin/ntpd/client.c
+++ b/src/usr.sbin/ntpd/client.c
@@ -138,9 +138,15 @@ client_query(struct ntp_peer *p)
if (p->query->fd == -1) {
struct sockaddr *sa = (struct sockaddr *)&p->addr->ss;
- if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM,
- 0)) == -1)
- fatal("client_query socket");
+ p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0);
+ if (p->query->fd == -1)
+ if (errno == EAFNOSUPPORT) {
+ log_warn("client_query socket");
+ client_nextaddr(p);
+ set_next(p, error_interval());
+ return (-1);
+ } else
+ fatal("client_query socket");
#ifdef SO_RTABLE
if (p->rtable != -1 &&
--
1.9.1

+ 53
- 0
patches/0009-update-ntpd.conf-to-indicate-OS-dependent-options.patch View File

@ -0,0 +1,53 @@
From 84100327370fec7ef44555c380e09e94b8a21c7c Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:20:03 -0600
Subject: [PATCH 09/12] update ntpd.conf to indicate OS-dependent options
Also, clarify listening behavior based on a patch from
Dererk <dererk@debian.org>
Debian bug ID: 575705
---
src/usr.sbin/ntpd/ntpd.conf.5 | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/usr.sbin/ntpd/ntpd.conf.5 b/src/usr.sbin/ntpd/ntpd.conf.5
index 3e9b5b4..6315f47 100644
--- a/src/usr.sbin/ntpd/ntpd.conf.5
+++ b/src/usr.sbin/ntpd/ntpd.conf.5
@@ -38,9 +38,14 @@ They are as follows:
.It Xo Ic listen on Ar address
.Op Ic rtable Ar table-id
.Xc
+.Xr ntpd 8
+has the ability to sync the local clock to remote NTP servers and, if
+this directive is specified, can act as NTP server itself, redistributing the
+local clock.
+.Pp
Specify a local IP address or a hostname the
.Xr ntpd 8
-daemon should listen on.
+daemon should listen on to enable remote clients synchronization.
If it appears multiple times,
.Xr ntpd 8
will listen on each given address.
@@ -53,7 +58,7 @@ will listen on all local addresses using the specified routing table.
does not listen on any address by default.
The optional
.Ic rtable
-keyword will specify which routing table to listen on.
+keyword will specify which routing table to listen on, if the operating system supports rdomains.
By default
.Xr ntpd 8
will listen using the current routing table.
@@ -76,7 +81,7 @@ listen on 127.0.0.1 rtable 4
.Xc
Specify a timedelta sensor device
.Xr ntpd 8
-should use.
+should use, if the operating system supports sensors.
The sensor can be specified multiple times:
.Xr ntpd 8
will use each given sensor that actually exists.
--
1.9.1

+ 150
- 0
patches/0010-add-p-option-to-create-a-pid-file.patch View File

@ -0,0 +1,150 @@
From 9a6c847be092266d0cc6d7d1010b614e1253ba65 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Wed, 31 Dec 2014 08:26:41 -0600
Subject: [PATCH 10/12] add -p option to create a pid file
This is used in both the Gentoo and Debian ports.
Origin: https://bugs.gentoo.org/show_bug.cgi?id=493082
---
src/usr.sbin/ntpd/ntpd.8 | 4 ++++
src/usr.sbin/ntpd/ntpd.c | 33 ++++++++++++++++++++++++++++-----
src/usr.sbin/ntpd/ntpd.h | 1 +
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/src/usr.sbin/ntpd/ntpd.8 b/src/usr.sbin/ntpd/ntpd.8
index 18b12e8..9eb1fee 100644
--- a/src/usr.sbin/ntpd/ntpd.8
+++ b/src/usr.sbin/ntpd/ntpd.8
@@ -25,6 +25,7 @@
.Bk -words
.Op Fl dnSsv
.Op Fl f Ar file
+.Op Fl p Ar file
.Ek
.Sh DESCRIPTION
The
@@ -56,6 +57,9 @@ instead of the default
.It Fl n
Configtest mode.
Only check the configuration file for validity.
+.It Fl p Ar file
+Write pid to
+.Ar file
.It Fl S
Do not set the time immediately at startup.
This is the default.
diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c
index 17ebf67..2d5809c 100644
--- a/src/usr.sbin/ntpd/ntpd.c
+++ b/src/usr.sbin/ntpd/ntpd.c
@@ -84,6 +84,18 @@ sighdlr(int sig)
}
}
+void
+writepid(struct ntpd_conf *lconf)
+{
+ if (lconf->pid_file != NULL) {
+ FILE *f = fopen(lconf->pid_file, "w");
+ if (f == NULL)
+ fatal("couldn't open pid file");
+ fprintf(f, "%ld\n", (long) getpid());
+ fclose(f);
+ }
+}
+
__dead void
usage(void)
{
@@ -92,7 +104,7 @@ usage(void)
if (strcmp(__progname, "ntpctl") == 0)
fprintf(stderr, "usage: ntpctl [-s all | peers | Sensors | status]\n");
else
- fprintf(stderr, "usage: %s [-dnSsv] [-f file]\n",
+ fprintf(stderr, "usage: %s [-dnSsv] [-f file] [-p file]\n",
__progname);
exit(1);
}
@@ -123,7 +135,7 @@ main(int argc, char *argv[])
log_init(1); /* log to stderr until daemonized */
- while ((ch = getopt(argc, argv, "df:nsSv")) != -1) {
+ while ((ch = getopt(argc, argv, "df:np:sSv")) != -1) {
switch (ch) {
case 'd':
lconf.debug = 1;
@@ -134,6 +146,9 @@ main(int argc, char *argv[])
case 'n':
lconf.noaction = 1;
break;
+ case 'p':
+ lconf.pid_file = optarg;
+ break;
case 's':
lconf.settime = 1;
break;
@@ -174,9 +189,11 @@ main(int argc, char *argv[])
reset_adjtime();
if (!lconf.settime) {
log_init(lconf.debug);
- if (!lconf.debug)
+ if (!lconf.debug) {
if (daemon(1, 0))
fatal("daemon");
+ writepid(&lconf);
+ }
} else
timeout = SETTIME_TIMEOUT * 1000;
@@ -223,9 +240,11 @@ main(int argc, char *argv[])
log_init(lconf.debug);
log_debug("no reply received in time, skipping initial "
"time setting");
- if (!lconf.debug)
+ if (!lconf.debug) {
if (daemon(1, 0))
fatal("daemon");
+ writepid(&lconf);
+ }
}
if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT))
@@ -264,6 +283,8 @@ main(int argc, char *argv[])
msgbuf_clear(&ibuf->w);
free(ibuf);
log_info("Terminating");
+ if (lconf.pid_file != NULL)
+ unlink(lconf.pid_file);
return (0);
}
@@ -339,9 +360,11 @@ dispatch_imsg(struct ntpd_conf *lconf)
memcpy(&d, imsg.data, sizeof(d));
ntpd_settime(d);
/* daemonize now */
- if (!lconf->debug)
+ if (!lconf->debug) {
if (daemon(1, 0))
fatal("daemon");
+ writepid(lconf);
+ }
lconf->settime = 0;
timeout = INFTIM;
break;
diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h
index aa9858b..f8d6382 100644
--- a/src/usr.sbin/ntpd/ntpd.h
+++ b/src/usr.sbin/ntpd/ntpd.h
@@ -187,6 +187,7 @@ struct ntpd_conf {
u_int8_t debug;
u_int8_t noaction;
u_int8_t filters;
+ char *pid_file;
};
struct ctl_show_status {
--
1.9.1

+ 45
- 0
patches/0011-Fix-DNS-timeout-lookup.patch View File

@ -0,0 +1,45 @@
From 6f091765d6ee996ad679868deb7f196c240c314e Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Wed, 31 Dec 2014 08:31:20 -0600
Subject: [PATCH 11/12] Fix DNS timeout lookup
Author: Paul B. Henson <henson@acm.org>
Origin: https://bugs.gentoo.org/show_bug.cgi?id=493358
---
src/usr.sbin/ntpd/ntpd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c
index 2d5809c..b45f4ca 100644
--- a/src/usr.sbin/ntpd/ntpd.c
+++ b/src/usr.sbin/ntpd/ntpd.c
@@ -123,6 +123,7 @@ main(int argc, char *argv[])
int pipe_chld[2];
struct passwd *pw;
extern char *__progname;
+ time_t start_time;
if (strcmp(__progname, "ntpctl") == 0) {
ctl_main (argc, argv);
@@ -222,6 +223,8 @@ main(int argc, char *argv[])
fatal(NULL);
imsg_init(ibuf, pipe_chld[0]);
+ start_time = getmonotime();
+
while (quit == 0) {
pfd[PFD_PIPE].fd = ibuf->fd;
pfd[PFD_PIPE].events = POLLIN;
@@ -234,7 +237,8 @@ main(int argc, char *argv[])
quit = 1;
}
- if (nfds == 0 && lconf.settime) {
+ if (lconf.settime &&
+ (nfds == 0 || getmonotime() > start_time + SETTIME_TIMEOUT)) {
lconf.settime = 0;
timeout = INFTIM;
log_init(lconf.debug);
--
1.9.1

+ 34
- 0
patches/0012-don-t-be-too-stingy-on-braces.patch View File

@ -0,0 +1,34 @@
From 47a111a45a541316d7ff9d844362b901f24f41e1 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Wed, 31 Dec 2014 08:47:45 -0600
Subject: [PATCH 12/12] don't be too stingy on braces
Match if bracing of the block below it to improve readability.
---
src/usr.sbin/ntpd/client.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c
index 0271068..4bfbf90 100644
--- a/src/usr.sbin/ntpd/client.c
+++ b/src/usr.sbin/ntpd/client.c
@@ -139,7 +139,7 @@ client_query(struct ntp_peer *p)
struct sockaddr *sa = (struct sockaddr *)&p->addr->ss;
p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0);
- if (p->query->fd == -1)
+ if (p->query->fd == -1) {
if (errno == EAFNOSUPPORT) {
log_warn("client_query socket");
client_nextaddr(p);
@@ -147,6 +147,7 @@ client_query(struct ntp_peer *p)
return (-1);
} else
fatal("client_query socket");
+ }
#ifdef SO_RTABLE
if (p->rtable != -1 &&
--
1.9.1

+ 0
- 28
patches/patch-client.c View File

@ -1,28 +0,0 @@
--- client.orig 2014-12-28 11:10:23.875157132 -0600
+++ client.c 2014-12-28 11:12:46.095160215 -0600
@@ -142,10 +142,12 @@
0)) == -1)
fatal("client_query socket");
+#ifdef SO_RTABLE
if (p->rtable != -1 &&
setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE,
&p->rtable, sizeof(p->rtable)) == -1)
fatal("client_query setsockopt SO_RTABLE");
+#endif
if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
if (errno == ECONNREFUSED || errno == ENETUNREACH ||
errno == EHOSTUNREACH || errno == EADDRNOTAVAIL) {
@@ -248,10 +250,12 @@
return (0);
}
+#ifdef SO_RTABLE
if (p->rtable != -1 &&
setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE, &p->rtable,
sizeof(p->rtable)) == -1)
fatal("client_dispatch setsockopt SO_RTABLE");
+#endif
for (cmsg = CMSG_FIRSTHDR(&somsg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&somsg, cmsg)) {

+ 0
- 23
patches/patch-log.c View File

@ -1,23 +0,0 @@
$FreeBSD: head/net/openntpd/files/patch-log.c 340725 2014-01-22 17:40:44Z mat $
--- log.c.orig 2007-08-22 23:04:30.000000000 +0200
+++ log.c 2009-08-01 22:08:01.000000000 +0200
@@ -26,6 +26,10 @@
#include "ntpd.h"
+#ifndef LOG_NTP
+#define LOG_NTP LOG_DAEMON
+#endif
+
int debug;
extern int debugsyslog;
@@ -39,7 +43,7 @@ log_init(int n_debug)
debug = n_debug;
if (!debug)
- openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
+ openlog(__progname, LOG_PID | LOG_NDELAY, LOG_NTP);
tzset();
}

+ 0
- 20
patches/patch-ntp.c View File

@ -1,20 +0,0 @@
--- ntp.orig 2014-12-28 11:48:24.731206568 -0600
+++ ntp.c 2014-12-28 11:49:42.107208245 -0600
@@ -79,7 +79,7 @@
u_int pfd_elms = 0, idx2peer_elms = 0;
u_int listener_cnt, new_cnt, sent_cnt, trial_cnt;
u_int ctl_cnt;
- pid_t pid, dns_pid;
+ pid_t pid;
struct pollfd *pfd = NULL;
struct servent *se;
struct listen_addr *la;
@@ -118,7 +118,7 @@
close(pipe_prnt[0]);
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_dns) == -1)
fatal("socketpair");
- dns_pid = ntp_dns(pipe_dns, nconf, pw);
+ ntp_dns(pipe_dns, nconf, pw);
close(pipe_dns[1]);
if (stat(pw->pw_dir, &stb) == -1)

+ 0
- 10
patches/patch-ntpd.c View File

@ -1,10 +0,0 @@
--- ntpd.orig 2014-12-28 11:51:56.363211155 -0600
+++ ntpd.c 2014-12-28 11:52:00.971211255 -0600
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <err.h>

+ 0
- 33
patches/patch-ntpd.h View File

@ -1,33 +0,0 @@
--- ntpd.orig Sun Dec 28 16:11:35 2014
+++ ntpd.h Sun Dec 28 16:12:14 2014
@@ -28,7 +28,6 @@
#include <netdb.h>
#include <pwd.h>
#include <stdarg.h>
-#include <event.h>
#include <poll.h>
#include "ntp.h"
@@ -190,14 +189,6 @@
u_int8_t filters;
};
-struct imsgev {
- struct imsgbuf ibuf;
- void (*handler)(int, short, void *);
- struct event ev;
- void *data;
- short events;
-};
-
struct ctl_show_status {
u_int peercnt;
u_int sensorcnt;
@@ -240,7 +231,6 @@
struct ctl_conn {
TAILQ_ENTRY(ctl_conn) entry;
- struct imsgev iev;
struct imsgbuf ibuf;
};

+ 0
- 15
patches/patch-parse.y View File

@ -1,15 +0,0 @@
--- parse.orig 2014-12-28 11:59:42.075221249 -0600
+++ parse.y 2014-12-28 11:54:22.799214329 -0600
@@ -313,10 +313,12 @@
opts.weight = $2;
}
rtable : RTABLE NUMBER {
+#ifdef RT_TABLEID_MAX
if ($2 < 0 || $2 > RT_TABLEID_MAX) {
yyerror("rtable must be between 1 and RT_TABLEID_MAX");
YYERROR;
}
+#endif
opts.rtable = $2;
}
;

+ 0
- 53
patches/patch-server.c View File

@ -1,53 +0,0 @@
--- server.orig 2014-12-28 12:16:48.203243490 -0600
+++ server.c 2014-12-28 12:18:07.907245217 -0600
@@ -39,7 +39,10 @@
u_int8_t *a6;
size_t sa6len = sizeof(struct in6_addr);
u_int new_cnt = 0;
- int tos = IPTOS_LOWDELAY, rdomain, fd;
+ int tos = IPTOS_LOWDELAY;
+#ifdef SO_RTABLE
+ int rdomain, fd;
+#endif
TAILQ_FOREACH(lap, &lconf->listen_addrs, entry) {
switch (lap->sa.ss_family) {
@@ -59,6 +62,7 @@
strlcpy(ifr.ifr_name, ifap->ifa_name,
sizeof(ifr.ifr_name));
+#ifdef SO_RTABLE
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (ioctl(fd, SIOCGIFRDOMAIN,
(caddr_t)&ifr) == -1)
@@ -69,6 +73,7 @@
if (lap->rtable != -1 && rdomain != lap->rtable)
continue;
+#endif
if (sa->sa_family == AF_INET &&
((struct sockaddr_in *)sa)->sin_addr.s_addr ==
@@ -87,7 +92,9 @@
fatal("setup_listeners calloc");
memcpy(&la->sa, sa, SA_LEN(sa));
+#ifdef SO_RTABLE
la->rtable = rdomain;
+#endif
TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
}
@@ -132,10 +139,12 @@
IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
log_warn("setsockopt IPTOS_LOWDELAY");
+#ifdef SO_RTABLE
if (la->rtable != -1 &&
setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
sizeof(la->rtable)) == -1)
fatal("setup_listeners setsockopt SO_RTABLE");
+#endif
if (bind(la->fd, (struct sockaddr *)&la->sa,
SA_LEN((struct sockaddr *)&la->sa)) == -1) {

+ 0
- 13
patches/patch-util.c View File

@ -1,13 +0,0 @@
--- util.orig 2014-12-28 12:18:54.727246232 -0600
+++ util.c 2014-12-28 12:19:04.211246438 -0600
@@ -17,8 +17,10 @@
*/
#include <sys/time.h>
+
#include <limits.h>
#include <stdio.h>
+#include <time.h>
#include "ntpd.h"

+ 5
- 4
update.sh View File

@ -56,8 +56,9 @@ for i in client.c config.c control.c log.c ntp.c ntp.h ntp_dns.c ntp_msg.c \
file=`basename $i`
echo Copying $file
$CP $ntpd_src/$i .
if [ -e $patches/patch-$file ]; then
echo Patching $file
$PATCH < $patches/patch-$file
fi
done
for i in patches/*.patch; do
echo Patching $i
$PATCH -p4 < $i
done

Loading…
Cancel
Save