Browse Source

Fix init of syslog for childs and teach dns process about synced state.

ok benno@
OPENBSD_6_6
otto 5 years ago
parent
commit
46a918abc5
6 changed files with 39 additions and 30 deletions
  1. +3
    -3
      src/usr.sbin/ntpd/config.c
  2. +10
    -9
      src/usr.sbin/ntpd/ntp.c
  3. +16
    -11
      src/usr.sbin/ntpd/ntp_dns.c
  4. +3
    -2
      src/usr.sbin/ntpd/ntpd.c
  5. +5
    -3
      src/usr.sbin/ntpd/ntpd.h
  6. +2
    -2
      src/usr.sbin/ntpd/parse.y

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

@ -1,4 +1,4 @@
/* $OpenBSD: config.c,v 1.30 2019/05/28 06:49:46 otto Exp $ */
/* $OpenBSD: config.c,v 1.31 2019/06/12 05:04:45 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -126,13 +126,13 @@ host_dns1(const char *s, struct ntp_addr **hn, int notauth)
}
int
host_dns(const char *s, struct ntp_addr **hn)
host_dns(const char *s, int synced, struct ntp_addr **hn)
{
int error, save_opts;
log_debug("trying to resolve %s", s);
error = host_dns1(s, hn, 0);
if (error <= 0) {
if (!synced && error <= 0) {
log_debug("no luck, trying to resolve %s without checking", s);
save_opts = _res.options;
_res.options |= RES_USE_CD;


+ 10
- 9
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.153 2019/06/09 08:40:54 otto Exp $ */
/* $OpenBSD: ntp.c,v 1.154 2019/06/12 05:04:45 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -95,12 +95,10 @@ ntp_main(struct ntpd_conf *nconf, struct passwd *pw, int argc, char **argv)
start_child(NTPDNS_PROC_NAME, pipe_dns[1], argc, argv);
/* in this case the parent didn't init logging and didn't daemonize */
if (nconf->settime && !nconf->debug) {
log_init(nconf->debug, LOG_DAEMON);
if (setsid() == -1)
fatal("setsid");
}
log_init(nconf->debug, LOG_DAEMON);
log_setverbose(nconf->verbose);
if (!nconf->debug && setsid() == -1)
fatal("setsid");
log_procinit("ntp");
if ((se = getservbyname("ntp", "udp")) == NULL)
@ -446,9 +444,11 @@ ntp_dispatch_imsg(void)
if (n == 1 && !conf->status.synced) {
log_info("clock is now synced");
conf->status.synced = 1;
priv_dns(IMSG_SYNCED, NULL, 0);
} else if (n == 0 && conf->status.synced) {
log_info("clock is now unsynced");
conf->status.synced = 0;
priv_dns(IMSG_UNSYNCED, NULL, 0);
}
break;
case IMSG_CONSTRAINT_RESULT:
@ -762,9 +762,10 @@ priv_settime(double offset)
void
priv_dns(int cmd, char *name, u_int32_t peerid)
{
u_int16_t dlen;
u_int16_t dlen = 0;
dlen = strlen(name) + 1;
if (name != NULL)
dlen = strlen(name) + 1;
imsg_compose(ibuf_dns, cmd, peerid, 0, -1, name, dlen);
}


