summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/ntpd/ntp.c16
-rw-r--r--usr.sbin/ntpd/ntpd.h4
-rw-r--r--usr.sbin/ntpd/sensors.c43
3 files changed, 58 insertions, 5 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index ae7418d0261..a4ef5edcbba 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/usr.sbin/ntpd/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.72 2006/05/27 18:32:00 henning Exp $ */
+/* $OpenBSD: ntp.c,v 1.73 2006/05/27 21:27:34 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -35,7 +35,8 @@
#include "ntp.h"
#define PFD_PIPE_MAIN 0
-#define PFD_MAX 1
+#define PFD_HOTPLUG 1
+#define PFD_MAX 2
volatile sig_atomic_t ntp_quit = 0;
struct imsgbuf *ibuf_main;
@@ -62,7 +63,8 @@ ntp_sighdlr(int sig)
pid_t
ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
{
- int a, b, nfds, i, j, idx_peers, timeout, nullfd;
+ int a, b, nfds, i, j, idx_peers, timeout;
+ int hotplugfd, nullfd;
u_int pfd_elms = 0, idx2peer_elms = 0;
u_int listener_cnt, new_cnt, sent_cnt, trial_cnt;
u_int sensors_cnt = 0;
@@ -97,6 +99,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1)
fatal(NULL);
+ hotplugfd = sensor_hotplugfd();
if (stat(pw->pw_dir, &stb) == -1)
fatal("stat");
@@ -187,6 +190,8 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
nextaction = time(NULL) + 3600;
pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd;
pfd[PFD_PIPE_MAIN].events = POLLIN;
+ pfd[PFD_HOTPLUG].fd = hotplugfd;
+ pfd[PFD_HOTPLUG].events = POLLIN;
i = PFD_MAX;
TAILQ_FOREACH(la, &conf->listen_addrs, entry) {
@@ -272,6 +277,11 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
ntp_quit = 1;
}
+ if (nfds > 0 && pfd[PFD_HOTPLUG].revents & (POLLIN|POLLERR)) {
+ nfds--;
+ sensor_hotplugevent(hotplugfd);
+ }
+
for (j = 1; nfds > 0 && j < idx_peers; j++)
if (pfd[j].revents & (POLLIN|POLLERR)) {
nfds--;
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index 5d3086ad862..8b041053b40 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.65 2006/05/27 18:32:00 henning Exp $ */
+/* $OpenBSD: ntpd.h,v 1.66 2006/05/27 21:27:34 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -285,3 +285,5 @@ void sensor_init(struct ntpd_conf *);
void sensor_scan(struct ntpd_conf *);
void sensor_remove(struct ntpd_conf *, struct ntp_sensor *);
int sensor_query(struct ntp_sensor *);
+int sensor_hotplugfd(void);
+void sensor_hotplugevent(int);
diff --git a/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c
index 6213f5ca581..59e306f8353 100644
--- a/usr.sbin/ntpd/sensors.c
+++ b/usr.sbin/ntpd/sensors.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sensors.c,v 1.2 2006/05/27 17:01:07 henning Exp $ */
+/* $OpenBSD: sensors.c,v 1.3 2006/05/27 21:27:34 henning Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@@ -20,6 +20,8 @@
#include <sys/queue.h>
#include <sys/sensors.h>
#include <sys/sysctl.h>
+#include <sys/device.h>
+#include <sys/hotplug.h>
#include <errno.h>
#include <fcntl.h>
@@ -30,6 +32,7 @@
#include "ntpd.h"
#define SENSORS_MAX 255
+#define _PATH_DEV_HOTPLUG "/dev/hotplug"
void sensor_add(struct ntpd_conf *, struct sensor *);
@@ -150,3 +153,41 @@ sensor_query(struct ntp_sensor *s)
return (0);
}
+
+int
+sensor_hotplugfd(void)
+{
+ int fd, flags;
+
+ if ((fd = open(_PATH_DEV_HOTPLUG, O_RDONLY, 0)) == -1)
+ fatal(NULL);
+
+ if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
+ fatal("fnctl F_GETFL");
+ flags |= O_NONBLOCK;
+ if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
+ fatal("fnctl F_SETFL");
+
+ return (fd);
+}
+
+void
+sensor_hotplugevent(int fd)
+{
+ struct hotplug_event he;
+ ssize_t n;
+
+ do {
+ if ((n = read(fd, &he, sizeof(he))) == -1 &&
+ errno != EINTR && errno != EAGAIN)
+ fatal("sensor_hotplugevent read");
+
+ if (n == sizeof(he))
+ switch (he.he_type) {
+ default: /* ignore */
+ break;
+ }
+ else if (n > 0)
+ fatal("sensor_hotplugevent: short read");
+ } while (n > 0 || (n == -1 && errno == EINTR));
+}