From a7a245c3697679343a22cfc596e3acb2335de5ba Mon Sep 17 00:00:00 2001 From: Chris Cappuccio Date: Thu, 27 May 2021 21:41:01 -0700 Subject: [PATCH] Explicitly include and alternate strerror_r usage for OpenBSD --- src/plugins/output/json/src/Sender.cpp | 8 +++++++- src/plugins/output/json/src/Server.cpp | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/plugins/output/json/src/Sender.cpp b/src/plugins/output/json/src/Sender.cpp index 883b25a3..60ba3faa 100644 --- a/src/plugins/output/json/src/Sender.cpp +++ b/src/plugins/output/json/src/Sender.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -230,7 +231,12 @@ Sender::send(const char *str, size_t len) // Connection failed char buffer[128]; +#ifdef __OpenBSD__ + char *err_str = buffer; + strerror_r(errno, buffer, 128); +#else const char *err_str = strerror_r(errno, buffer, 128); +#endif IPX_CTX_INFO(_ctx, "(Send output) Destination '%s:%" PRIu16 "' disconnected: %s", params.addr.c_str(), params.port, err_str); return SEND_FAILED; @@ -257,4 +263,4 @@ Sender::send(const char *str, size_t len) std::string tmp(ptr, todo); msg_rest.assign(tmp); return SEND_WOULDBLOCK; -} \ No newline at end of file +} diff --git a/src/plugins/output/json/src/Server.cpp b/src/plugins/output/json/src/Server.cpp index 4124a137..dd3e6c6a 100644 --- a/src/plugins/output/json/src/Server.cpp +++ b/src/plugins/output/json/src/Server.cpp @@ -40,6 +40,7 @@ #include "Server.hpp" #include #include +#include #include #include @@ -202,7 +203,12 @@ Server::thread_accept(void *context) } char buffer[128]; +#ifdef __OpenBSD__ + char *err_str = buffer; + strerror_r(errno, buffer, 128); +#else const char *err_str = strerror_r(errno, buffer, 128); +#endif IPX_CTX_ERROR(acc->ctx, "(Server output) select() - failed (%s)", err_str); break; } @@ -215,7 +221,12 @@ Server::thread_accept(void *context) new_fd = accept(acc->socket_fd, (struct sockaddr *) &client_addr, &sin_size); if (new_fd == -1) { char buffer[128]; +#ifdef __OpenBSD__ + char *err_str = buffer; + strerror_r(errno, buffer, 128); +#else const char *err_str = strerror_r(errno, buffer, 128); +#endif IPX_CTX_ERROR(acc->ctx, "(Server output) accept() - failed (%s)", err_str); continue; } @@ -271,7 +282,12 @@ Server::msg_send(const char *data, ssize_t len, client_t &client) // Connection failed char buffer[128]; +#ifdef __OpenBSD__ + char *err_str = buffer; + strerror_r(errno, buffer, 128); +#else const char *err_str = strerror_r(errno, buffer, 128); +#endif IPX_CTX_INFO(_ctx, "(Server output) Client disconnected: %s (%s)", get_client_desc(client.info).c_str(), err_str); return SEND_FAILED;