diff --git a/src/plugins/output/json/src/File.cpp b/src/plugins/output/json/src/File.cpp index 17866ee1..9454e858 100644 --- a/src/plugins/output/json/src/File.cpp +++ b/src/plugins/output/json/src/File.cpp @@ -53,6 +53,7 @@ #include #include #include +#include /** * \brief Class constructor @@ -342,8 +343,21 @@ File::dir_create(ipx_ctx_t *ctx, const std::string &path) continue; default: // Other errors - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_ERROR(ctx, "(File output) Failed to create a directory %s (%s).", aux_str.c_str(), err_str); return 1; @@ -357,8 +371,21 @@ File::dir_create(ipx_ctx_t *ctx, const std::string &path) if (mkdir(aux_str.c_str(), mask) != 0) { // Failed to create directory - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_ERROR(ctx, "(File output) Failed to create a directory %s (%s).", aux_str.c_str(), err_str); return 1; @@ -419,8 +446,21 @@ File::file_create(ipx_ctx_t *ctx, const std::string &tmplt, const std::string &p } if (!file) { // Failed to create a flow file - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_ERROR(ctx, "Failed to create a flow file '%s' (%s).", file_name.c_str(), err_str); return NULL; } diff --git a/src/plugins/output/json/src/Sender.cpp b/src/plugins/output/json/src/Sender.cpp index 883b25a3..a1f918a3 100644 --- a/src/plugins/output/json/src/Sender.cpp +++ b/src/plugins/output/json/src/Sender.cpp @@ -229,8 +229,21 @@ Sender::send(const char *str, size_t len) } // Connection failed - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_INFO(_ctx, "(Send output) Destination '%s:%" PRIu16 "' disconnected: %s", params.addr.c_str(), params.port, err_str); return SEND_FAILED; @@ -257,4 +270,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..c0d87e69 100644 --- a/src/plugins/output/json/src/Server.cpp +++ b/src/plugins/output/json/src/Server.cpp @@ -47,6 +47,7 @@ #include #include #include +#include /** How many pending connections queue will hold */ #define BACKLOG (10) @@ -201,8 +202,21 @@ Server::thread_accept(void *context) continue; } - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_ERROR(acc->ctx, "(Server output) select() - failed (%s)", err_str); break; } @@ -214,8 +228,21 @@ Server::thread_accept(void *context) new_fd = accept(acc->socket_fd, (struct sockaddr *) &client_addr, &sin_size); if (new_fd == -1) { - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_ERROR(acc->ctx, "(Server output) accept() - failed (%s)", err_str); continue; } @@ -270,8 +297,21 @@ Server::msg_send(const char *data, ssize_t len, client_t &client) } // Connection failed - char buffer[128]; - const char *err_str = strerror_r(errno, buffer, 128); + int errno_save = errno; + locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); + const char *err_str; + if (loc == (locale_t)0) { + if (errno == ENOENT) { + loc = newlocale(LC_MESSAGES_MASK, "POSIX", (locale_t)0); + } + } + if (loc != (locale_t)0) { + err_str = strerror_l(errno_save, loc); + freelocale(loc); + } else { + err_str = "newlocale() failed"; + } + errno = errno_save; IPX_CTX_INFO(_ctx, "(Server output) Client disconnected: %s (%s)", get_client_desc(client.info).c_str(), err_str); return SEND_FAILED;