summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ntpd/constraint.c
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2016-01-27 21:48:34 +0000
committerreyk <reyk@openbsd.org>2016-01-27 21:48:34 +0000
commit0a1ac5ece8021b85b58c55b01367be73beea211a (patch)
tree29f852b1289b011fc2b06fd487984c23581c5e3f /usr.sbin/ntpd/constraint.c
parentupdate ntpd log initialization to work like relayd, fix debug log levels (diff)
downloadwireguard-openbsd-0a1ac5ece8021b85b58c55b01367be73beea211a.tar.xz
wireguard-openbsd-0a1ac5ece8021b85b58c55b01367be73beea211a.zip
Don't attempt to kill() the constraint in the wrong process. The
process management of the contraint processes has been moved from ntp to the parent, for better privsep and pledge, but the ntp process still attempted to kill the constraints on timeout directly. Fix this regression by introducing a new imsg from ntp to the parent and the related logic to kill a constraint at the right place. Reported & tested by bcook@ Ok bcook@
Diffstat (limited to 'usr.sbin/ntpd/constraint.c')
-rw-r--r--usr.sbin/ntpd/constraint.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/usr.sbin/ntpd/constraint.c b/usr.sbin/ntpd/constraint.c
index 91d6ceb5cd7..169007e4bde 100644
--- a/usr.sbin/ntpd/constraint.c
+++ b/usr.sbin/ntpd/constraint.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: constraint.c,v 1.24 2015/12/19 17:55:29 reyk Exp $ */
+/* $OpenBSD: constraint.c,v 1.25 2016/01/27 21:48:34 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -163,7 +163,10 @@ constraint_query(struct constraint *cstr)
}
/* Timeout, just kill the process to reset it. */
- kill(cstr->pid, SIGTERM);
+ imsg_compose(ibuf_main, IMSG_CONSTRAINT_KILL,
+ cstr->id, 0, -1, NULL, 0);
+
+ cstr->state = STATE_TIMEOUT;
return (-1);
case STATE_INVALID:
if (cstr->last + CONSTRAINT_SCAN_INTERVAL > now) {
@@ -380,6 +383,7 @@ priv_constraint_check_child(pid_t pid, int status)
{
struct constraint *cstr;
int fail, sig;
+ char *signame;
fail = sig = 0;
if (WIFSIGNALED(status)) {
@@ -391,15 +395,35 @@ priv_constraint_check_child(pid_t pid, int status)
fatalx("unexpected cause of SIGCHLD");
if ((cstr = constraint_bypid(pid)) != NULL) {
- if (sig)
- fatalx("constraint %s, signal %d",
- log_sockaddr((struct sockaddr *)
- &cstr->addr->ss), sig);
+ if (sig) {
+ if (sig != SIGTERM) {
+ signame = strsignal(sig) ?
+ strsignal(sig) : "unknown";
+ log_warnx("constraint %s; "
+ "terminated with signal %d (%s)",
+ log_sockaddr((struct sockaddr *)
+ &cstr->addr->ss), sig, signame);
+ }
+ fail = 1;
+ }
priv_constraint_close(cstr->fd, fail);
}
}
+void
+priv_constraint_kill(u_int32_t id)
+{
+ struct constraint *cstr;
+
+ if ((cstr = constraint_byid(id)) == NULL) {
+ log_warnx("IMSG_CONSTRAINT_KILL for invalid id %d", id);
+ return;
+ }
+
+ kill(cstr->pid, SIGTERM);
+}
+
struct constraint *
constraint_byid(u_int32_t id)
{