mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-01-21 08:34:29 +08:00
Add eval_ccode() into helper
Commit adds eval_ccode() into helper in order to save some code repetition on evaluation of retvals from _ipmi_* functions.
This commit is contained in:
parent
31f9d4c635
commit
bb35d370ba
@ -83,6 +83,8 @@ int str2ushort(const char * str, uint16_t * ushrt_ptr);
|
||||
int str2char(const char * str, int8_t * chr_ptr);
|
||||
int str2uchar(const char * str, uint8_t * uchr_ptr);
|
||||
|
||||
int eval_ccode(const int ccode);
|
||||
|
||||
int is_fru_id(const char *argv_ptr, uint8_t *fru_id_ptr);
|
||||
int is_ipmi_channel_num(const char *argv_ptr, uint8_t *channel_ptr);
|
||||
int is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr);
|
||||
|
||||
31
lib/helper.c
31
lib/helper.c
@ -672,6 +672,37 @@ ipmi_start_daemon(struct ipmi_intf *intf)
|
||||
dup(fd);
|
||||
}
|
||||
|
||||
/* eval_ccode - evaluate return value of _ipmi_* functions and print error error
|
||||
* message, if conditions are met.
|
||||
*
|
||||
* @ccode - return value of _ipmi_* function.
|
||||
*
|
||||
* returns - 0 if ccode is 0, otherwise (-1) and error might get printed-out.
|
||||
*/
|
||||
int
|
||||
eval_ccode(const int ccode)
|
||||
{
|
||||
if (ccode == 0) {
|
||||
return 0;
|
||||
} else if (ccode < 0) {
|
||||
switch (ccode) {
|
||||
case (-1):
|
||||
lprintf(LOG_ERR, "IPMI response is NULL.");
|
||||
break;
|
||||
case (-2):
|
||||
lprintf(LOG_ERR, "Unexpected data length received.");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (-1);
|
||||
} else {
|
||||
lprintf(LOG_ERR, "IPMI command failed: %s",
|
||||
val2str(ccode, completion_code_vals));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* is_fru_id - wrapper for str-2-int FRU ID conversion. Message is printed
|
||||
* on error.
|
||||
* FRU ID range: <0..255>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user