From 6e741541ed7109d736746dcefc11b5d119bc18fd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 21 Mar 2018 20:28:01 +0100 Subject: [PATCH] dhcp-server: introduce log_dhcp_server_errno() Sometimes we want to print the error number, hence do so properly, and avoid to use strerror() which is not reentrant. --- src/libsystemd-network/dhcp-server-internal.h | 1 + src/libsystemd-network/sd-dhcp-server.c | 32 +++++++------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h index 8b5620e138..f2ffb39e44 100644 --- a/src/libsystemd-network/dhcp-server-internal.h +++ b/src/libsystemd-network/dhcp-server-internal.h @@ -86,6 +86,7 @@ typedef struct DHCPRequest { } DHCPRequest; #define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__) +#define log_dhcp_server_errno(client, error, fmt, ...) log_internal(LOG_DEBUG, error, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__) int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, size_t length); diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index c947174b1c..ab86a86bb4 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -786,18 +786,12 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, return 0; r = server_send_offer(server, req, address); - if (r < 0) { + if (r < 0) /* this only fails on critical errors */ - log_dhcp_server(server, "could not send offer: %s", - strerror(-r)); - return r; - } else { - log_dhcp_server(server, "OFFER (0x%x)", - be32toh(req->message->xid)); - return DHCP_OFFER; - } + return log_dhcp_server_errno(server, r, "Could not send offer: %m"); - break; + log_dhcp_server(server, "OFFER (0x%x)", be32toh(req->message->xid)); + return DHCP_OFFER; } case DHCP_DECLINE: log_dhcp_server(server, "DECLINE (0x%x): %s", be32toh(req->message->xid), strna(error_message)); @@ -897,8 +891,7 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, r = server_send_ack(server, req, address); if (r < 0) { /* this only fails on critical errors */ - log_dhcp_server(server, "could not send ack: %s", - strerror(-r)); + log_dhcp_server_errno(server, r, "Could not send ack: %m"); if (!existing_lease) dhcp_lease_free(lease); @@ -914,18 +907,15 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, return DHCP_ACK; } + } else if (init_reboot) { r = server_send_nak(server, req); - if (r < 0) { + if (r < 0) /* this only fails on critical errors */ - log_dhcp_server(server, "could not send nak: %s", - strerror(-r)); - return r; - } else { - log_dhcp_server(server, "NAK (0x%x)", - be32toh(req->message->xid)); - return DHCP_NAK; - } + return log_dhcp_server_errno(server, r, "Could not send nak: %m"); + + log_dhcp_server(server, "NAK (0x%x)", be32toh(req->message->xid)); + return DHCP_NAK; } break;