const char *rrd_strerror( int err) { static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; rrd_context_t *ctx; ctx = rrd_get_context(); pthread_mutex_lock(&mtx); strncpy(ctx->lib_errstr, strerror(err), sizeof(ctx->lib_errstr)); ctx->lib_errstr[sizeof(ctx->lib_errstr) - 1] = '\0'; pthread_mutex_unlock(&mtx); return ctx->lib_errstr; }
const char *rrd_strerror( int err) { rrd_context_t *ctx; context_init_context(); ctx = rrd_get_context(); EnterCriticalSection(&CriticalSection); strncpy(ctx->lib_errstr, strerror(err), sizeof(ctx->lib_errstr)); ctx->lib_errstr[sizeof(ctx->lib_errstr) - 1] = '\0'; LeaveCriticalSection(&CriticalSection); return ctx->lib_errstr; }
const char *rrd_strerror( int err) { rrd_context_t *ctx = rrd_get_context(); char *ret = "unknown error"; *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 */ #if 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; }
/* * Called once per process to initialize the rrd lib. */ static ngx_int_t ngx_http_rrd_init_process(ngx_cycle_t *cycle) { ARG_START_KEY = ngx_hash_key(ARG_START.data, ARG_START.len); rrd_get_context(); ngx_log_error_core(NGX_LOG_DEBUG, cycle->log, 0, "rrd: init"); return NGX_OK; }