Skip to content

Commit 431b287

Browse files
cosmo0920edsiper
authored andcommitted
network: Fix int-conversion error by using POSIX version of strerror_r
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 1e2bb3e commit 431b287

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/flb_network.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
#include <monkey/mk_core.h>
5050
#include <ares.h>
5151

52+
#ifdef FLB_SYSTEM_MACOS
53+
#ifdef _GNU_SOURCE
54+
#undef _GNU_SOURCE
55+
#endif
56+
/* Use POSIX version of strerror_r forcibly on macOS. */
57+
#include <string.h>
58+
#endif
59+
5260
#ifndef SOL_TCP
5361
#define SOL_TCP IPPROTO_TCP
5462
#endif
@@ -524,7 +532,20 @@ static int net_connect_async(int fd,
524532
}
525533

526534
/* Connection is broken, not much to do here */
535+
#if ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
536+
(defined(_XOPEN_SOURCE) || _XOPEN_SOURCE - 0L >= 600L)) && \
537+
(!defined(_GNU_SOURCE))
538+
ret = strerror_r(error, so_error_buf, sizeof(so_error_buf));
539+
if (ret == 0) {
540+
str = so_error_buf;
541+
}
542+
else {
543+
flb_errno();
544+
return -1;
545+
}
546+
#else
527547
str = strerror_r(error, so_error_buf, sizeof(so_error_buf));
548+
#endif
528549
flb_error("[net] TCP connection failed: %s:%i (%s)",
529550
u->tcp_host, u->tcp_port, str);
530551
return -1;

0 commit comments

Comments
 (0)