summaryrefslogtreecommitdiff
path: root/sbin/dhclient/kroute.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2012-12-04 19:24:04 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2012-12-04 19:24:04 +0000
commit0360b5844fced3950f93dd48956263e3c61bcdd9 (patch)
treebd95a817b825106e554977a57c6c89f39636708b /sbin/dhclient/kroute.c
parent88c41f8abbe91b0c05088f347532ff624af55472 (diff)
Eliminate hand-rolled pseudo-strerror() %m strangeness by replacing
all occurances of %m with strerror(errno). And then nuking do_percentm() and related buffer shuffling. Also simplify parse_warn() so it takes a simple char * of the error, and thus rely on pointing to error location in input for details. Makes sense to beck@
Diffstat (limited to 'sbin/dhclient/kroute.c')
-rw-r--r--sbin/dhclient/kroute.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 7290fb7e927..9337ea62726 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.22 2012/12/03 22:36:16 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.23 2012/12/04 19:24:03 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -48,12 +48,14 @@ flush_routes_and_arp_cache(int rdomain)
rslt = imsg_compose(unpriv_ibuf, IMSG_FLUSH_ROUTES, 0, 0, -1,
&imsg, sizeof(imsg));
if (rslt == -1)
- warning("flush_routes_and_arp_cache: imsg_compose: %m");
+ warning("flush_routes_and_arp_cache: 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_and_arp_cache: imsg_flush: %m");
+ warning("flush_routes_and_arp_cache: imsg_flush: %s",
+ strerror(errno));
}
void
@@ -91,13 +93,13 @@ priv_flush_routes_and_arp_cache(struct imsg_flush_routes *imsg)
error("malloc");
if (sysctl(mib, 7, buf, &needed, NULL, 0) == -1)
- error("sysctl retrieval of routes: %m");
+ error("sysctl retrieval of routes: %s", strerror(errno));
if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
- error("opening socket to flush routes: %m");
+ error("opening socket to flush routes: %s", strerror(errno));
if (asprintf(&routelabel, "DHCLIENT %d", (int)getpid()) == -1)
- error("recreating route label: %m");
+ error("recreating route label: %s", strerror(errno));
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
@@ -162,7 +164,7 @@ priv_flush_routes_and_arp_cache(struct imsg_flush_routes *imsg)
rlen = write(s, next, rtm->rtm_msglen);
if (rlen == -1) {
if (errno != ESRCH)
- error("RTM_DELETE write: %m");
+ error("RTM_DELETE write: %s", strerror(errno));
} else if (rlen < (int)rtm->rtm_msglen)
error("short RTM_DELETE write (%d)\n", rlen);
@@ -202,7 +204,7 @@ add_default_route(int rdomain, struct in_addr addr, struct in_addr gateway)
&imsg, sizeof(imsg));
if (rslt == -1)
- warning("add_default_route: imsg_compose: %m");
+ warning("add_default_route: imsg_compose: %s", strerror(errno));
}
void
@@ -219,7 +221,7 @@ priv_add_default_route(struct imsg_add_default_route *imsg)
*/
if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
- error("Routing Socket open failed: %m");
+ error("Routing Socket open failed: %s", strerror(errno));
/* Build RTM header */
@@ -285,7 +287,7 @@ priv_add_default_route(struct imsg_add_default_route *imsg)
len = snprintf(label.sr_label, sizeof(label.sr_label), "DHCLIENT %d",
getpid());
if (len == -1)
- error("writing label for default route: %m");
+ error("writing label for default route: %s", strerror(errno));
if (len >= sizeof(label.sr_label))
error("label for default route too long (%zd)",
sizeof(label.sr_label));
@@ -301,7 +303,8 @@ priv_add_default_route(struct imsg_add_default_route *imsg)
if (writev(s, iov, iovcnt) != -1)
break;
if (errno != EEXIST)
- error("failed to add default route: %m");
+ error("failed to add default route: %s",
+ strerror(errno));
sleep(1);
}
@@ -318,7 +321,7 @@ delete_addresses(char *ifname, int rdomain)
struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0)
- error("delete_addresses getifaddrs: %m");
+ error("delete_addresses getifaddrs: %s", strerror(errno));
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if ((ifa->ifa_flags & IFF_LOOPBACK) ||
@@ -364,7 +367,7 @@ delete_address(char *ifname, int rdomain, struct in_addr addr)
sizeof(imsg));
if (rslt == -1)
- warning("delete_address: imsg_compose: %m");
+ warning("delete_address: imsg_compose: %s", strerror(errno));
}
void
@@ -382,7 +385,7 @@ priv_delete_address(struct imsg_delete_address *imsg)
*/
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
- error("socket open failed: %m");
+ error("socket open failed: %s", strerror(errno));
memset(&ifaliasreq, 0, sizeof(ifaliasreq));
strncpy(ifaliasreq.ifra_name, imsg->ifname,
@@ -395,7 +398,8 @@ priv_delete_address(struct imsg_delete_address *imsg)
/* SIOCDIFADDR will result in a RTM_DELADDR message we must catch! */
if (ioctl(s, SIOCDIFADDR, &ifaliasreq) == -1) {
- warning("SIOCDIFADDR failed (%s): %m", inet_ntoa(imsg->addr));
+ warning("SIOCDIFADDR failed (%s): %s", inet_ntoa(imsg->addr),
+ strerror(errno));
close(s);
return;
}
@@ -407,7 +411,7 @@ priv_delete_address(struct imsg_delete_address *imsg)
*/
if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
- error("Routing Socket open failed: %m");
+ error("Routing Socket open failed: %s", strerror(errno));
/* Build RTM header */
@@ -453,7 +457,7 @@ priv_delete_address(struct imsg_delete_address *imsg)
/* ESRCH means the route does not exist to delete. */
if ((writev(s, iov, iovcnt) == -1) && (errno != ESRCH))
- error("failed to delete 127.0.0.1: %m");
+ error("failed to delete 127.0.0.1: %s", strerror(errno));
close(s);
}
@@ -485,7 +489,7 @@ add_address(char *ifname, int rdomain, struct in_addr addr,
sizeof(imsg));
if (rslt == -1)
- warning("add_address: imsg_compose: %m");
+ warning("add_address: imsg_compose: %s", strerror(errno));
}
void
@@ -504,7 +508,7 @@ priv_add_address(struct imsg_add_address *imsg)
*/
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
- error("socket open failed: %m");
+ error("socket open failed: %s", strerror(errno));
memset(&ifaliasreq, 0, sizeof(ifaliasreq));
strncpy(ifaliasreq.ifra_name, imsg->ifname,
@@ -525,7 +529,8 @@ priv_add_address(struct imsg_add_address *imsg)
/* No need to set broadcast address. Kernel can figure it out. */
if (ioctl(s, SIOCAIFADDR, &ifaliasreq) == -1)
- warning("SIOCAIFADDR failed (%s): %m", inet_ntoa(imsg->addr));
+ warning("SIOCAIFADDR failed (%s): %s", inet_ntoa(imsg->addr),
+ strerror(errno));
close(s);
@@ -534,7 +539,7 @@ priv_add_address(struct imsg_add_address *imsg)
*/
if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
- error("Routing Socket open failed: %m");
+ error("Routing Socket open failed: %s", strerror(errno));
/* Build RTM header */
@@ -586,7 +591,7 @@ priv_add_address(struct imsg_add_address *imsg)
len = snprintf(label.sr_label, sizeof(label.sr_label), "DHCLIENT %d",
getpid());
if (len == -1)
- error("writing label for host route: %m");
+ error("writing label for host route: %s", strerror(errno));
if (len >= sizeof(label.sr_label))
error("label for host route too long (%zd)",
sizeof(label.sr_label));
@@ -603,10 +608,12 @@ priv_add_address(struct imsg_add_address *imsg)
break;
/* XXX Why do some systems get ENETUNREACH? */
if (errno == ENETUNREACH) {
- note("failed to add 127.0.0.1 route: %m");
+ note("failed to add 127.0.0.1 route: %s",
+ strerror(errno));
break;
} else if (errno != EEXIST)
- error("failed to add 127.0.0.1 route: %m");
+ error("failed to add 127.0.0.1 route: %s",
+ strerror(errno));
sleep(1);
}
@@ -634,12 +641,12 @@ cleanup(struct client_lease *active)
rslt = imsg_compose(unpriv_ibuf, IMSG_CLEANUP, 0, 0, -1,
&imsg, sizeof(imsg));
if (rslt == -1)
- warning("cleanup: imsg_compose: %m");
+ warning("cleanup: imsg_compose: %s", strerror(errno));
/* Do flush so cleanup message gets through immediately. */
rslt = imsg_flush(unpriv_ibuf);
if (rslt == -1)
- warning("cleanup: imsg_flush: %m");
+ warning("cleanup: imsg_flush: %s", strerror(errno));
}
void