diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2014-02-09 20:45:57 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2014-02-09 20:45:57 +0000 |
commit | 921ec171ed19d80ccafcb5d19b8cee4d4db325c0 (patch) | |
tree | f38cf748becb18798dedda6421c543f6dc128a42 /sbin/dhclient | |
parent | 8426aa0d2f7d3e7f14d116125458c904325fa782 (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')
-rw-r--r-- | sbin/dhclient/dhclient.c | 7 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 9 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 38 |
4 files changed, 32 insertions, 26 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index e8eb8a93f1f..74205ff3fb0 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.292 2014/02/08 18:12:17 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.293 2014/02/09 20:45:56 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -2419,10 +2419,7 @@ write_file(char *path, int flags, mode_t mode, uid_t uid, gid_t gid, if (rslt == -1) warning("write_file: imsg_composev: %s", strerror(errno)); - /* Do flush to maximize chances of keeping file current. */ - rslt = imsg_flush(unpriv_ibuf); - if (rslt == -1) - warning("write_file: imsg_flush: %s", strerror(errno)); + flush_unpriv_ibuf("write_file"); } void diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 08ef9b279da..10efd27559d 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.135 2014/01/21 05:17:45 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.136 2014/02/09 20:45:56 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -312,3 +312,5 @@ void add_route(int, struct in_addr, struct in_addr, struct in_addr, int, int); void sendhup(struct client_lease *); int resolv_conf_priority(int); + +void flush_unpriv_ibuf(const char *); diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index e445f83ef84..da9916451be 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.87 2013/12/08 22:49:02 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.88 2014/02/09 20:45:56 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -209,12 +209,7 @@ another: routehandler(); } if (fds[2].revents & POLLOUT) { - if (msgbuf_write(&unpriv_ibuf->w) <= 0 && - errno != EAGAIN) { - warning("pipe write error to [priv]"); - quit = INTERNALSIG; - continue; - } + flush_unpriv_ibuf("dispatch"); } if ((fds[2].revents & (POLLIN | POLLHUP))) { /* Pipe to [priv] closed. Assume it emitted error. */ 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; + } + } +} |