ID: 41 - ipmi_sel_interpret() - clean up formatting and kill indentation

Commit cleans up formatting and indentation in ipmi_sel_interpret()
in 'lib/ipmi_sel.c'.
This commit is contained in:
Zdenek Styblik 2013-08-16 09:56:15 +00:00
parent 5177966867
commit ee6c9be382
2 changed files with 153 additions and 154 deletions

View File

@ -119,6 +119,7 @@ version 1.8.13rc0 2013-08-09
* ID: 264 - incorrect array index in get_lan_param_select()
* ID: 269 - Fixes for configure.in for cross compilation
* ID: 267 - Corruption in "lan alert print" output
* ID: 41 - ipmi_sel_interpret() - clean up formatting, indentation
version 1.8.12 released 2012-08-09

View File

@ -2183,46 +2183,57 @@ ipmi_sel_save_entries(struct ipmi_intf * intf, int count, const char * savefile)
* -1 on error
*/
static int
ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * readfile, const char *format)
ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana,
const char *readfile, const char *format)
{
FILE *fp = 0;
int status = 0;
struct sel_event_record evt;
char *buffer;
/* since the interface is not used, iana is taken from the command line */
char *buffer = NULL;
char *cursor = NULL;
int status = 0;
/* since the interface is not used, iana is taken from
* the command line
*/
sel_iana = iana;
if (strncmp("pps", format, 3) == 0) {
/* Parser for the following format */
/*
0x001F: Event: at Mar 27 06:41:10 2007;from:(0x9a,0,7); \
sensor:(0xc3,119); event:0x6f(asserted): 0xA3 0x00 0x88
commonly found in PPS shelf managers
Supports a tweak for hotswap events that are already interpreted.
/* 0x001F: Event: at Mar 27 06:41:10 2007;from:(0x9a,0,7);
* sensor:(0xc3,119); event:0x6f(asserted): 0xA3 0x00 0x88
* commonly found in PPS shelf managers
* Supports a tweak for hotswap events that are already interpreted.
*/
fp = ipmi_open_file(readfile, 0);
if (fp){
if (fp == NULL) {
lprintf(LOG_ERR, "Failed to open file '%s' for reading.",
readfile);
return (-1);
}
buffer = (char *)malloc((size_t)256);
if( buffer != NULL ) {
if (buffer == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
fclose(fp);
return (-1);
}
do {
/* Only allow complete lines to be parsed,hardcoded maximum
line length */
if( fgets(buffer, 256, fp) != NULL ){
if( strlen(buffer) < 256 ) {
char *cursor = buffer;
evt.record_type= 2; /* assume normal "System" event */
evt.record_id=
strtol((const char*)cursor, (char **)NULL,16);
/* Only allow complete lines to be parsed,
* hardcoded maximum line length
*/
if (fgets(buffer, 256, fp) == NULL) {
status = (-1);
break;
}
if (strlen(buffer) > 255) {
lprintf(LOG_ERR, "ipmitool: invalid entry found in file.");
continue;
}
cursor = buffer;
/* assume normal "System" event */
evt.record_type = 2;
evt.record_id = strtol((const char *)cursor, (char **)NULL, 16);
evt.sel_type.standard_type.evm_rev = 4;
/* FIXME: convert*/ evt.sel_type.standard_type.timestamp;
/* FIXME: convert*/
evt.sel_type.standard_type.timestamp;
/* skip timestamp */
cursor = index((const char *)cursor, ';');
@ -2241,7 +2252,6 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
evt.sel_type.standard_type.sensor_type =
strtol((const char *)cursor, (char **)NULL, 16);
cursor = index((const char *)cursor, ',');
cursor++;
@ -2260,8 +2270,7 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
cursor++;
if (*cursor == 'a') {
evt.sel_type.standard_type.event_dir = 0;
}
else {
} else {
evt.sel_type.standard_type.event_dir = 1;
}
/* skip to data info */
@ -2269,7 +2278,6 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
cursor++;
if (evt.sel_type.standard_type.sensor_type == 0xF0) {
/* got to FRU id */
while (!isdigit(*cursor)) {
cursor++;
@ -2282,7 +2290,6 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
cursor = index((const char *)cursor, 'M');
cursor++;
/* Set previous state */
evt.sel_type.standard_type.event_data[1] =
strtol(cursor, (char **)NULL, 10);
@ -2291,7 +2298,6 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
cursor = index((const char *)cursor, 'M');
cursor++;
/* Set current state */
evt.sel_type.standard_type.event_data[0] =
0xA0 | strtol(cursor, (char **)NULL, 10);
@ -2302,10 +2308,8 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
evt.sel_type.standard_type.event_data[1] |=
(strtol(cursor, (char **)NULL, 16)) << 4;
} else if (*cursor == '0') {
evt.sel_type.standard_type.event_data[0] =
strtol((const char *)cursor, (char **)NULL, 16);
cursor = index((const char *)cursor, ' ');
cursor++;
@ -2320,28 +2324,22 @@ ipmi_sel_interpret(struct ipmi_intf * intf, unsigned long iana, const char * rea
} else {
lprintf(LOG_ERR, "ipmitool: can't guess format.");
}
/* parse the PPS line into a sel_event_record */
if (verbose) {
ipmi_sel_print_std_entry_verbose(intf, &evt);
}
else {
} else {
ipmi_sel_print_std_entry(intf, &evt);
}
}else{ /* length didn't fit */
lprintf(LOG_ERR, "ipmitool: invalid entry found in file.");
}
}else{ /* fgets failed (or reached end of file) */
status = -1;
}
cursor = NULL;
} while (status == 0); /* until file is completely read */
cursor = NULL;
free(buffer);
buffer = NULL;
} /* if memory allocation succeeded */
fclose(fp);
} /* if file open succeeded */
} /* if format is known */
} else {
lprintf(LOG_ERR, "Given format '%s' is unknown.", format);
status = (-1);
}
return status;
}