summaryrefslogtreecommitdiffstats
path: root/src/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2017-04-09 08:44:16 +0100
committerRoy Marples <roy@marples.name>2017-04-09 08:44:16 +0100
commita7544e344dedcd8a97a0252663de8f789404e8fa (patch)
treefd80dab09183fc0bced47d7ab26b7fcd6ef13824 /src/if-bsd.c
parentce3ea7a52b7246b9ab1131b4030e8b843339c44e (diff)
downloaddhcpcd-a7544e344dedcd8a97a0252663de8f789404e8fa.tar.xz
logerr: errx with logging
Had a few complaints that the lastlog option was dropped. It's now been restored, but with a new way of logging which is the same as errx(3) as found on the BSD platforms but the output also goes to the logging option of choice. This allows the function to define the log priority for syslog and there is no more need to specify %m. In turn, this makes the code needed to write error messages a lot shorter than before. loginfo and logdebug have no optional x suffix because they are not meant to record errors, unlike logerr and logwarn.
Diffstat (limited to 'src/if-bsd.c')
-rw-r--r--src/if-bsd.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/if-bsd.c b/src/if-bsd.c
index f58dd2cb..dbbf4c1e 100644
--- a/src/if-bsd.c
+++ b/src/if-bsd.c
@@ -66,7 +66,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#if defined(OpenBSD) && OpenBSD >= 201411
@@ -84,6 +83,7 @@
#include "ipv4ll.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "route.h"
#include "sa.h"
@@ -155,7 +155,7 @@ if_opensockets_os(struct dhcpcd_ctx *ctx)
#ifdef ROUTE_MSGFILTER
if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER,
&msgfilter, sizeof(msgfilter)) == -1)
- syslog(LOG_ERR, "ROUTE_MSGFILTER: %m");
+ logerr(__func__);
#endif
return ctx->link_fd == -1 ? -1 : 0;
@@ -1058,8 +1058,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
ifr_sin->sin_family = AF_INET;
ifr_sin->sin_addr = addr;
if (ioctl(ctx->pf_inet_fd, SIOCGIFADDR, &ifr) == 0) {
- syslog(LOG_WARNING,
- "%s: ignored false RTM_DELADDR for %s",
+ logwarnx("%s: ignored false RTM_DELADDR for %s",
ifp->name, inet_ntoa(addr));
break;
}
@@ -1070,7 +1069,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
if (ifam->ifam_type == RTM_DELADDR)
addrflags = 0 ;
else if ((addrflags = if_addrflags(ifp, &addr, NULL)) == -1) {
- syslog(LOG_ERR, "%s: if_addrflags: %s: %m",
+ logerr("%s: if_addrflags: %s",
ifp->name, inet_ntoa(addr));
break;
}
@@ -1096,7 +1095,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
if (ifam->ifam_type == RTM_DELADDR)
addrflags = 0;
else if ((addrflags = if_addrflags6(ifp, &addr6, NULL)) == -1) {
- syslog(LOG_ERR, "%s: if_addrflags6: %m", ifp->name);
+ logerr("%s: if_addrflags6", ifp->name);
break;
}
#endif
@@ -1337,8 +1336,8 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
if (!(ctx->options & DHCPCD_TEST) &&
flags & ND6_IFF_AUTO_LINKLOCAL)
{
- syslog(LOG_DEBUG,
- "%s: disabling Kernel IPv6 auto link-local support",
+ logdebug("%s: disabling Kernel IPv6 auto "
+ "link-local support",
ifp->name);
flags &= ~ND6_IFF_AUTO_LINKLOCAL;
}
@@ -1355,8 +1354,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
if (!(ctx->options & DHCPCD_TEST) &&
flags & ND6_IFF_ACCEPT_RTADV)
{
- syslog(LOG_DEBUG,
- "%s: disabling Kernel IPv6 RA support",
+ logdebug("%s: disabling Kernel IPv6 RA support",
ifp->name);
flags &= ~ND6_IFF_ACCEPT_RTADV;
}
@@ -1373,15 +1371,13 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
if (nd.ndi.flags != (uint32_t)flags) {
if (ctx->options & DHCPCD_TEST) {
- syslog(LOG_WARNING,
- "%s: interface not IPv6 enabled",
+ logwarnx("%s: interface not IPv6 enabled",
ifp->name);
return -1;
}
nd.ndi.flags = (uint32_t)flags;
if (ioctl(s, SIOCSIFINFO_FLAGS, &nd) == -1) {
- syslog(LOG_ERR, "%s: SIOCSIFINFO_FLAGS: %m",
- ifp->name);
+ logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
return -1;
}
}
@@ -1391,14 +1387,14 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
* LLADDR auto configuration are disabled where applicable. */
#ifdef SIOCIFAFATTACH
if (af_attach(s, ifp, AF_INET6) == -1) {
- syslog(LOG_ERR, "%s: af_attach: %m", ifp->name);
+ logerr("%s: af_attach", ifp->name);
return -1;
}
#endif
#ifdef SIOCGIFXFLAGS
if (set_ifxflags(s, ifp) == -1) {
- syslog(LOG_ERR, "%s: set_ifxflags: %m", ifp->name);
+ logerr("%s: set_ifxflags", ifp->name);
return -1;
}
#endif
@@ -1424,14 +1420,14 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
#ifdef IPV6CTL_ACCEPT_RTADV
ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV);
if (ra == -1)
- /* The sysctl probably doesn't exist, but this isn't an
- * error as such so just log it and continue */
- syslog(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
- "IPV6CTL_ACCEPT_RTADV: %m");
+ if (errno == ENOENT)
+ ra = 0;
+ else
+ logerr("IPV6CTL_ACCEPT_RTADV");
else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
- syslog(LOG_DEBUG, "disabling Kernel IPv6 RA support");
+ logdebug("disabling Kernel IPv6 RA support");
if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) {
- syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
+ logerr("IPV6CTL_ACCEPT_RTADV");
return ra;
}
ra = 0;
@@ -1443,7 +1439,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
* and prefixes so the kernel does not expire prefixes
* and default routes we are trying to own. */
if (if_raflush(s) == -1)
- syslog(LOG_WARNING, "if_raflush: %m");
+ logwarn("if_raflush");
}
ctx->ra_global = ra;