summaryrefslogtreecommitdiff
path: root/sbin/dhclient/kroute.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2014-02-09 20:45:57 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2014-02-09 20:45:57 +0000
commit921ec171ed19d80ccafcb5d19b8cee4d4db325c0 (patch)
treef38cf748becb18798dedda6421c543f6dc128a42 /sbin/dhclient/kroute.c
parent8426aa0d2f7d3e7f14d116125458c904325fa782 (diff)
Don't use imsg_flush(), roll a local flush_unpriv_ibuf() that loops
on EAGAIN, sets quit to INTERNALSIG on errors (unless quit is already set to something else), and prints a consistant error message when errors other than EPIPE and end of file are encountered. Fixes failure to write resolv.conf when -L is used, and makes add_address() and add_route() also wait until imsg is in pipe.
Diffstat (limited to 'sbin/dhclient/kroute.c')
-rw-r--r--sbin/dhclient/kroute.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 2cd86e41df3..4b3930de435 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.62 2014/02/09 20:23:22 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.63 2014/02/09 20:45:56 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -65,10 +65,7 @@ flush_routes(char *ifname, int rdomain)
if (rslt == -1)
warning("flush_routes: imsg_compose: %s", strerror(errno));
- /* Do flush to maximize chances of cleaning up routes on exit. */
- rslt = imsg_flush(unpriv_ibuf);
- if (rslt == -1)
- warning("flush_routes: imsg_flush: %s", strerror(errno));
+ flush_unpriv_ibuf("flush_routes");
}
void
@@ -190,6 +187,8 @@ add_route(int rdomain, struct in_addr dest, struct in_addr netmask,
&imsg, sizeof(imsg));
if (rslt == -1)
warning("add_route: imsg_compose: %s", strerror(errno));
+
+ flush_unpriv_ibuf("add_route");
}
void
@@ -333,10 +332,7 @@ delete_address(char *ifname, int rdomain, struct in_addr addr)
if (rslt == -1)
warning("delete_address: imsg_compose: %s", strerror(errno));
- /* Do flush to quickly kill previous dhclient, if any. */
- rslt = imsg_flush(unpriv_ibuf);
- if (rslt == -1 && errno != EPIPE)
- warning("delete_address: imsg_flush: %s", strerror(errno));
+ flush_unpriv_ibuf("delete_address");
}
void
@@ -400,6 +396,8 @@ add_address(char *ifname, int rdomain, struct in_addr addr,
sizeof(imsg));
if (rslt == -1)
warning("add_address: imsg_compose: %s", strerror(errno));
+
+ flush_unpriv_ibuf("add_address");
}
void
@@ -471,10 +469,7 @@ sendhup(struct client_lease *active)
if (rslt == -1)
warning("sendhup: imsg_compose: %s", strerror(errno));
- /* Do flush so cleanup message gets through immediately. */
- rslt = imsg_flush(unpriv_ibuf);
- if (rslt == -1 && errno != EPIPE)
- warning("sendhup: imsg_flush: %s", strerror(errno));
+ flush_unpriv_ibuf("sendhup");
}
/*
@@ -690,3 +685,20 @@ delete_route(int s, int rdomain, struct rt_msghdr *rtm)
} else if (rlen < (int)rtm->rtm_msglen)
error("short RTM_DELETE write (%zd)\n", rlen);
}
+
+void
+flush_unpriv_ibuf(const char *who)
+{
+ while (unpriv_ibuf->w.queued) {
+ if (msgbuf_write(&unpriv_ibuf->w) <= 0) {
+ if (errno == EAGAIN)
+ continue;
+ if (quit == 0)
+ quit = INTERNALSIG;
+ if (errno != EPIPE && errno != 0)
+ warning("%s: msgbuf_write: %s", who,
+ strerror(errno));
+ break;
+ }
+ }
+}