1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 14:55:37 +03:00

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.
This commit is contained in:
Lennart Poettering 2018-03-21 20:28:01 +01:00
parent 0f01c1f918
commit 6e741541ed
2 changed files with 12 additions and 21 deletions

View File

@ -86,6 +86,7 @@ typedef struct DHCPRequest {
} 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(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, int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
size_t length); size_t length);

View File

@ -786,18 +786,12 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
return 0; return 0;
r = server_send_offer(server, req, address); r = server_send_offer(server, req, address);
if (r < 0) { if (r < 0)
/* this only fails on critical errors */ /* this only fails on critical errors */
log_dhcp_server(server, "could not send offer: %s", return log_dhcp_server_errno(server, r, "Could not send offer: %m");
strerror(-r));
return r;
} else {
log_dhcp_server(server, "OFFER (0x%x)",
be32toh(req->message->xid));
return DHCP_OFFER;
}
break; log_dhcp_server(server, "OFFER (0x%x)", be32toh(req->message->xid));
return DHCP_OFFER;
} }
case DHCP_DECLINE: case DHCP_DECLINE:
log_dhcp_server(server, "DECLINE (0x%x): %s", be32toh(req->message->xid), strna(error_message)); 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); r = server_send_ack(server, req, address);
if (r < 0) { if (r < 0) {
/* this only fails on critical errors */ /* this only fails on critical errors */
log_dhcp_server(server, "could not send ack: %s", log_dhcp_server_errno(server, r, "Could not send ack: %m");
strerror(-r));
if (!existing_lease) if (!existing_lease)
dhcp_lease_free(lease); dhcp_lease_free(lease);
@ -914,18 +907,15 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
return DHCP_ACK; return DHCP_ACK;
} }
} else if (init_reboot) { } else if (init_reboot) {
r = server_send_nak(server, req); r = server_send_nak(server, req);
if (r < 0) { if (r < 0)
/* this only fails on critical errors */ /* this only fails on critical errors */
log_dhcp_server(server, "could not send nak: %s", return log_dhcp_server_errno(server, r, "Could not send nak: %m");
strerror(-r));
return r; log_dhcp_server(server, "NAK (0x%x)", be32toh(req->message->xid));
} else { return DHCP_NAK;
log_dhcp_server(server, "NAK (0x%x)",
be32toh(req->message->xid));
return DHCP_NAK;
}
} }
break; break;