[LEDE-DEV] [PATCH] odhcpd: Replace strerror(errno) with %m format
Rosen Penev
rosenp at gmail.com
Sat Dec 16 19:55:04 PST 2017
Saves a few bytes.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
src/config.c | 2 +-
src/dhcpv4.c | 6 ++----
src/dhcpv6.c | 6 ++----
src/ndp.c | 7 +++----
src/netlink.c | 4 ++--
src/odhcpd.c | 4 ++--
src/router.c | 5 ++---
src/ubus.c | 2 +-
8 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/src/config.c b/src/config.c
index bb885d0..9bbb773 100644
--- a/src/config.c
+++ b/src/config.c
@@ -184,7 +184,7 @@ static int mkdir_p(char *dir, mode_t mask)
return 0;
if (ret)
- syslog(LOG_ERR, "mkdir(%s, %d) failed: %s\n", dir, mask, strerror(errno));
+ syslog(LOG_ERR, "mkdir(%s, %d) failed: %m\n", dir, mask);
return ret;
}
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index c367507..db5f138 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -86,8 +86,7 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable)
int sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
if (sock < 0) {
- syslog(LOG_ERR, "Failed to create DHCPv4 server socket: %s",
- strerror(errno));
+ syslog(LOG_ERR, "Failed to create DHCPv4 server socket: %m");
return -1;
}
@@ -110,8 +109,7 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable)
{INADDR_ANY}, {0}};
if (bind(sock, (struct sockaddr*)&bind_addr, sizeof(bind_addr))) {
- syslog(LOG_ERR, "Failed to open DHCPv4 server socket: %s",
- strerror(errno));
+ syslog(LOG_ERR, "Failed to open DHCPv4 server socket: %m");
return -1;
}
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index 462a85e..e092c10 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -53,8 +53,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable)
if (enable && iface->dhcpv6) {
int sock = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
if (sock < 0) {
- syslog(LOG_ERR, "Failed to create DHCPv6 server socket: %s",
- strerror(errno));
+ syslog(LOG_ERR, "Failed to create DHCPv6 server socket: %m");
return -1;
}
@@ -76,8 +75,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable)
0, IN6ADDR_ANY_INIT, 0};
if (bind(sock, (struct sockaddr*)&bind_addr, sizeof(bind_addr))) {
- syslog(LOG_ERR, "Failed to open DHCPv6 server socket: %s",
- strerror(errno));
+ syslog(LOG_ERR, "Failed to open DHCPv6 server socket: %m");
return -1;
}
diff --git a/src/ndp.c b/src/ndp.c
index d589066..72fd3bc 100644
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -62,7 +62,7 @@ int ndp_init(void)
// Open ICMPv6 socket
ping_socket = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
if (ping_socket < 0) {
- syslog(LOG_ERR, "Unable to open raw socket: %s", strerror(errno));
+ syslog(LOG_ERR, "Unable to open raw socket: %m");
return -1;
}
@@ -113,8 +113,7 @@ int ndp_setup_interface(struct interface *iface, bool enable)
int sock = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6));
if (sock < 0) {
- syslog(LOG_ERR, "Unable to open packet socket: %s",
- strerror(errno));
+ syslog(LOG_ERR, "Unable to open packet socket: %m");
ret = -1;
goto out;
}
@@ -126,7 +125,7 @@ int ndp_setup_interface(struct interface *iface, bool enable)
if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER,
&bpf_prog, sizeof(bpf_prog))) {
- syslog(LOG_ERR, "Failed to set BPF: %s", strerror(errno));
+ syslog(LOG_ERR, "Failed to set BPF: %m");
ret = -1;
goto out;
}
diff --git a/src/netlink.c b/src/netlink.c
index ca9376e..e9fd04a 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -58,13 +58,13 @@ int netlink_init(void)
{
rtnl_socket = create_socket(NETLINK_ROUTE);
if (!rtnl_socket) {
- syslog(LOG_ERR, "Unable to open nl socket: %s", strerror(errno));
+ syslog(LOG_ERR, "Unable to open nl socket: %m");
goto err;
}
rtnl_event.sock = create_socket(NETLINK_ROUTE);
if (!rtnl_event.sock) {
- syslog(LOG_ERR, "Unable to open nl event socket: %s", strerror(errno));
+ syslog(LOG_ERR, "Unable to open nl event socket: %m");
goto err;
}
diff --git a/src/odhcpd.c b/src/odhcpd.c
index 97a6de9..8c1273c 100644
--- a/src/odhcpd.c
+++ b/src/odhcpd.c
@@ -187,8 +187,8 @@ ssize_t odhcpd_send(int socket, struct sockaddr_in6 *dest,
ssize_t sent = sendmsg(socket, &msg, MSG_DONTWAIT);
if (sent < 0)
- syslog(LOG_NOTICE, "Failed to send to %s%%%s (%s)",
- ipbuf, iface->ifname, strerror(errno));
+ syslog(LOG_NOTICE, "Failed to send to %s%%%s (%m)",
+ ipbuf, iface->ifname);
else
syslog(LOG_DEBUG, "Sent %li bytes to %s%%%s",
(long)sent, ipbuf, iface->ifname);
diff --git a/src/router.c b/src/router.c
index c35cd12..f6d99a8 100644
--- a/src/router.c
+++ b/src/router.c
@@ -48,7 +48,7 @@ int router_init(void)
// Open ICMPv6 socket
int sock = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
if (sock < 0 && errno != EAFNOSUPPORT) {
- syslog(LOG_ERR, "Failed to open RAW-socket: %s", strerror(errno));
+ syslog(LOG_ERR, "Failed to open RAW-socket: %m");
return -1;
}
@@ -82,8 +82,7 @@ int router_init(void)
odhcpd_register(&router_event);
if (!(fp_route = fopen("/proc/net/ipv6_route", "r")))
- syslog(LOG_ERR, "Failed to open routing table: %s",
- strerror(errno));
+ syslog(LOG_ERR, "Failed to open routing table: %m");
netlink_add_netevent_handler(&router_netevent_handler);
diff --git a/src/ubus.c b/src/ubus.c
index 19b14be..6af5911 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -412,7 +412,7 @@ bool ubus_has_prefix(const char *name, const char *ifname)
int ubus_init(void)
{
if (!(ubus = ubus_connect(NULL))) {
- syslog(LOG_ERR, "Unable to connect to ubus: %s", strerror(errno));
+ syslog(LOG_ERR, "Unable to connect to ubus: %m");
return -1;
}
--
2.7.4
More information about the Lede-dev
mailing list