/* * Misc private functions */ static void c_ipmi_error(c_ipmi_instance_t *st, const char *func, int status) { char errbuf[ERR_BUF_SIZE] = {0}; if (IPMI_IS_OS_ERR(status) || IPMI_IS_RMCPP_ERR(status) || IPMI_IS_IPMI_ERR(status)) { ipmi_get_error_string(status, errbuf, sizeof(errbuf)); } if (errbuf[0] == 0) { snprintf(errbuf, sizeof(errbuf), "Unknown error %#x", status); } errbuf[sizeof(errbuf) - 1] = '\0'; ERROR("ipmi plugin: %s failed for `%s`: %s", func, st->name, errbuf); } /* void c_ipmi_error */
char * ipmi_get_error_string(unsigned int err, char *buffer, unsigned int buf_len) { unsigned int len; char *err_type; if (err == 0) { strncpy(buffer, "Success (No error)", buf_len); return buffer; } if (IPMI_IS_OS_ERR(err)) { snprintf(buffer+4, buf_len-4, "%s", strerror(IPMI_GET_OS_ERR(err))); err_type = "OS: "; } else if (IPMI_IS_IPMI_ERR(err)) { ipmi_get_cc_string(IPMI_GET_IPMI_ERR(err), buffer+6, buf_len-6); err_type = "IPMI: "; } else if (IPMI_IS_RMCPP_ERR(err)) { int rmcpp_err = IPMI_GET_RMCPP_ERR(err); if ((rmcpp_err <= 0) && (rmcpp_err > 0x12)) rmcpp_err = 0x13; snprintf(buffer+7, buf_len-7, "%s (0x%02x)", rmcpp_error_codes[rmcpp_err - 1], IPMI_GET_RMCPP_ERR(err)); err_type = "RMCP+: "; } else if (IPMI_IS_SOL_ERR(err)) { int sol_err = IPMI_GET_SOL_ERR(err); if ((sol_err < 1) || (sol_err > 7)) sol_err = 7; strncpy(buffer+5, sol_error_codes[sol_err - 1], buf_len-5); err_type = "SoL: "; } else { strncpy(buffer+9, "Unknown", buf_len-9); err_type = "Unknown: "; } len = strlen(err_type); if (len > buf_len-1) { len = buf_len-1; buffer[buf_len-1] = '\0'; } memcpy(buffer, err_type, len); return buffer; }
int ipmi_get_error_string_len(unsigned int err) { if (err == 0) return(strlen("Success (No error)")); if (IPMI_IS_OS_ERR(err)) return strlen(strerror(IPMI_GET_OS_ERR(err))) + 5; else if (IPMI_IS_IPMI_ERR(err)) { return ipmi_get_cc_string_len(IPMI_GET_IPMI_ERR(err)) + 7; } else if (IPMI_IS_RMCPP_ERR(err)) { int rmcpp_err = IPMI_GET_RMCPP_ERR(err); if ((rmcpp_err <= 0) && (rmcpp_err > 0x12)) rmcpp_err = 0x13; return strlen(rmcpp_error_codes[rmcpp_err - 1]) + 15; } else if (IPMI_IS_SOL_ERR(err)) { int sol_err = IPMI_GET_SOL_ERR(err); if ((sol_err < 1) || (sol_err > 7)) sol_err = 7; return strlen(sol_error_codes[sol_err - 1]) + 6; } else { return strlen("Unknown") + 10; } }