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