Browse Source

make ntpd listen on the hotplug socket and decode yadda yadda, because

new sensors showing up will be announced that way when slacking ml comes
back from food
OPENBSD_4_0
henning 18 years ago
parent
commit
1c3c1ca642
3 changed files with 58 additions and 5 deletions
  1. +13
    -3
      src/usr.sbin/ntpd/ntp.c
  2. +3
    -1
      src/usr.sbin/ntpd/ntpd.h
  3. +42
    -1
      src/usr.sbin/ntpd/sensors.c

+ 13
- 3
src/usr.sbin/ntpd/ntp.c View File

@ -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> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -35,7 +35,8 @@
#include "ntp.h" #include "ntp.h"
#define PFD_PIPE_MAIN 0 #define PFD_PIPE_MAIN 0
#define PFD_MAX 1
#define PFD_HOTPLUG 1
#define PFD_MAX 2
volatile sig_atomic_t ntp_quit = 0; volatile sig_atomic_t ntp_quit = 0;
struct imsgbuf *ibuf_main; struct imsgbuf *ibuf_main;
@ -62,7 +63,8 @@ ntp_sighdlr(int sig)
pid_t pid_t
ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) 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 pfd_elms = 0, idx2peer_elms = 0;
u_int listener_cnt, new_cnt, sent_cnt, trial_cnt; u_int listener_cnt, new_cnt, sent_cnt, trial_cnt;
u_int sensors_cnt = 0; 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) if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1)
fatal(NULL); fatal(NULL);
hotplugfd = sensor_hotplugfd();
if (stat(pw->pw_dir, &stb) == -1) if (stat(pw->pw_dir, &stb) == -1)
fatal("stat"); fatal("stat");
@ -187,6 +190,8 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
nextaction = time(NULL) + 3600; nextaction = time(NULL) + 3600;
pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd; pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd;
pfd[PFD_PIPE_MAIN].events = POLLIN; pfd[PFD_PIPE_MAIN].events = POLLIN;
pfd[PFD_HOTPLUG].fd = hotplugfd;
pfd[PFD_HOTPLUG].events = POLLIN;
i = PFD_MAX; i = PFD_MAX;
TAILQ_FOREACH(la, &conf->listen_addrs, entry) { TAILQ_FOREACH(la, &conf->listen_addrs, entry) {
@ -272,6 +277,11 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
ntp_quit = 1; 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++) for (j = 1; nfds > 0 && j < idx_peers; j++)
if (pfd[j].revents & (POLLIN|POLLERR)) { if (pfd[j].revents & (POLLIN|POLLERR)) {
nfds--; nfds--;


+ 3
- 1
src/usr.sbin/ntpd/ntpd.h View File

@ -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> * 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_scan(struct ntpd_conf *);
void sensor_remove(struct ntpd_conf *, struct ntp_sensor *); void sensor_remove(struct ntpd_conf *, struct ntp_sensor *);
int sensor_query(struct ntp_sensor *); int sensor_query(struct ntp_sensor *);
int sensor_hotplugfd(void);
void sensor_hotplugevent(int);

+ 42
- 1
src/usr.sbin/ntpd/sensors.c View File

@ -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> * Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -20,6 +20,8 @@
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/sensors.h> #include <sys/sensors.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/device.h>
#include <sys/hotplug.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -30,6 +32,7 @@
#include "ntpd.h" #include "ntpd.h"
#define SENSORS_MAX 255 #define SENSORS_MAX 255
#define _PATH_DEV_HOTPLUG "/dev/hotplug"
void sensor_add(struct ntpd_conf *, struct sensor *); void sensor_add(struct ntpd_conf *, struct sensor *);
@ -150,3 +153,41 @@ sensor_query(struct ntp_sensor *s)
return (0); 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));
}

Loading…
Cancel
Save