From 4db9739e178bc1025a6f2addaa1d29dc5acd3648 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Thu, 6 Jan 2005 17:48:24 +0000 Subject: [PATCH] massive rework of many subsytems handle errors better and return status codes correctly --- ipmitool/configure.in | 28 +- ipmitool/doc/ipmitool.1 | 2 +- ipmitool/include/ipmitool/ipmi_fru.h | 2 +- ipmitool/include/ipmitool/ipmi_sdr.h | 16 +- ipmitool/lib/dimm_spd.c | 67 +- ipmitool/lib/helper.c | 15 +- ipmitool/lib/ipmi_channel.c | 184 +-- ipmitool/lib/ipmi_chassis.c | 405 +++--- ipmitool/lib/ipmi_event.c | 13 +- ipmitool/lib/ipmi_fru.c | 1143 ++++++++++------- ipmitool/lib/ipmi_lanp.c | 652 +++++----- ipmitool/lib/ipmi_mc.c | 199 +-- ipmitool/lib/ipmi_raw.c | 42 +- ipmitool/lib/ipmi_sdr.c | 1696 ++++++++++++++++---------- ipmitool/lib/ipmi_sel.c | 349 +++--- ipmitool/lib/ipmi_sensor.c | 4 +- ipmitool/src/ipmishell.c | 89 +- ipmitool/src/ipmitool.c | 327 +++-- ipmitool/src/plugins/Makefile.am | 4 +- ipmitool/src/plugins/ipmi_intf.c | 138 ++- ipmitool/src/plugins/lan/lan.c | 59 +- ipmitool/src/plugins/open/open.c | 63 +- 22 files changed, 3314 insertions(+), 2183 deletions(-) diff --git a/ipmitool/configure.in b/ipmitool/configure.in index 99bdfae..c8c509f 100644 --- a/ipmitool/configure.in +++ b/ipmitool/configure.in @@ -3,7 +3,7 @@ dnl autoconf for ipmitool dnl AC_INIT([src/ipmitool.c]) AC_CANONICAL_SYSTEM -AM_INIT_AUTOMAKE([ipmitool], [1.6.2]) +AM_INIT_AUTOMAKE([ipmitool], [1.6.2pre8]) AM_CONFIG_HEADER(config.h) AC_CONFIG_SRCDIR([src/ipmitool.c]) AC_PREREQ(2.50) @@ -59,6 +59,7 @@ solaris*) LD=gld AR=gar # disable the linux-specific interfaces + enable_intf_bmc=yes enable_intf_imb=no enable_intf_open=no enable_ipmievd=no @@ -192,22 +193,37 @@ dnl enable Solaris LIPMI interface AC_CHECK_HEADER([sys/lipmi/lipmi_intf.h], [have_lipmi=yes], [have_lipmi=no]) AC_ARG_ENABLE([intf-lipmi], [AC_HELP_STRING([--enable-intf-lipmi], - [enable Solaris x86 IPMI interface [default=auto]])], + [enable Solaris 9 x86 IPMI interface [default=no]])], [if test "x$enable_intf_lipmi" != "xno" && test "x$have_lipmi" != "xyes"; then - echo "** Unable to build Solaris x86 IPMI interface support!" + echo "** Unable to build Solaris 9 x86 IPMI interface support!" enable_intf_lipmi=no fi], - [enable_intf_lipmi=$have_lipmi]) + [enable_intf_lipmi=no]) if test "x$enable_intf_lipmi" = "xstatic" || test "x$enable_intf_lipmi" = "xplugin"; then enable_intf_lipmi=yes fi if test "x$enable_intf_lipmi" = "xyes"; then - AC_DEFINE(IPMI_INTF_LIPMI, [1], [Define to 1 to enable Solaris LIPMI interface.]) + AC_DEFINE(IPMI_INTF_LIPMI, [1], [Define to 1 to enable Solaris 9 LIPMI interface.]) AC_SUBST(INTF_LIPMI, [lipmi]) AC_SUBST(INTF_LIPMI_LIB, [libintf_lipmi.la]) IPMITOOL_INTF_LIB="$IPMITOOL_INTF_LIB lipmi/libintf_lipmi.la" fi +dnl enable Solaris BMC interface +AC_ARG_ENABLE([intf-bmc], + [AC_HELP_STRING([--enable-intf-bmc], + [enable Solaris 10 x86 IPMI interface [default=no]])],, + [enable_intf_bmc=no]) +if test "x$enable_intf_bmc" = "xstatic" || test "x$enable_intf_bmc" = "xplugin"; then + enable_intf_bmc=yes +fi +if test "x$enable_intf_bmc" = "xyes"; then + AC_DEFINE(IPMI_INTF_BMC, [1], [Define to 1 to enable Solaris 10 BMC interface.]) + AC_SUBST(INTF_BMC, [bmc]) + AC_SUBST(INTF_BMC_LIB, [libintf_bmc.la]) + IPMITOOL_INTF_LIB="$IPMITOOL_INTF_LIB bmc/libintf_bmc.la" +fi + AC_SUBST(IPMITOOL_INTF_LIB) dnl check for readline library to enable ipmi shell @@ -260,6 +276,7 @@ AC_CONFIG_FILES([Makefile src/plugins/lanplus/Makefile src/plugins/open/Makefile src/plugins/imb/Makefile + src/plugins/bmc/Makefile src/plugins/lipmi/Makefile]) AC_OUTPUT @@ -272,6 +289,7 @@ AC_MSG_RESULT([ lan : $enable_intf_lan]) AC_MSG_RESULT([ lanplus : $enable_intf_lanplus]) AC_MSG_RESULT([ open : $enable_intf_open]) AC_MSG_RESULT([ imb : $enable_intf_imb]) +AC_MSG_RESULT([ bmc : $enable_intf_bmc]) AC_MSG_RESULT([ lipmi : $enable_intf_lipmi]) AC_MSG_RESULT([]) AC_MSG_RESULT([Extra tools]) diff --git a/ipmitool/doc/ipmitool.1 b/ipmitool/doc/ipmitool.1 index cb6626d..e51ac7f 100644 --- a/ipmitool/doc/ipmitool.1 +++ b/ipmitool/doc/ipmitool.1 @@ -41,7 +41,7 @@ Remote server address, can be IP address or hostname. This option is required f Remote username, default is NULL user. .TP \fB\-L\fR <\fIprivlvl\fP> -Force sessin privilege level. Can be CALLBACK, USER, OPERATOR, ADMIN. Default is USER. +Force sessin privilege level. Can be CALLBACK, USER, OPERATOR, ADMIN. Default is ADMIN. .TP \fB\-a\fR Promt for the remote server password, 16 character maximum. This is optional for the LAN interface, if a password is not provided the session will not be authenticated. diff --git a/ipmitool/include/ipmitool/ipmi_fru.h b/ipmitool/include/ipmitool/ipmi_fru.h index 35205a5..4d1e1ac 100644 --- a/ipmitool/include/ipmitool/ipmi_fru.h +++ b/ipmitool/include/ipmitool/ipmi_fru.h @@ -223,6 +223,6 @@ static const char * chassis_type_desc[] __attribute__((unused)) = { }; int ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv); -void ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru); +int ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru); #endif /* IPMI_FRU_H */ diff --git a/ipmitool/include/ipmitool/ipmi_sdr.h b/ipmitool/include/ipmitool/ipmi_sdr.h index ee3272f..e05e633 100644 --- a/ipmitool/include/ipmitool/ipmi_sdr.h +++ b/ipmitool/include/ipmitool/ipmi_sdr.h @@ -589,20 +589,20 @@ struct ipmi_sdr_iterator * ipmi_sdr_start(struct ipmi_intf * intf); struct sdr_get_rs * ipmi_sdr_get_next_header(struct ipmi_intf * intf, struct ipmi_sdr_iterator * i); unsigned char * ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header, struct ipmi_sdr_iterator * i); void ipmi_sdr_end(struct ipmi_intf * intf, struct ipmi_sdr_iterator * i); -void ipmi_sdr_print_sdr(struct ipmi_intf * intf, unsigned char type); -void ipmi_sdr_print_rawentry(struct ipmi_intf * intf, unsigned char type, unsigned char * raw, int len); -void ipmi_sdr_print_listentry(struct ipmi_intf * intf, struct sdr_record_list * entry); +int ipmi_sdr_print_sdr(struct ipmi_intf * intf, unsigned char type); +int ipmi_sdr_print_rawentry(struct ipmi_intf * intf, unsigned char type, unsigned char * raw, int len); +int ipmi_sdr_print_listentry(struct ipmi_intf * intf, struct sdr_record_list * entry); const char * ipmi_sdr_get_status(unsigned char stat); float sdr_convert_sensor_reading(struct sdr_record_full_sensor * sensor, unsigned char val); unsigned char sdr_convert_sensor_value_to_raw(struct sdr_record_full_sensor * sensor, float val); struct ipmi_rs * ipmi_sdr_get_sensor_reading(struct ipmi_intf * intf, unsigned char sensor); const char * ipmi_sdr_get_sensor_type_desc(const unsigned char type); -void ipmi_sdr_print_sensor_full(struct ipmi_intf * intf, struct sdr_record_full_sensor * sensor); -void ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf, struct sdr_record_compact_sensor * sensor); -void ipmi_sdr_print_sensor_eventonly(struct ipmi_intf * intf, struct sdr_record_eventonly_sensor * sensor); -void ipmi_sdr_print_fru_locator(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru); -void ipmi_sdr_print_mc_locator(struct ipmi_intf * intf, struct sdr_record_mc_locator * mc); +int ipmi_sdr_print_sensor_full(struct ipmi_intf * intf, struct sdr_record_full_sensor * sensor); +int ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf, struct sdr_record_compact_sensor * sensor); +int ipmi_sdr_print_sensor_eventonly(struct ipmi_intf * intf, struct sdr_record_eventonly_sensor * sensor); +int ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru); +int ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf * intf, struct sdr_record_mc_locator * mc); struct sdr_record_list * ipmi_sdr_find_sdr_byentity(struct ipmi_intf * intf, struct entity_id * entity); struct sdr_record_list * ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf * intf, unsigned char num, unsigned char type); diff --git a/ipmitool/lib/dimm_spd.c b/ipmitool/lib/dimm_spd.c index 5156870..d8b3c90 100644 --- a/ipmitool/lib/dimm_spd.c +++ b/ipmitool/lib/dimm_spd.c @@ -35,6 +35,8 @@ */ #include +#include +#include #include #include @@ -670,7 +672,8 @@ const struct valstr jedec_id5_vals[] = { { 0x00, NULL }, }; -void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id) +int +ipmi_spd_print(struct ipmi_intf * intf, unsigned char id) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -687,14 +690,26 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) - return; + if (rsp == NULL) { + printf(" Device not present (No Response)\n"); + return -1; + } + if (rsp->ccode > 0) { + printf(" Device not present (%s)\n", + val2str(rsp->ccode, completion_code_vals)); + return -1; + } + fru.size = (rsp->data[1] << 8) | rsp->data[0]; fru.access = rsp->data[2] & 0x1; - if (verbose > 1) - printf("fru.size = %d bytes (accessed by %s)\n", - fru.size, fru.access ? "words" : "bytes"); + lprintf(LOG_DEBUG, "fru.size = %d bytes (accessed by %s)", + fru.size, fru.access ? "words" : "bytes"); + + if (fru.size < 1) { + lprintf(LOG_ERR, " Invalid FRU size %d", fru.size); + return -1; + } memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_STORAGE; @@ -711,14 +726,14 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id) msg_data[3] = 32; rsp = intf->sendrecv(intf, &req); - if (!rsp) { + if (rsp == NULL) { printf(" Device not present (No Response)\n"); - return; + return -1; } - if(rsp->ccode) { + if (rsp->ccode > 0) { printf(" Device not present (%s)\n", val2str(rsp->ccode, completion_code_vals)); - return; + return -1; } len = rsp->data[0]; @@ -726,33 +741,43 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id) offset += len; } while (offset < fru.size); - if (verbose) + if (verbose > 1) printbuf(spd_data, offset, "SPD DATA"); if (offset < 92) - return; /* we need first 91 bytes to do our thing */ + return -1; /* we need first 91 bytes to do our thing */ size = spd_data[5] * (spd_data[31] << 2); printf(" Memory Size : %d MB\n", size); - printf(" Memory Type : %s\n", val2str(spd_data[2], spd_memtype_vals)); - printf(" Voltage Intf : %s\n", val2str(spd_data[8], spd_voltage_vals)); - printf(" Error Detect/Cor : %s\n", val2str(spd_data[11], spd_config_vals)); + printf(" Memory Type : %s\n", + val2str(spd_data[2], spd_memtype_vals)); + printf(" Voltage Intf : %s\n", + val2str(spd_data[8], spd_voltage_vals)); + printf(" Error Detect/Cor : %s\n", + val2str(spd_data[11], spd_config_vals)); /* handle jedec table bank continuation values */ printf(" Manufacturer : "); if (spd_data[64] != 0x7f) - printf("%s\n", val2str(spd_data[64], jedec_id1_vals)); + printf("%s\n", + val2str(spd_data[64], jedec_id1_vals)); else { if (spd_data[65] != 0x7f) - printf("%s\n", val2str(spd_data[65], jedec_id2_vals)); + printf("%s\n", + val2str(spd_data[65], jedec_id2_vals)); else { if (spd_data[66] != 0x7f) - printf("%s\n", val2str(spd_data[66], jedec_id3_vals)); + printf("%s\n", + val2str(spd_data[66], jedec_id3_vals)); else { if (spd_data[67] != 0x7f) - printf("%s\n", val2str(spd_data[67], jedec_id4_vals)); + printf("%s\n", + val2str(spd_data[67], + jedec_id4_vals)); else - printf("%s\n", val2str(spd_data[68], jedec_id5_vals)); + printf("%s\n", + val2str(spd_data[68], + jedec_id5_vals)); } } } @@ -763,4 +788,6 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id) part[18] = 0; printf(" Part Number : %s\n", part); } + + return 0; } diff --git a/ipmitool/lib/helper.c b/ipmitool/lib/helper.c index 27e6943..a98fc9e 100644 --- a/ipmitool/lib/helper.c +++ b/ipmitool/lib/helper.c @@ -47,6 +47,8 @@ #include +extern int verbose; + uint32_t buf2long(unsigned char * buf) { return (uint32_t)(buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]); @@ -79,16 +81,19 @@ void printbuf(const unsigned char * buf, int len, const char * desc) { int i; - if (!len) + if (len <= 0) return; - printf("%s (%d bytes)\n", desc, len); + if (verbose < 1) + return; + + fprintf(stderr, "%s (%d bytes)\n", desc, len); for (i=0; i #include #include +#include #include #include #include @@ -61,23 +62,19 @@ void printf_channel_usage (void); * Create a string describing the supported authentication types as * specificed by the parameter n */ -const char * ipmi_1_5_authtypes(unsigned char n) +static const char * +ipmi_1_5_authtypes(unsigned char n) { unsigned int i; static char supportedTypes[128]; bzero(supportedTypes, 128); - i = 0; - while (ipmi_authtype_vals[i].val) - { - if (n & ipmi_authtype_vals[i].val) - { + for (i = 0; ipmi_authtype_vals[i].val != 0; i++) { + if (n & ipmi_authtype_vals[i].val) { strcat(supportedTypes, ipmi_authtype_vals[i].str); strcat(supportedTypes, " "); } - - ++i; } return supportedTypes; @@ -91,16 +88,16 @@ const char * ipmi_1_5_authtypes(unsigned char n) * return 0 on success * -1 on failure */ -int ipmi_get_channel_auth_cap(struct ipmi_intf * intf, - unsigned char channel, - unsigned char priv) +int +ipmi_get_channel_auth_cap(struct ipmi_intf * intf, + unsigned char channel, + unsigned char priv) { struct ipmi_rs * rsp; struct ipmi_rq req; struct get_channel_auth_cap_rsp auth_cap; - - unsigned char msg_data[2]; + msg_data[0] = channel | 0x80; // Ask for IPMI v2 data as well msg_data[1] = priv; @@ -112,8 +109,7 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf, rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) - { + if ((rsp == NULL) || (rsp->ccode > 0)) { /* * It's very possible that this failed because we asked for IPMI v2 data * Ask again, without requesting IPMI v2 data @@ -121,16 +117,19 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf, msg_data[0] &= 0x7F; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { - printf("Error:%x Get Channel Authentication Capabilities Command (0x%x)\n", - rsp ? rsp->ccode : 0, channel); + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get Channel Authentication Capabilities"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Channel Authentication Capabilities failed: %s", + val2str(rsp->ccode, completion_code_vals)); return -1; } } memcpy(&auth_cap, rsp->data, sizeof(struct get_channel_auth_cap_rsp)); - printf("Channel number : %d\n", auth_cap.channel_number); printf("IPMI v1.5 auth types : %s\n", @@ -152,8 +151,7 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf, printf("Anonymous login enabled : %s\n", (auth_cap.anon_login_enabled) ? "yes" : "no"); - if (auth_cap.v20_data_available) - { + if (auth_cap.v20_data_available) { printf("Channel supports IPMI v1.5 : %s\n", (auth_cap.ipmiv15_support) ? "yes" : "no"); printf("Channel supports IPMI v2.0 : %s\n", @@ -164,8 +162,7 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf, * If there is support for an OEM authentication type, there is some * information. */ - if (auth_cap.enabled_auth_types & IPMI_1_5_AUTH_TYPE_BIT_OEM) - { + if (auth_cap.enabled_auth_types & IPMI_1_5_AUTH_TYPE_BIT_OEM) { printf("IANA Number for OEM : %d\n", auth_cap.oem_id[0] | auth_cap.oem_id[1] << 8 | @@ -202,17 +199,18 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - - if (!rsp || rsp->ccode) { - printf("Error:%x Get Channel Info Command (0x%x)\n", - rsp ? rsp->ccode : 0, channel); + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get Channel Info"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Channel Info failed: %s", + val2str(rsp->ccode, completion_code_vals)); return -1; } - memcpy(&channel_info, rsp->data, sizeof(struct get_channel_info_rsp)); - printf("Channel 0x%x info:\n", channel_info.channel_number); printf(" Channel Medium Type : %s\n", @@ -260,7 +258,13 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel) req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get Channel Access (volatile)"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Channel Access (volatile) failed: %s", + val2str(rsp->ccode, completion_code_vals)); return -1; } @@ -298,7 +302,13 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel) rqdata[1] = 0x40; /* 0x40=non-volatile */ rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get Channel Access (non-volatile)"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Channel Access (non-volatile) failed: %s", + val2str(rsp->ccode, completion_code_vals)); return -1; } @@ -331,7 +341,7 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel) break; } - return 0; + return 0; } static int @@ -345,7 +355,7 @@ ipmi_get_user_access(struct ipmi_intf * intf, unsigned char channel, unsigned ch ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN); - curr_uid = userid ? userid : 1; + curr_uid = userid ? : 1; memset(&req1, 0, sizeof(req1)); req1.msg.netfn = IPMI_NETFN_APP; @@ -365,39 +375,53 @@ ipmi_get_user_access(struct ipmi_intf * intf, unsigned char channel, unsigned ch rqdata[1] = curr_uid & 0x3f; rsp = intf->sendrecv(intf, &req1); - if (!rsp || rsp->ccode) { - printf("Error:%x Get User Access Command (0x%x)\n", - rsp ? rsp->ccode : 0, channel); + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get User Access (channel %d id %d)", + rqdata[0], rqdata[1]); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get User Access (channel %d id %d) failed: %s", + rqdata[0], rqdata[1], + val2str(rsp->ccode, completion_code_vals)); return -1; } memcpy(&user_access, rsp->data, sizeof(struct get_user_access_rsp)); - rqdata[0] = curr_uid & 0x3f; rsp = intf->sendrecv(intf, &req2); - if (!rsp || rsp->ccode) { - printf("Error:%x Get User Name Command (0x%x)\n", - rsp ? rsp->ccode : 0, channel); + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get User Name (id %d)", rqdata[0]); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get User Name (id %d) failed: %s", + rqdata[0], val2str(rsp->ccode, completion_code_vals)); return -1; } - if (init) - { + if (init) { printf("Maximum User IDs : %d\n", user_access.max_user_ids); printf("Enabled User IDs : %d\n", user_access.enabled_user_ids); max_uid = user_access.max_user_ids; init = 0; } - printf("\nUser ID : %d\n", curr_uid); + printf("\n"); + printf("User ID : %d\n", curr_uid); printf("User Name : %s\n", rsp->data); - printf("Fixed Name : %s\n", curr_uid <= user_access.fixed_user_ids ? "Yes" : "No"); - printf("Access Available : %s\n", user_access.callin_callback ? "callback" : "call-in / callback"); - printf("Link Authentication : %sabled\n", user_access.link_auth ? "en" : "dis"); - printf("IPMI Messaging : %sabled\n", user_access.ipmi_messaging ? "en" : "dis"); - printf("Privilege Level : %s\n", val2str(user_access.privilege_limit, ipmi_privlvl_vals)); + printf("Fixed Name : %s\n", + (curr_uid <= user_access.fixed_user_ids) ? "Yes" : "No"); + printf("Access Available : %s\n", + (user_access.callin_callback) ? "callback" : "call-in / callback"); + printf("Link Authentication : %sabled\n", + (user_access.link_auth) ? "en" : "dis"); + printf("IPMI Messaging : %sabled\n", + (user_access.ipmi_messaging) ? "en" : "dis"); + printf("Privilege Level : %s\n", + val2str(user_access.privilege_limit, ipmi_privlvl_vals)); curr_uid ++; @@ -406,7 +430,7 @@ ipmi_get_user_access(struct ipmi_intf * intf, unsigned char channel, unsigned ch return 0; } -static void +static int ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv) { unsigned char channel, userid; @@ -419,9 +443,9 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv) ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN); - if (argc < 3 || !strncmp(argv[0], "help", 4)) { + if ((argc < 3) || (strncmp(argv[0], "help", 4) == 0)) { printf_channel_usage(); - return; + return 0; } channel = (unsigned char)strtol(argv[0], NULL, 0); @@ -437,10 +461,16 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv) rqdata[1] = userid & 0x3f; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { - printf("Error:%x Get User Access Command (0x%x)\n", - rsp ? rsp->ccode : 0, channel); - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Get User Access (channel %d id %d)", + rqdata[0], rqdata[1]); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get User Access (channel %d id %d) failed: %s", + rqdata[0], rqdata[1], + val2str(rsp->ccode, completion_code_vals)); + return -1; } memcpy(&user_access, rsp->data, sizeof(struct get_user_access_rsp)); @@ -456,21 +486,21 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv) for (i = 2; i < argc; i ++) { - if (!strncmp(argv[i], "callin=", 7)) { - set_access.callin_callback = !strncmp (argv[i]+7, "off", 3); + if (strncmp(argv[i], "callin=", 7) == 0) { + set_access.callin_callback = !(strncmp (argv[i]+7, "off", 3)); } - else if (!strncmp(argv[i], "link=", 5)) { + else if (strncmp(argv[i], "link=", 5) == 0) { set_access.link_auth = strncmp (argv[i]+5, "off", 3); } - else if (!strncmp(argv[i], "ipmi=", 5)) { + else if (strncmp(argv[i], "ipmi=", 5) == 0) { set_access.ipmi_messaging = strncmp (argv[i]+5, "off", 3); } - else if (!strncmp(argv[i], "privilege=", 10)) { + else if (strncmp(argv[i], "privilege=", 10) == 0) { set_access.privilege_limit = strtol (argv[i]+10, NULL, 0); } else { printf ("Invalid option: %s\n", argv [i]); - return; + return -1; } } @@ -481,13 +511,19 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { - printf("Error:%x Set User Access Command (0x%x)\n", - rsp ? rsp->ccode : 0, channel); - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to Set User Access (channel %d id %d)", + set_access.channel, set_access.user_id); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Set User Access (channel %d id %d) failed: %s", + set_access.channel, set_access.user_id, + val2str(rsp->ccode, completion_code_vals)); + return -1; } - return; + return 0; } void @@ -513,11 +549,11 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv) { int retval = 0; - if (!argc || !strncmp(argv[0], "help", 4)) + if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0)) { printf_channel_usage(); } - else if (!strncmp(argv[0], "authcap", 7)) + else if (strncmp(argv[0], "authcap", 7) == 0) { if (argc != 3) printf_channel_usage(); @@ -526,9 +562,9 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv) (unsigned char)strtol(argv[1], NULL, 0), (unsigned char)strtol(argv[2], NULL, 0)); } - else if (!strncmp(argv[0], "getaccess", 10)) + else if (strncmp(argv[0], "getaccess", 10) == 0) { - if (argc < 2 || argc > 3) + if ((argc < 2) || (argc > 3)) printf_channel_usage(); else { unsigned char ch = (unsigned char)strtol(argv[1], NULL, 0); @@ -538,11 +574,11 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv) retval = ipmi_get_user_access(intf, ch, id); } } - else if (!strncmp(argv[0], "setaccess", 9)) + else if (strncmp(argv[0], "setaccess", 9) == 0) { - ipmi_set_user_access(intf, argc-1, &(argv[1])); + retval = ipmi_set_user_access(intf, argc-1, &(argv[1])); } - else if (!strncmp(argv[0], "info", 4)) + else if (strncmp(argv[0], "info", 4) == 0) { if (argc > 2) printf_channel_usage(); @@ -557,7 +593,7 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv) { printf("Invalid CHANNEL command: %s\n", argv[0]); printf_channel_usage(); - retval = 1; + retval = -1; } return retval; diff --git a/ipmitool/lib/ipmi_chassis.c b/ipmitool/lib/ipmi_chassis.c index a10f92e..0fbc13a 100644 --- a/ipmitool/lib/ipmi_chassis.c +++ b/ipmitool/lib/ipmi_chassis.c @@ -40,12 +40,14 @@ #include #include +#include #include #include extern int verbose; -static int ipmi_chassis_power_status(struct ipmi_intf * intf) +static int +ipmi_chassis_power_status(struct ipmi_intf * intf) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -56,14 +58,19 @@ static int ipmi_chassis_power_status(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { - printf("error in Chassis Status Command\n"); - return 0; + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to get Chassis Power Status"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Chassis Power Status failed: %s", + val2str(rsp->ccode, completion_code_vals)); + return -1; } printf("Chassis Power is %s\n", (rsp->data[0] & 0x1) ? "on" : "off"); - return rsp->data[0] & 0x1; + return 0; } static const struct valstr ipmi_chassis_power_control_vals[] = { @@ -76,7 +83,8 @@ static const struct valstr ipmi_chassis_power_control_vals[] = { { 0x00, NULL }, }; -static void ipmi_chassis_power_control(struct ipmi_intf * intf, unsigned char ctl) +static int +ipmi_chassis_power_control(struct ipmi_intf * intf, unsigned char ctl) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -90,18 +98,29 @@ static void ipmi_chassis_power_control(struct ipmi_intf * intf, unsigned char ct req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - - if (!rsp || rsp->ccode) { - printf("Unable to set Chassis Power Control to %s\n", - val2str(ctl, ipmi_chassis_power_control_vals)); - } else { - printf("Chassis Power Control: %s\n", - val2str(ctl, ipmi_chassis_power_control_vals)); - intf->abort = 1; + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to set Chassis Power Control to %s", + val2str(ctl, ipmi_chassis_power_control_vals)); + return -1; } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Set Chassis Power Control to %s failed: %s", + val2str(ctl, ipmi_chassis_power_control_vals), + val2str(rsp->ccode, completion_code_vals)); + return -1; + } + + printf("Chassis Power Control: %s\n", + val2str(ctl, ipmi_chassis_power_control_vals)); + + /* sessions often get lost when changing chassis power */ + intf->abort = 1; + + return 0; } -static void ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) +static int +ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) { struct ipmi_rq req; struct ipmi_rs * rsp; @@ -117,17 +136,15 @@ static void ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) req.msg.netfn = IPMI_NETFN_CHASSIS; req.msg.cmd = 0x4; - if (arg) { - if (!strcmp(arg, "force")){ - identify_data.interval = 0; - identify_data.force_on = 1; - } else { - identify_data.interval = (unsigned char)atoi(arg); - identify_data.force_on = 0; - } - + if (arg != NULL) { + if (strncmp(arg, "force", 5) == 0) { + identify_data.interval = 0; + identify_data.force_on = 1; + } else { + identify_data.interval = (unsigned char)atoi(arg); + identify_data.force_on = 0; + } req.msg.data = (unsigned char *)&identify_data; - /* The Force Identify On byte is optional and not * supported by all devices-- if force is not specified, * we pass only one data byte; if specified, we pass two @@ -137,34 +154,41 @@ static void ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) } rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { - printf("ERROR:%x Chassis Identify Command\n", rsp->ccode); - if (identify_data.force_on) { + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to set Chassis Identify"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Set Chassis Identify failed: %s", + val2str(rsp->ccode, completion_code_vals)); + if (identify_data.force_on != 0) { /* Intel SE7501WV2 F/W 1.2 returns CC 0xC7, but * the IPMI v1.5 spec does not standardize a CC * if unsupported, so we warn */ - printf("Chassis may not support Force Identify On\n"); + lprintf(LOG_WARNING, "Chassis may not support Force Identify On\n"); } - return; + return -1; } + printf("Chassis identify interval: "); - if (!arg) { + if (arg == NULL) { printf("default (15 seconds)\n"); } else { - if (identify_data.force_on) { + if (identify_data.force_on != 0) { printf("indefinate\n"); } else { - if (identify_data.interval) { - printf("%i seconds\n", identify_data.interval); - } else { + if (identify_data.interval == 0) printf("off\n"); - } + else + printf("%i seconds\n", identify_data.interval); } } + return 0; } -static void ipmi_chassis_poh(struct ipmi_intf * intf) +static int +ipmi_chassis_poh(struct ipmi_intf * intf) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -175,9 +199,15 @@ static void ipmi_chassis_poh(struct ipmi_intf * intf) req.msg.cmd = 0xf; rsp = intf->sendrecv(intf, &req); - - if (!rsp || rsp->ccode) - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to get Chassis Power-On-Hours"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Chassis Power-On-Hours failed: %s", + val2str(rsp->ccode, completion_code_vals)); + return -1; + } memcpy(&count, rsp->data+1, 4); @@ -185,7 +215,8 @@ static void ipmi_chassis_poh(struct ipmi_intf * intf) (long)count, (long)(count / 24), (long)(count % 24)); } -static void ipmi_chassis_restart_cause(struct ipmi_intf * intf) +static int +ipmi_chassis_restart_cause(struct ipmi_intf * intf) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -195,9 +226,15 @@ static void ipmi_chassis_restart_cause(struct ipmi_intf * intf) req.msg.cmd = 0x7; rsp = intf->sendrecv(intf, &req); - - if (!rsp || rsp->ccode) - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Unable to get Chassis Restart Cause"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Chassis Restart Cause failed: %s", + val2str(rsp->ccode, completion_code_vals)); + return -1; + } printf("System restart cause: "); @@ -233,11 +270,14 @@ static void ipmi_chassis_restart_cause(struct ipmi_intf * intf) printf("power-cycle via PEF\n"); break; default: - printf("error!\n"); + printf("invalid\n"); } + + return 0; } -static void ipmi_chassis_status(struct ipmi_intf * intf) +static int +ipmi_chassis_status(struct ipmi_intf * intf) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -247,14 +287,14 @@ static void ipmi_chassis_status(struct ipmi_intf * intf) req.msg.cmd = 0x1; rsp = intf->sendrecv(intf, &req); - if (!rsp) { - printf("Error sending Chassis Status command\n"); - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Error sending Chassis Status command"); + return -1; } if (rsp->ccode > 0) { - printf("Error sending Chassis Status command: %s\n", - val2str(rsp->ccode, completion_code_vals)); - return; + lprintf(LOG_ERR, "Error sending Chassis Status command: %s", + val2str(rsp->ccode, completion_code_vals)); + return -1; } /* byte 1 */ @@ -299,25 +339,27 @@ static void ipmi_chassis_status(struct ipmi_intf * intf) printf("Drive Fault : %s\n", (rsp->data[2] & 0x4) ? "true" : "false"); printf("Cooling/Fan Fault : %s\n", (rsp->data[2] & 0x8) ? "true" : "false"); - if (rsp->data_len > 3) - { - /* optional byte 4 */ - if (rsp->data[3] == 0) { - printf("Front Panel Control : none\n"); - } else { - printf("Sleep Button Disable : %s\n", (rsp->data[3] & 0x80) ? "allowed" : "not allowed"); - printf("Diag Button Disable : %s\n", (rsp->data[3] & 0x40) ? "allowed" : "not allowed"); - printf("Reset Button Disable : %s\n", (rsp->data[3] & 0x20) ? "allowed" : "not allowed"); - printf("Power Button Disable : %s\n", (rsp->data[3] & 0x10) ? "allowed" : "not allowed"); - printf("Sleep Button Disabled: %s\n", (rsp->data[3] & 0x80) ? "true" : "false"); - printf("Diag Button Disabled : %s\n", (rsp->data[3] & 0x40) ? "true" : "false"); - printf("Reset Button Disabled: %s\n", (rsp->data[3] & 0x20) ? "true" : "false"); - printf("Power Button Disabled: %s\n", (rsp->data[3] & 0x10) ? "true" : "false"); - } + if (rsp->data_len > 3) { + /* optional byte 4 */ + if (rsp->data[3] == 0) { + printf("Front Panel Control : none\n"); + } else { + printf("Sleep Button Disable : %s\n", (rsp->data[3] & 0x80) ? "allowed" : "not allowed"); + printf("Diag Button Disable : %s\n", (rsp->data[3] & 0x40) ? "allowed" : "not allowed"); + printf("Reset Button Disable : %s\n", (rsp->data[3] & 0x20) ? "allowed" : "not allowed"); + printf("Power Button Disable : %s\n", (rsp->data[3] & 0x10) ? "allowed" : "not allowed"); + printf("Sleep Button Disabled: %s\n", (rsp->data[3] & 0x80) ? "true" : "false"); + printf("Diag Button Disabled : %s\n", (rsp->data[3] & 0x40) ? "true" : "false"); + printf("Reset Button Disabled: %s\n", (rsp->data[3] & 0x20) ? "true" : "false"); + printf("Power Button Disabled: %s\n", (rsp->data[3] & 0x10) ? "true" : "false"); + } } + + return 0; } -static void ipmi_chassis_set_bootparam(struct ipmi_intf * intf, unsigned char param, unsigned char * data, int len) +static int +ipmi_chassis_set_bootparam(struct ipmi_intf * intf, unsigned char param, unsigned char * data, int len) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -336,21 +378,28 @@ static void ipmi_chassis_set_bootparam(struct ipmi_intf * intf, unsigned char pa req.msg.data_len = len + 1; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) { - printf("Error setting Chassis Boot Parameter %d\n", param); - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Error setting Chassis Boot Parameter %d", param); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Set Chassis Boot Parameter %d failed: %s", + param, val2str(rsp->ccode, completion_code_vals)); + return -1; } - printf("Chassis Set Boot Param %d to %s\n", param, data); + printf("Chassis Set Boot Parameter %d to %s\n", param, data); + return 0; } -static void ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg) +static int +ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg) { struct ipmi_rs * rsp; struct ipmi_rq req; unsigned char msg_data[3]; - if (!arg) + if (arg == NULL) return; memset(msg_data, 0, 3); @@ -366,8 +415,15 @@ static void ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg) req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (!rsp || rsp->ccode) - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Error Getting Chassis Boot Parameter %s", arg); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Get Chassis Boot Parameter %s failed: %s", + arg, val2str(rsp->ccode, completion_code_vals)); + return -1; + } if (verbose > 2) printbuf(rsp->data, rsp->data_len, "Boot Option"); @@ -378,45 +434,47 @@ static void ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg) printf("Boot parameter data: %s\n", buf2str(rsp->data+2, rsp->data_len - 2)); } -static void ipmi_chassis_set_bootflag(struct ipmi_intf * intf, char * arg) +static int +ipmi_chassis_set_bootflag(struct ipmi_intf * intf, char * arg) { unsigned char flags[5]; + int rc = 0; ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN); - if (!arg) { - printf("Error: no bootflag argument supplied\n"); - return; + if (arg == NULL) { + lprintf(LOG_ERR, "No bootflag argument supplied"); + return -1; } - if (!strncmp(arg, "force_pxe", 9)) { - flags[1] = 0x04; // 00000100 - } - else if (!strncmp(arg, "force_disk", 10)) { - flags[1] = 0x08; // 00001000 - } - else if (!strncmp(arg, "force_diag", 10)) { - flags[1] = 0x10; // 00010000 - } - else if (!strncmp(arg, "force_cdrom", 11)) { - flags[1] = 0x14; // 00010100 - } - else if (!strncmp(arg, "force_floppy", 12)) { - flags[1] = 0x3c; // 00111100 - } + if (strncmp(arg, "force_pxe", 9) == 0) + flags[1] = 0x04; + else if (strncmp(arg, "force_disk", 10) == 0) + flags[1] = 0x08; + else if (strncmp(arg, "force_diag", 10) == 0) + flags[1] = 0x10; + else if (strncmp(arg, "force_cdrom", 11) == 0) + flags[1] = 0x14; + else if (strncmp(arg, "force_floppy", 12) == 0) + flags[1] = 0x3c; else { - printf("Invalid bootflag: %s\n", arg); - return; + lprintf(LOG_ERR, "Invalid bootflag: %s", arg); + return -1; } flags[0] = 0x80; /* set flag valid bit */ - ipmi_chassis_set_bootparam(intf, 5, flags, 5); + rc = ipmi_chassis_set_bootparam(intf, 5, flags, 5); - flags[0] = 0x08; /* don't automatically clear boot flag valid bit in 60 seconds */ - ipmi_chassis_set_bootparam(intf, 3, flags, 1); + if (rc < 0) { + flags[0] = 0x08; /* don't automatically clear boot flag valid bit in 60 seconds */ + rc = ipmi_chassis_set_bootparam(intf, 3, flags, 1); + } + + return rc; } -static void ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char policy) +static int +ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char policy) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -430,14 +488,15 @@ static void ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char pol req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (!rsp) - return; - if (rsp->ccode > 0) { - printf("BMC Power Restore Policy command failed: %s\n", - val2str(rsp->ccode, completion_code_vals)); - return; + if (rsp == NULL) { + lprintf(LOG_ERR, "Error in Power Restore Policy command"); + return -1; + } + if (rsp->ccode > 0) { + lprintf(LOG_ERR, "Power Restore Policy command failed: %s", + val2str(rsp->ccode, completion_code_vals)); + return -1; } - if (policy == IPMI_CHASSIS_POLICY_NO_CHANGE) { printf("Supported chassis power policy: "); @@ -465,121 +524,119 @@ static void ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char pol printf("unknown\n"); } } + return 0; } -int ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv) +int +ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv) { - if (!argc || !strncmp(argv[0], "help", 4)) { - printf("Chassis Commands: status, power, identify, policy, restart_cause, poh\n"); - return 0; + int rc = 0; + + if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0)) { + lprintf(LOG_NOTICE, "Chassis Commands: status, power, identify, policy, restart_cause, poh"); } - else if (!strncmp(argv[0], "status", 6)) { - ipmi_chassis_status(intf); + else if (strncmp(argv[0], "status", 6) == 0) { + rc = ipmi_chassis_status(intf); } - else if (!strncmp(argv[0], "power", 5)) { + else if (strncmp(argv[0], "power", 5) == 0) { unsigned char ctl = 0; - if (argc < 2 || !strncmp(argv[1], "help", 4)) { - printf("chassis power Commands: status, on, off, cycle, reset, diag, soft\n"); + if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) { + lprintf(LOG_NOTICE, "chassis power Commands: status, on, off, cycle, reset, diag, soft"); return 0; } - if (!strncmp(argv[1], "status", 6)) { - ipmi_chassis_power_status(intf); - return 0; + if (strncmp(argv[1], "status", 6) == 0) { + rc = ipmi_chassis_power_status(intf); + return rc; } - - if (!strncmp(argv[1], "up", 2) || !strncmp(argv[1], "on", 2)) + if ((strncmp(argv[1], "up", 2) == 0) || (strncmp(argv[1], "on", 2) == 0)) ctl = IPMI_CHASSIS_CTL_POWER_UP; - else if (!strncmp(argv[1], "down", 4) || !strncmp(argv[1], "off", 3)) + else if ((strncmp(argv[1], "down", 4) == 0) || (strncmp(argv[1], "off", 3) == 0)) ctl = IPMI_CHASSIS_CTL_POWER_DOWN; - else if (!strncmp(argv[1], "cycle", 5)) + else if (strncmp(argv[1], "cycle", 5) == 0) ctl = IPMI_CHASSIS_CTL_POWER_CYCLE; - else if (!strncmp(argv[1], "reset", 5)) + else if (strncmp(argv[1], "reset", 5) == 0) ctl = IPMI_CHASSIS_CTL_HARD_RESET; - else if (!strncmp(argv[1], "diag", 5)) + else if (strncmp(argv[1], "diag", 4) == 0) ctl = IPMI_CHASSIS_CTL_PULSE_DIAG; - else if (!strncmp (argv[1], "acpi", 4) || !strncmp(argv[1], "soft", 4)) + else if ((strncmp(argv[1], "acpi", 4) == 0) || (strncmp(argv[1], "soft", 4) == 0)) ctl = IPMI_CHASSIS_CTL_ACPI_SOFT; else { - printf("Invalid chassis power command: %s\n", argv[1]); + lprintf(LOG_ERR, "Invalid chassis power command: %s", argv[1]); return -1; } - ipmi_chassis_power_control(intf, ctl); + rc = ipmi_chassis_power_control(intf, ctl); } - else if (!strncmp(argv[0], "identify", 8)) { + else if (strncmp(argv[0], "identify", 8) == 0) { if (argc < 2) { - ipmi_chassis_identify(intf, NULL); + rc = ipmi_chassis_identify(intf, NULL); } - else if (!strncmp(argv[1], "help", 4)) { - printf("chassis identify \n"); - printf(" default is 15 seconds\n"); - printf(" 0 to turn off\n"); - printf(" force to turn on indefinitely\n"); + else if (strncmp(argv[1], "help", 4) == 0) { + lprintf(LOG_NOTICE, "chassis identify "); + lprintf(LOG_NOTICE, " default is 15 seconds"); + lprintf(LOG_NOTICE, " 0 to turn off"); + lprintf(LOG_NOTICE, " force to turn on indefinitely"); } else { - ipmi_chassis_identify(intf, argv[1]); + rc = ipmi_chassis_identify(intf, argv[1]); } } - else if (!strncmp(argv[0], "poh", 3)) { - ipmi_chassis_poh(intf); + else if (strncmp(argv[0], "poh", 3) == 0) { + rc = ipmi_chassis_poh(intf); } - else if (!strncmp(argv[0], "restart_cause", 13)) { - ipmi_chassis_restart_cause(intf); + else if (strncmp(argv[0], "restart_cause", 13) == 0) { + rc = ipmi_chassis_restart_cause(intf); } - else if (!strncmp(argv[0], "policy", 4)) { - if (argc < 2 || !strncmp(argv[1], "help", 4)) { - printf("chassis policy \n"); - printf(" list : return supported policies\n"); - printf(" always-on : turn on when power is restored\n"); - printf(" previous : return to previous state when power is restored\n"); - printf(" always-off : stay off after power is restored\n"); + else if (strncmp(argv[0], "policy", 4) == 0) { + if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) { + lprintf(LOG_NOTICE, "chassis policy "); + lprintf(LOG_NOTICE, " list : return supported policies"); + lprintf(LOG_NOTICE, " always-on : turn on when power is restored"); + lprintf(LOG_NOTICE, " previous : return to previous state when power is restored"); + lprintf(LOG_NOTICE, " always-off : stay off after power is restored"); } else { unsigned char ctl; - - if (!strncmp(argv[1], "list", 4)) + if (strncmp(argv[1], "list", 4) == 0) ctl = IPMI_CHASSIS_POLICY_NO_CHANGE; - else if (!strncmp(argv[1], "always-on", 9)) + else if (strncmp(argv[1], "always-on", 9) == 0) ctl = IPMI_CHASSIS_POLICY_ALWAYS_ON; - else if (!strncmp(argv[1], "previous", 8)) + else if (strncmp(argv[1], "previous", 8) == 0) ctl = IPMI_CHASSIS_POLICY_PREVIOUS; - else if (!strncmp(argv[1], "always-off", 10)) + else if (strncmp(argv[1], "always-off", 10) == 0) ctl = IPMI_CHASSIS_POLICY_ALWAYS_OFF; else { - printf("invalid chassis policy: %s\n", argv[1]); + lprintf(LOG_ERR, "Invalid chassis policy: %s", argv[1]); return -1; } - - ipmi_chassis_power_policy(intf, ctl); + rc = ipmi_chassis_power_policy(intf, ctl); } } - else if (!strncmp(argv[0], "bootparam", 7)) { - if (argc < 3 || !strncmp(argv[1], "help", 4)) { - printf("bootparam get|set