X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_thread_safe.c;h=94af58b4a3586344024abc65fb9679e4ca87d177;hp=25732b4beb8bb9c723ef61d8a529d47b9b1b7dad;hb=19f031713115921bebf5949ce63926d66dd8c6a5;hpb=a5eb18ad8c70e530a2e28ed435a0f52da0f5bee0 diff --git a/src/rrd_thread_safe.c b/src/rrd_thread_safe.c index 25732b4..94af58b 100644 --- a/src/rrd_thread_safe.c +++ b/src/rrd_thread_safe.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3rc8 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010 * This file: Copyright 2003 Peter Stamfest * & Tobias Oetiker * Distributed under the GPL @@ -59,11 +59,38 @@ const char *rrd_strerror( int err) { rrd_context_t *ctx = rrd_get_context(); + char *ret = "unknown error"; - if (strerror_r(err, ctx->lib_errstr, sizeof(ctx->lib_errstr))) - return "strerror_r failed. sorry!"; - else - return ctx->lib_errstr; + *ctx->lib_errstr = '\0'; + + /* Even though POSIX/XSI requires "strerror_r" to return an "int", some + * systems (e.g. the GNU libc) return a "char *" _and_ ignore the second + * argument ... -tokkee */ +#ifdef STRERROR_R_CHAR_P + ret = strerror_r(err, ctx->lib_errstr, sizeof(ctx->lib_errstr)); + if ((! ret) || (*ret == '\0')) { + if (*ctx->lib_errstr != '\0') + ret = ctx->lib_errstr; + else { + /* according to the manpage this should not happen - + let's handle it somehow sanely anyway */ + snprintf(ctx->lib_errstr, sizeof(ctx->lib_errstr), + "unknown error %i - strerror_r did not return anything", + err); + ctx->lib_errstr[sizeof(ctx->lib_errstr) - 1] = '\0'; + ret = ctx->lib_errstr; + } + } +#else /* ! STRERROR_R_CHAR_P */ + if (strerror_r(err, ctx->lib_errstr, sizeof(ctx->lib_errstr))) { + snprintf(ctx->lib_errstr, sizeof(ctx->lib_errstr), + "unknown error %i - strerror_r returned with errno = %i", + err, errno); + ctx->lib_errstr[sizeof(ctx->lib_errstr) - 1] = '\0'; + } + ret = ctx->lib_errstr; +#endif + return ret; } #else #undef strerror