diff --git a/src/flb_network.c b/src/flb_network.c index 5b62a697535..e96f2576045 100644 --- a/src/flb_network.c +++ b/src/flb_network.c @@ -49,6 +49,14 @@ #include #include +#ifdef FLB_SYSTEM_MACOS +#ifdef _GNU_SOURCE +#undef _GNU_SOURCE +#endif +/* Use POSIX version of strerror_r forcibly on macOS. */ +#include +#endif + #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP #endif @@ -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;