+ 16
- 11
src/usr.sbin/ntpd/ntp_dns.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp_dns.c,v 1.21 2019/05/28 06:49:46 otto Exp $ */
/* $OpenBSD: ntp_dns.c,v 1.22 2019/06/12 05:04:45 otto Exp $ */
/*
* Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org>
@ -39,7 +39,7 @@ volatile sig_atomic_t quit_dns = 0;
struct imsgbuf *ibuf_dns;
void sighdlr_dns(int);
int dns_dispatch_imsg(void);
int dns_dispatch_imsg(struct ntpd_conf *);
void
sighdlr_dns(int sig)
@ -62,12 +62,10 @@ ntp_dns(struct ntpd_conf *nconf, struct passwd *pw)
if (setpriority(PRIO_PROCESS, 0, 0) == -1)
log_warn("could not set priority");
/* in this case the parent didn't init logging and didn't daemonize */
if (nconf->settime && !nconf->debug) {
log_init(nconf->debug, LOG_DAEMON);
if (setsid() == -1)
fatal("setsid");
}
log_init(nconf->debug, LOG_DAEMON);
log_setverbose(nconf->verbose);
if (!nconf->debug && setsid() == -1)
fatal("setsid");
log_procinit("dns");
if ((nullfd = open("/dev/null", O_RDWR, 0)) == -1)
@ -119,7 +117,7 @@ ntp_dns(struct ntpd_conf *nconf, struct passwd *pw)
if (nfds > 0 && pfd[0].revents & POLLIN) {
nfds--;
if (dns_dispatch_imsg() == -1)
if (dns_dispatch_imsg(nconf) == -1)
quit_dns = 1;
}
}
@ -130,7 +128,7 @@ ntp_dns(struct ntpd_conf *nconf, struct passwd *pw)
}
int
dns_dispatch_imsg(void)
dns_dispatch_imsg(struct ntpd_conf *nconf)
{
struct imsg imsg;
int n, cnt;
@ -164,7 +162,8 @@ dns_dispatch_imsg(void)
if (name[len] != '\0' ||
strlen(name) != len)
fatalx("invalid %s received", str);
if ((cnt = host_dns(name, &hn)) == -1)
if ((cnt = host_dns(name, nconf->status.synced,
&hn)) == -1)
break;
buf = imsg_create(ibuf_dns, imsg.hdr.type,
imsg.hdr.peerid, 0,
@ -190,6 +189,12 @@ dns_dispatch_imsg(void)
if (buf)
imsg_close(ibuf_dns, buf);
break;
case IMSG_SYNCED:
nconf->status.synced = 1;
break;
case IMSG_UNSYNCED:
nconf->status.synced = 0;
break;
default:
break;
}


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.121 2019/06/09 08:40:54 otto Exp $ */
/* $OpenBSD: ntpd.c,v 1.122 2019/06/12 05:04:45 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -179,7 +179,8 @@ main(int argc, char *argv[])
}
/* log to stderr until daemonized */
log_init(lconf.debug ? lconf.debug : 1, LOG_DAEMON);
log_init(1, LOG_DAEMON);
log_setverbose(lconf.verbose);
argc -= optind;
argv += optind;


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.141 2019/06/09 08:40:54 otto Exp $ */
/* $OpenBSD: ntpd.h,v 1.142 2019/06/12 05:04:45 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -305,7 +305,9 @@ enum imsg_type {
IMSG_CTL_SHOW_SENSORS,
IMSG_CTL_SHOW_SENSORS_END,
IMSG_CTL_SHOW_ALL,
IMSG_CTL_SHOW_ALL_END
IMSG_CTL_SHOW_ALL_END,
IMSG_SYNCED,
IMSG_UNSYNCED
};
enum ctl_actions {
@ -335,7 +337,7 @@ int parse_config(const char *, struct ntpd_conf *);
/* config.c */
void host(const char *, struct ntp_addr **);
int host_dns(const char *, struct ntp_addr **);
int host_dns(const char *, int, struct ntp_addr **);
void host_dns_free(struct ntp_addr *);
struct ntp_peer *new_peer(void);
struct ntp_conf_sensor *new_sensor(char *);


+ 2
- 2
src/usr.sbin/ntpd/parse.y View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.71 2019/02/13 22:57:08 deraadt Exp $ */
/* $OpenBSD: parse.y,v 1.72 2019/06/12 05:04:45 otto Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -109,7 +109,7 @@ main : LISTEN ON address listen_opts {
struct ntp_addr *h, *next;
if ((h = $3->a) == NULL &&
(host_dns($3->name, &h) == -1 || !h)) {
(host_dns($3->name, 0, &h) == -1 || !h)) {
yyerror("could not resolve \"%s\"", $3->name);
free($3->name);
free($3);


Loading…
Cancel
Save