Browse Source

Prevent multiple ntpds from tripping over each other.

This brings over the logic from bgpd & ospfd.
Input & OK deraadt
OPENBSD_6_5
florian 5 years ago
parent
commit
ea28228b66
3 changed files with 33 additions and 3 deletions
  1. +27
    -1
      src/usr.sbin/ntpd/control.c
  2. +4
    -1
      src/usr.sbin/ntpd/ntpd.c
  3. +2
    -1
      src/usr.sbin/ntpd/ntpd.h

+ 27
- 1
src/usr.sbin/ntpd/control.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.13 2018/08/04 11:07:14 mestre Exp $ */
/* $OpenBSD: control.c,v 1.14 2019/01/14 16:30:21 florian Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -36,6 +36,32 @@
#define square(x) ((x) * (x))
int
control_check(char *path)
{
struct sockaddr_un sun;
int fd;
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
log_warn("control_check: socket check");
return (-1);
}
if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0) {
log_warnx("control_check: socket in use");
close(fd);
return (-1);
}
close(fd);
return (0);
}
int
control_init(char *path)
{


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.119 2018/11/29 14:25:07 tedu Exp $ */
/* $OpenBSD: ntpd.c,v 1.120 2019/01/14 16:30:21 florian Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -202,6 +202,9 @@ main(int argc, char *argv[])
pname);
fatalx("%s: process '%s' failed", __func__, pname);
} else {
if ((control_check(CTLSOCKET)) == -1)
fatalx("ntpd already running");
}
if (setpriority(PRIO_PROCESS, 0, -20) == -1)


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.137 2018/11/06 20:41:36 jsing Exp $ */
/* $OpenBSD: ntpd.h,v 1.138 2019/01/14 16:30:21 florian Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -393,6 +393,7 @@ void sensor_query(struct ntp_sensor *);
void ntp_dns(struct ntpd_conf *, struct passwd *);
/* control.c */
int control_check(char *);
int control_init(char *);
int control_listen(int);
void control_shutdown(int);


Loading…
Cancel
Save