Skip to content

Commit

Permalink
network: Fix int-conversion error by using POSIX version of strerror_r
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Mar 12, 2024
1 parent 1e2bb3e commit 431b287
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/flb_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
#include <monkey/mk_core.h>
#include <ares.h>

#ifdef FLB_SYSTEM_MACOS
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
/* Use POSIX version of strerror_r forcibly on macOS. */
#include <string.h>
#endif

#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif
Expand Down Expand Up @@ -524,7 +532,20 @@ static int net_connect_async(int fd,
}

/* Connection is broken, not much to do here */
#if ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
(defined(_XOPEN_SOURCE) || _XOPEN_SOURCE - 0L >= 600L)) && \
(!defined(_GNU_SOURCE))
ret = strerror_r(error, so_error_buf, sizeof(so_error_buf));
if (ret == 0) {
str = so_error_buf;
}
else {
flb_errno();
return -1;
}
#else
str = strerror_r(error, so_error_buf, sizeof(so_error_buf));
#endif
flb_error("[net] TCP connection failed: %s:%i (%s)",
u->tcp_host, u->tcp_port, str);
return -1;
Expand Down

0 comments on commit 431b287

Please sign in to comment.