Skip to content

Commit

Permalink
strerror_r doesn't return a pointer on OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowman committed May 28, 2021
1 parent 1455916 commit fa4c71b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/plugins/output/json/src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ File::File(const struct cfg_file &cfg, ipx_ctx_t *ctx) : Output(cfg.name, ctx)
throw std::runtime_error("(File output) Rwlockattr initialization failed!");
}

#ifndef __OpenBSD__
if (pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) != 0) {
if (_thread->m_calg == calg::GZIP) {
gzclose((gzFile)_thread->file);
Expand All @@ -120,6 +121,7 @@ File::File(const struct cfg_file &cfg, ipx_ctx_t *ctx) : Output(cfg.name, ctx)
delete _thread;
throw std::runtime_error("(File output) Rwlockattr setkind failed!");
}
#endif

if (pthread_rwlock_init(&_thread->rwlock, &attr) != 0) {
if (_thread->m_calg == calg::GZIP) {
Expand Down Expand Up @@ -341,7 +343,12 @@ File::dir_create(ipx_ctx_t *ctx, const std::string &path)
default:
// Other errors
char buffer[128];
#ifdef __OpenBSD__
char *err_str = buffer;
strerror_r(errno, err_str, 128);
#else
const char *err_str = strerror_r(errno, buffer, 128);
#endif
IPX_CTX_ERROR(ctx, "(File output) Failed to create a directory %s (%s).",
aux_str.c_str(), err_str);
return 1;
Expand All @@ -356,7 +363,12 @@ 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];
#ifdef __OpenBSD__
char *err_str = buffer;
strerror_r(errno, err_str, 128);
#else
const char *err_str = strerror_r(errno, buffer, 128);
#endif
IPX_CTX_ERROR(ctx, "(File output) Failed to create a directory %s (%s).",
aux_str.c_str(), err_str);
return 1;
Expand Down Expand Up @@ -418,7 +430,12 @@ 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];
#ifdef __OpenBSD__
char *err_str = buffer;
strerror_r(errno, err_str, 128);
#else
const char *err_str = strerror_r(errno, buffer, 128);
#endif
IPX_CTX_ERROR(ctx, "Failed to create a flow file '%s' (%s).", file_name.c_str(), err_str);
return NULL;
}
Expand Down

0 comments on commit fa4c71b

Please sign in to comment.