Skip to content

Commit

Permalink
Explicitly include <cerrno> and alternate strerror_r usage for OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowman committed May 28, 2021
1 parent f8c7bda commit a7a245c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/plugins/output/json/src/Sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <time.h>
#include <unistd.h>
#include <inttypes.h>
#include <cerrno>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -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;
Expand All @@ -257,4 +263,4 @@ Sender::send(const char *str, size_t len)
std::string tmp(ptr, todo);
msg_rest.assign(tmp);
return SEND_WOULDBLOCK;
}
}
16 changes: 16 additions & 0 deletions src/plugins/output/json/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "Server.hpp"
#include <stdexcept>
#include <cstring>
#include <cerrno>

#include <unistd.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a7a245c

Please sign in to comment.