diff --git a/src/logger.cc b/src/logger.cc index 6ddbea9..9f1d4a5 100644 --- a/src/logger.cc +++ b/src/logger.cc @@ -80,17 +80,26 @@ std::string logger::format(const std::string& fmt, ...) return buf; } +// alpine has a broken definition for strerr_r +// see https://stackoverflow.com/questions/41953104/strerror-r-is-incorrectly-declared-on-alpine-linux + +std::string logger::err_str(int result, char *buff, int err) +{ + if (result) + sprintf(buff, "unknown error: %d", err); + return buff; +} + +std::string logger::err_str(char *result, char *buff, int err) +{ + return result; +} + + std::string logger::err() { char buf[2048]; - -#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE - if (strerror_r(errno, buf, sizeof(buf)) - return "Unknown error"; - return buf; -#else - return strerror_r(errno, buf, sizeof(buf)); -#endif + return logger::err_str(strerror_r(errno, buf, sizeof(buf)), buf, errno); } logger logger::error() diff --git a/src/logger.h b/src/logger.h index 7d3d7db..d8fa19e 100644 --- a/src/logger.h +++ b/src/logger.h @@ -74,6 +74,7 @@ public: static std::string err(); private: + int _pri; std::stringstream _ss; @@ -91,7 +92,9 @@ private: static int _max_pri; - + // fixes for strerr_r on alpine + static std::string err_str(int result, char *buff, int err); + static std::string err_str(char *result, char *buff, int err); }; NDPPD_NS_END