summaryrefslogtreecommitdiff
path: root/usr.sbin/dhcrelay
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-02-13 22:49:39 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-02-13 22:49:39 +0000
commita6dc8390db2f6845eca6f615f527524e8611ec9e (patch)
treec485706b369cff40430e94768dc9558133bb8158 /usr.sbin/dhcrelay
parent128c30ad3a3a7c7a1b63d94191b1bf912a6dc0fe (diff)
Eliminate pointless'%m' (a.k.a. hand rolled strerror()) by using fatal() and
log_warn(). Zap a couple of explicit 'syslog()' calls.
Diffstat (limited to 'usr.sbin/dhcrelay')
-rw-r--r--usr.sbin/dhcrelay/bpf.c23
-rw-r--r--usr.sbin/dhcrelay/dhcrelay.c35
-rw-r--r--usr.sbin/dhcrelay/dispatch.c10
3 files changed, 32 insertions, 36 deletions
diff --git a/usr.sbin/dhcrelay/bpf.c b/usr.sbin/dhcrelay/bpf.c
index 020810bba54..275d3074f07 100644
--- a/usr.sbin/dhcrelay/bpf.c
+++ b/usr.sbin/dhcrelay/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.16 2017/02/13 22:05:35 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.17 2017/02/13 22:49:38 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -73,12 +73,11 @@ if_register_bpf(struct interface_info *info)
/* Open the BPF device */
if ((sock = open("/dev/bpf0", O_RDWR)) == -1)
- fatalx("Can't open bpf device: %m");
+ fatal("Can't open bpf device");
/* Set the BPF device to point at this interface. */
if (ioctl(sock, BIOCSETIF, &info->ifr) == -1)
- fatalx("Can't attach interface %s to bpf device: %m",
- info->name);
+ fatal("Can't attach interface %s to bpf device", info->name);
return (sock);
}
@@ -270,7 +269,7 @@ if_register_receive(struct interface_info *info, int isserver)
/* Make sure the BPF version is in range... */
if (ioctl(info->rfdesc, BIOCVERSION, &v) == -1)
- fatalx("Can't get BPF version: %m");
+ fatal("Can't get BPF version");
if (v.bv_major != BPF_MAJOR_VERSION ||
v.bv_minor < BPF_MINOR_VERSION)
@@ -282,15 +281,15 @@ if_register_receive(struct interface_info *info, int isserver)
* with packets.
*/
if (ioctl(info->rfdesc, BIOCIMMEDIATE, &flag) == -1)
- fatalx("Can't set immediate mode on bpf device: %m");
+ fatal("Can't set immediate mode on bpf device");
/* make sure kernel fills in the source ethernet address */
if (ioctl(info->rfdesc, BIOCSHDRCMPLT, &cmplt) == -1)
- fatalx("Can't set header complete flag on bpf device: %m");
+ fatal("Can't set header complete flag on bpf device");
/* Get the required BPF buffer length from the kernel. */
if (ioctl(info->rfdesc, BIOCGBLEN, &sz) == -1)
- fatalx("Can't get bpf buffer length: %m");
+ fatal("Can't get bpf buffer length");
info->rbuf_max = sz;
info->rbuf = malloc(info->rbuf_max);
if (!info->rbuf)
@@ -311,7 +310,7 @@ if_register_receive(struct interface_info *info, int isserver)
p.bf_insns = dhcp_bpf_filter;
}
if (ioctl(info->rfdesc, BIOCSETF, &p) == -1)
- fatalx("Can't install packet filter program: %m");
+ fatal("Can't install packet filter program");
/* Set up the bpf write filter program structure. */
if (isserver) {
@@ -323,11 +322,11 @@ if_register_receive(struct interface_info *info, int isserver)
}
if (ioctl(info->rfdesc, BIOCSETWF, &p) == -1)
- fatalx("Can't install write filter program: %m");
+ fatal("Can't install write filter program");
/* make sure these settings cannot be changed after dropping privs */
if (ioctl(info->rfdesc, BIOCLOCK) == -1)
- fatalx("Failed to lock bpf descriptor: %m");
+ fatal("Failed to lock bpf descriptor");
}
ssize_t
@@ -359,7 +358,7 @@ send_packet(struct interface_info *interface,
result = writev(interface->wfdesc, iov, 2);
done:
if (result == -1)
- log_warnx("send_packet: %m");
+ log_warn("send_packet");
return (result);
}
diff --git a/usr.sbin/dhcrelay/dhcrelay.c b/usr.sbin/dhcrelay/dhcrelay.c
index fd4d19e727a..0b47acc99ae 100644
--- a/usr.sbin/dhcrelay/dhcrelay.c
+++ b/usr.sbin/dhcrelay/dhcrelay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcrelay.c,v 1.57 2017/02/13 22:05:35 krw Exp $ */
+/* $OpenBSD: dhcrelay.c,v 1.58 2017/02/13 22:49:38 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org>
@@ -220,7 +220,7 @@ main(int argc, char *argv[])
if (daemonize) {
devnull = open(_PATH_DEVNULL, O_RDWR, 0);
if (devnull == -1)
- fatalx("open(%s): %m", _PATH_DEVNULL);
+ fatal("open(%s)", _PATH_DEVNULL);
}
if (interfaces == NULL)
@@ -261,20 +261,20 @@ main(int argc, char *argv[])
sp->to.sin_len = sizeof sp->to;
sp->fd = socket(AF_INET, SOCK_DGRAM, 0);
if (sp->fd == -1)
- fatalx("socket: %m");
+ fatal("socket");
opt = 1;
if (setsockopt(sp->fd, SOL_SOCKET, SO_REUSEPORT,
&opt, sizeof(opt)) == -1)
- fatalx("setsockopt: %m");
+ fatal("setsockopt");
if (setsockopt(sp->fd, SOL_SOCKET, SO_RTABLE, &rdomain,
sizeof(rdomain)) == -1)
- fatalx("setsockopt: %m");
+ fatal("setsockopt");
if (bind(sp->fd, (struct sockaddr *)&laddr, sizeof laddr) ==
-1)
- fatalx("bind: %m");
+ fatal("bind");
if (connect(sp->fd, (struct sockaddr *)&sp->to,
sizeof sp->to) == -1)
- fatalx("connect: %m");
+ fatal("connect");
add_protocol("server", sp->fd, got_response, sp);
}
@@ -283,17 +283,17 @@ main(int argc, char *argv[])
laddr.sin_addr.s_addr = INADDR_ANY;
server_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (server_fd == -1)
- fatalx("socket: %m");
+ fatal("socket");
opt = 1;
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEPORT,
&opt, sizeof(opt)) == -1)
- fatalx("setsockopt: %m");
+ fatal("setsockopt");
if (setsockopt(server_fd, SOL_SOCKET, SO_RTABLE, &rdomain,
sizeof(rdomain)) == -1)
- fatalx("setsockopt: %m");
+ fatal("setsockopt");
if (bind(server_fd, (struct sockaddr *)&laddr,
sizeof(laddr)) == -1)
- fatalx("bind: %m");
+ fatal("bind");
}
tzset();
@@ -307,17 +307,17 @@ main(int argc, char *argv[])
if ((pw = getpwnam("_dhcp")) == NULL)
fatalx("user \"_dhcp\" not found");
if (chroot(_PATH_VAREMPTY) == -1)
- fatalx("chroot: %m");
+ fatal("chroot");
if (chdir("/") == -1)
- fatalx("chdir(\"/\"): %m");
+ fatal("chdir(\"/\")");
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatalx("can't drop privileges: %m");
+ fatal("can't drop privileges");
if (daemonize) {
if (rdaemon(devnull) == -1)
- fatalx("rdaemon: %m");
+ fatal("rdaemon");
log_perror = 0;
}
log_init(0, LOG_DAEMON); /* stop loggoing to stderr */
@@ -535,8 +535,7 @@ got_response(struct protocol *l)
* Ignore ECONNREFUSED as too many dhcp servers send a bogus
* icmp unreach for every request.
*/
- log_warnx("recv failed for %s: %m",
- inet_ntoa(sp->to.sin_addr));
+ log_warn("recv failed for %s", inet_ntoa(sp->to.sin_addr));
return;
}
if (result == -1 && errno == ECONNREFUSED)
@@ -862,7 +861,7 @@ get_rdomain(char *name)
struct ifreq ifr;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
- fatalx("get_rdomain socket: %m");
+ fatal("get_rdomain socket");
bzero(&ifr, sizeof(ifr));
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
diff --git a/usr.sbin/dhcrelay/dispatch.c b/usr.sbin/dhcrelay/dispatch.c
index 97d526d7420..1f075b6b54a 100644
--- a/usr.sbin/dhcrelay/dispatch.c
+++ b/usr.sbin/dhcrelay/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.18 2017/02/13 22:05:35 krw Exp $ */
+/* $OpenBSD: dispatch.c,v 1.19 2017/02/13 22:49:38 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -233,7 +233,7 @@ another:
continue;
}
else
- fatalx("poll: %m");
+ fatal("poll");
}
/* Get the current time... */
@@ -310,7 +310,7 @@ interface_status(struct interface_info *ifinfo)
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) == -1) {
- syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", ifname);
+ log_warn("ioctl(SIOCGIFFLAGS) on %s", ifname);
goto inactive;
}
/*
@@ -327,9 +327,7 @@ interface_status(struct interface_info *ifinfo)
strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) == -1) {
if (errno != EINVAL) {
- syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m",
- ifname);
-
+ log_debug("ioctl(SIOCGIFMEDIA) on %s", ifname);
ifinfo->noifmedia = 1;
goto active;
}