diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-12-04 19:24:04 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-12-04 19:24:04 +0000 |
commit | 0360b5844fced3950f93dd48956263e3c61bcdd9 (patch) | |
tree | bd95a817b825106e554977a57c6c89f39636708b /sbin | |
parent | 88c41f8abbe91b0c05088f347532ff624af55472 (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')
-rw-r--r-- | sbin/dhclient/bpf.c | 33 | ||||
-rw-r--r-- | sbin/dhclient/clparse.c | 16 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 46 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 21 | ||||
-rw-r--r-- | sbin/dhclient/errwarn.c | 68 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 59 | ||||
-rw-r--r-- | sbin/dhclient/privsep.c | 5 |
8 files changed, 109 insertions, 143 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index 5913533c64a..1dfc3b2c40d 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.22 2012/11/15 14:54:18 krw Exp $ */ +/* $OpenBSD: bpf.c,v 1.23 2012/12/04 19:24:02 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -70,15 +70,16 @@ if_register_bpf(void) if (errno == EBUSY) continue; else - error("Can't find free bpf: %m"); + error("Can't find free bpf: %s", + strerror(errno)); } else break; } /* Set the BPF device to point at this interface. */ if (ioctl(sock, BIOCSETIF, ifi->ifp) < 0) - error("Can't attach interface %s to bpf device %s: %m", - ifi->name, filename); + error("Can't attach interface %s to bpf device %s: %s", + ifi->name, filename, strerror(errno)); return (sock); } @@ -98,13 +99,13 @@ if_register_send(void) * Use raw socket for unicast send. */ if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP)) == -1) - error("socket(SOCK_RAW): %m"); + error("socket(SOCK_RAW): %s", strerror(errno)); if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) == -1) - error("setsockopt(IP_HDRINCL): %m"); + error("setsockopt(IP_HDRINCL): %s", strerror(errno)); if (setsockopt(sock, IPPROTO_IP, SO_RTABLE, &ifi->rdomain, sizeof(ifi->rdomain)) == -1) - error("setsockopt(SO_RTABLE): %m"); + error("setsockopt(SO_RTABLE): %s", strerror(errno)); ifi->ufdesc = sock; } @@ -196,7 +197,7 @@ if_register_receive(void) /* Make sure the BPF version is in range... */ if (ioctl(ifi->rfdesc, BIOCVERSION, &v) < 0) - error("Can't get BPF version: %m"); + error("Can't get BPF version: %s", strerror(errno)); if (v.bv_major != BPF_MAJOR_VERSION || v.bv_minor < BPF_MINOR_VERSION) @@ -208,14 +209,16 @@ if_register_receive(void) * with packets. */ if (ioctl(ifi->rfdesc, BIOCIMMEDIATE, &flag) < 0) - error("Can't set immediate mode on bpf device: %m"); + error("Can't set immediate mode on bpf device: %s", + strerror(errno)); if (ioctl(ifi->rfdesc, BIOCSFILDROP, &flag) < 0) - error("Can't set filter-drop mode on bpf device: %m"); + error("Can't set filter-drop mode on bpf device: %s", + strerror(errno)); /* Get the required BPF buffer length from the kernel. */ if (ioctl(ifi->rfdesc, BIOCGBLEN, &sz) < 0) - error("Can't get bpf buffer length: %m"); + error("Can't get bpf buffer length: %s", strerror(errno)); ifi->rbuf_max = sz; ifi->rbuf = malloc(ifi->rbuf_max); if (!ifi->rbuf) @@ -236,7 +239,8 @@ if_register_receive(void) dhcp_bpf_filter[8].k = LOCAL_PORT; if (ioctl(ifi->rfdesc, BIOCSETF, &p) < 0) - error("Can't install packet filter program: %m"); + error("Can't install packet filter program: %s", + strerror(errno)); /* Set up the bpf write filter program structure. */ p.bf_len = dhcp_bpf_wfilter_len; @@ -246,7 +250,8 @@ if_register_receive(void) dhcp_bpf_wfilter[7].k = htons(IP_MF|IP_OFFMASK); if (ioctl(ifi->rfdesc, BIOCSETWF, &p) < 0) - error("Can't install write filter program: %m"); + error("Can't install write filter program: %s", + strerror(errno)); if (ioctl(ifi->rfdesc, BIOCLOCK, NULL) < 0) error("Cannot lock bpf"); @@ -288,7 +293,7 @@ send_packet(struct in_addr from, struct sockaddr_in *to, } if (result == -1) - warning("send_packet: %m"); + warning("send_packet: %s", strerror(errno)); return (result); } diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 6e44f3d2399..be1e3380e24 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.49 2012/11/27 18:52:39 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.50 2012/12/04 19:24:02 krw Exp $ */ /* Parser for dhclient config and lease files... */ @@ -333,18 +333,17 @@ parse_option_list(FILE *cfile, u_int8_t *list, size_t sz) break; if (i == DHO_END) { - parse_warn("%s: unexpected option name.", val); + parse_warn("unexpected option name."); goto syntaxerror; } if (ix == sz) { - parse_warn("%s: too many options.", val); + parse_warn("too many options."); goto syntaxerror; } /* Avoid storing duplicate options in the list. */ for (j = 0; j < ix; j++) { if (list[j] == i) { - parse_warn("%s: option in list more than once.", - val); + parse_warn("option in list more than once."); goto syntaxerror; } } @@ -541,8 +540,7 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease) break; } if (strcmp(ifi->name, val) != 0) { - parse_warn("wrong interface name. Expecting '%s'.", - ifi->name); + parse_warn("wrong interface name."); skip_to_semi(cfile); break; } @@ -613,7 +611,7 @@ parse_option_decl(FILE *cfile, struct option_data *options) break; if (code > 255) { - parse_warn("no option named %s", val); + parse_warn("unknown option name."); skip_to_semi(cfile); return (-1); } @@ -638,7 +636,7 @@ parse_option_decl(FILE *cfile, struct option_data *options) } len = strlen(val); if (hunkix + len + 1 > sizeof(hunkbuf)) { - parse_warn("option data buffer %s", + parse_warn("option data buffer " "overflow"); skip_to_semi(cfile); return (-1); diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 1766d2d696d..14f46b91d79 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.187 2012/12/03 22:36:16 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.188 2012/12/04 19:24:02 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -361,7 +361,7 @@ main(int argc, char *argv[]) dispatch: if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) - error("cannot open %s: %m", _PATH_DEVNULL); + error("cannot open %s: %s", _PATH_DEVNULL, strerror(errno)); if ((pw = getpwnam("_dhcp")) == NULL) error("no such user: _dhcp"); @@ -370,7 +370,7 @@ main(int argc, char *argv[]) discover_interface(); if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socket_fd) == -1) - error("socketpair: %m"); + error("socketpair: %s", strerror(errno)); socket_nonblockmode(socket_fd[0]); socket_nonblockmode(socket_fd[1]); @@ -382,25 +382,26 @@ main(int argc, char *argv[]) imsg_init(unpriv_ibuf, socket_fd[1]); if ((fd = open(path_dhclient_db, O_RDONLY|O_EXLOCK|O_CREAT, 0)) == -1) - error("can't open and lock %s: %m", path_dhclient_db); + error("can't open and lock %s: %s", path_dhclient_db, + strerror(errno)); read_client_leases(); if ((leaseFile = fopen(path_dhclient_db, "w")) == NULL) - error("can't open %s: %m", path_dhclient_db); + error("can't open %s: %s", path_dhclient_db, strerror(errno)); rewrite_client_leases(); close(fd); if ((routefd = socket(PF_ROUTE, SOCK_RAW, 0)) == -1) - error("socket(PF_ROUTE, SOCK_RAW): %m"); + error("socket(PF_ROUTE, SOCK_RAW): %s", strerror(errno)); rtfilter = ROUTE_FILTER(RTM_NEWADDR) | ROUTE_FILTER(RTM_DELADDR) | ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_IFANNOUNCE); if (setsockopt(routefd, PF_ROUTE, ROUTE_MSGFILTER, &rtfilter, sizeof(rtfilter)) == -1) - error("setsockopt(ROUTE_MSGFILTER): %m"); + error("setsockopt(ROUTE_MSGFILTER): %s", strerror(errno)); if (setsockopt(routefd, AF_ROUTE, ROUTE_TABLEFILTER, &ifi->rdomain, sizeof(ifi->rdomain)) == -1) - error("setsockopt(ROUTE_TABLEFILTER): %m"); + error("setsockopt(ROUTE_TABLEFILTER): %s", strerror(errno)); if (chroot(_PATH_VAREMPTY) == -1) error("chroot"); @@ -1749,7 +1750,7 @@ fork_privchld(int fd, int fd2) pfd[0].events = POLLIN; if ((nfds = poll(pfd, 1, INFTIM)) == -1) { if (errno != EINTR) { - warning("poll error: %m"); + warning("poll error: %s", strerror(errno)); break; } continue; @@ -1759,7 +1760,7 @@ fork_privchld(int fd, int fd2) continue; if ((n = imsg_read(priv_ibuf)) == -1) { - warning("imsg_read(priv_ibuf): %m"); + warning("imsg_read(priv_ibuf): %s", strerror(errno)); break; } @@ -1797,13 +1798,13 @@ get_ifname(char *ifname, char *arg) if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) { if (errno == ENOENT) error("no interface in group egress found"); - error("ioctl SIOCGIFGMEMB: %m"); + error("ioctl SIOCGIFGMEMB: %s", strerror(errno)); } len = ifgr.ifgr_len; if ((ifgr.ifgr_groups = calloc(1, len)) == NULL) error("get_ifname"); if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) - error("ioctl SIOCGIFGMEMB: %m"); + error("ioctl SIOCGIFGMEMB: %s", strerror(errno)); arg = NULL; for (ifg = ifgr.ifgr_groups; @@ -1815,7 +1816,7 @@ get_ifname(char *ifname, char *arg) } if (strlcpy(ifi->name, arg, IFNAMSIZ) >= IFNAMSIZ) - error("Interface name too long: %m"); + error("Interface name too long: %s", strerror(errno)); free(ifgr.ifgr_groups); close(s); @@ -1856,7 +1857,7 @@ new_resolv_conf(char *ifname, char *domainname, char *nameservers) sizeof(imsg)); if (rslt == -1) - warning("new_resolv_conf: imsg_compose: %m"); + warning("new_resolv_conf: imsg_compose: %s", strerror(errno)); } void @@ -1870,14 +1871,15 @@ priv_resolv_conf(struct imsg_resolv_conf *imsg) O_WRONLY | O_CREAT | O_TRUNC | O_SYNC | O_EXLOCK, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (conffd == -1) { - note("Couldn't open resolv.conf: %m"); + note("Couldn't open resolv.conf: %s", strerror(errno)); return; } if (strlen(imsg->contents)) { n = write(conffd, imsg->contents, strlen(imsg->contents)); if (n == -1) - note("Couldn't write contents to resolv.conf: %m"); + note("Couldn't write contents to resolv.conf: %s", + strerror(errno)); else if (n == 0) note("Couldn't write contents to resolv.conf"); else if (n < strlen(imsg->contents)) @@ -1891,18 +1893,20 @@ priv_resolv_conf(struct imsg_resolv_conf *imsg) buf = calloc(1, MAXRESOLVCONFSIZE); if (tailfd == -1) - note("Couldn't open resolv.conf.tail: %m"); + note("Couldn't open resolv.conf.tail: %s", strerror(errno)); else { tailn = read(tailfd, buf, MAXRESOLVCONFSIZE - 1); close(tailfd); if (tailn == -1) - note("Couldn't read resolv.conf.tail: %m"); + note("Couldn't read resolv.conf.tail: %s", + strerror(errno)); else if (tailn == 0) note("Got no data from resolv.conf.tail"); else { n = write(conffd, buf, strlen(buf)); if (n == -1) - note("Couldn't write tail to resolv.conf: %m"); + note("Couldn't write tail to resolv.conf: %s", + strerror(errno)); else if (n == 0) note("Couldn't write tail to resolv.conf"); else if (n < strlen(buf)) @@ -2040,10 +2044,10 @@ socket_nonblockmode(int fd) int flags; if ((flags = fcntl(fd, F_GETFL, 0)) == -1) - error("fcntl F_GETF: %m"); + error("fcntl F_GETF: %s", strerror(errno)); flags |= O_NONBLOCK; if ((flags = fcntl(fd, F_SETFL, flags)) == -1) - error("fcntl F_SETFL: %m"); + error("fcntl F_SETFL: %s", strerror(errno)); } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 4315f3b5faa..5bf46c5cdb5 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.96 2012/12/02 17:03:19 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.97 2012/12/04 19:24:03 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -211,7 +211,7 @@ int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); #ifdef DEBUG int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); #endif -int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +int parse_warn(char *); /* conflex.c */ extern int lexline, lexchar; diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 81e73313717..86cecaa9d18 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.67 2012/11/24 18:06:14 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.68 2012/12/04 19:24:03 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -169,7 +169,7 @@ another: if (errno == EAGAIN || errno == EINTR) { continue; } else - error("poll: %m"); + error("poll: %s", strerror(errno)); } if ((fds[0].revents & (POLLIN | POLLHUP))) { @@ -230,7 +230,8 @@ interface_link_forceup(char *ifname) memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sock, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) { - note("interface_link_forceup: SIOCGIFFLAGS failed (%m)"); + note("interface_link_forceup: SIOCGIFFLAGS failed (%s)", + strerror(errno)); close(sock); return; } @@ -238,14 +239,16 @@ interface_link_forceup(char *ifname) /* Force it down and up so others notice link state change. */ ifr.ifr_flags &= ~IFF_UP; if (ioctl(sock, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) { - note("interface_link_forceup: SIOCSIFFLAGS DOWN failed (%m)"); + note("interface_link_forceup: SIOCSIFFLAGS DOWN failed (%s)", + strerror(errno)); close(sock); return; } ifr.ifr_flags |= IFF_UP; if (ioctl(sock, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) { - note("interface_link_forceup: SIOCSIFFLAGS UP failed (%m)"); + note("interface_link_forceup: SIOCSIFFLAGS UP failed (%s)", + strerror(errno)); close(sock); return; } @@ -267,7 +270,8 @@ interface_status(char *ifname) memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) { - error("ioctl(SIOCGIFFLAGS) on %s: %m", ifname); + error("ioctl(SIOCGIFFLAGS) on %s: %s", ifname, + strerror(errno)); } /* @@ -289,7 +293,8 @@ interface_status(char *ifname) */ #ifdef DEBUG if (errno != EINVAL && errno != ENOTTY) - debug("ioctl(SIOCGIFMEDIA) on %s: %m", ifname); + debug("ioctl(SIOCGIFMEDIA) on %s: %s", ifname, + strerror(errno)); #endif ifi->noifmedia = 1; @@ -340,7 +345,7 @@ get_rdomain(char *name) struct ifreq ifr; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - error("get_rdomain socket: %m"); + error("get_rdomain socket: %s", strerror(errno)); memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c index e7ddff58142..781df5875a6 100644 --- a/sbin/dhclient/errwarn.c +++ b/sbin/dhclient/errwarn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: errwarn.c,v 1.18 2012/11/15 14:54:18 krw Exp $ */ +/* $OpenBSD: errwarn.c,v 1.19 2012/12/04 19:24:03 krw Exp $ */ /* Errors and warnings... */ @@ -45,10 +45,7 @@ #include <sys/uio.h> -static void do_percentm(char *obuf, size_t size, char *ibuf); - static char mbuf[1024]; -static char fbuf[1024]; int warnings_occurred; @@ -60,10 +57,8 @@ error(char *fmt, ...) { va_list list; - do_percentm(fbuf, sizeof(fbuf), fmt); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fmt, list); va_end(list); #ifndef DEBUG @@ -90,10 +85,8 @@ warning(char *fmt, ...) { va_list list; - do_percentm(fbuf, sizeof(fbuf), fmt); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fmt, list); va_end(list); #ifndef DEBUG @@ -116,10 +109,8 @@ note(char *fmt, ...) { va_list list; - do_percentm(fbuf, sizeof(fbuf), fmt); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fmt, list); va_end(list); #ifndef DEBUG @@ -143,10 +134,8 @@ debug(char *fmt, ...) { va_list list; - do_percentm(fbuf, sizeof(fbuf), fmt); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fmt, list); va_end(list); syslog(LOG_DEBUG, "%s", mbuf); @@ -160,59 +149,16 @@ debug(char *fmt, ...) } #endif -/* - * Find %m in the input string and substitute an error message string. - */ -static void -do_percentm(char *obuf, size_t size, char *ibuf) -{ - char ch; - char *s = ibuf; - char *t = obuf; - int prlen; - size_t fmt_left; - int saved_errno = errno; - - /* - * We wouldn't need this mess if printf handled %m, or if - * strerror() had been invented before syslog(). - */ - for (fmt_left = size; (ch = *s); ++s) { - if (ch == '%' && s[1] == 'm') { - ++s; - prlen = snprintf(t, fmt_left, "%s", - strerror(saved_errno)); - if (prlen == -1) - prlen = 0; - else if (prlen >= fmt_left) - prlen = fmt_left - 1; - t += prlen; - fmt_left -= prlen; - } else { - if (fmt_left > 1) { - *t++ = ch; - fmt_left--; - } - } - } - *t = '\0'; -} - int -parse_warn(char *fmt, ...) +parse_warn(char *msg) { - va_list list; static char spaces[] = " " " "; /* 80 spaces */ struct iovec iov[6]; size_t iovcnt; - do_percentm(mbuf, sizeof(mbuf), fmt); - snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); + snprintf(mbuf, sizeof(mbuf), "%s line %d: %s", tlname, lexline, msg); #ifndef DEBUG syslog(LOG_ERR, "%s", mbuf); 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 diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c index 16e529d11c6..af0a3f008a3 100644 --- a/sbin/dhclient/privsep.c +++ b/sbin/dhclient/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.25 2012/12/02 17:03:19 krw Exp $ */ +/* $OpenBSD: privsep.c,v 1.26 2012/12/04 19:24:03 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -30,7 +30,8 @@ dispatch_imsg(struct imsgbuf *ibuf) for (;;) { if ((n = imsg_get(ibuf, &imsg)) == -1) - error("dispatch_imsg: imsg_get failure: %m"); + error("dispatch_imsg: imsg_get failure: %s", + strerror(errno)); if (n == 0) break; |