mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 10:37:22 +00:00
event: Clean up event sending from a file
The ipmi_event_fromfile() function was massively repeating the code of ipmi_send_platform_event() and ipmi_event_msg_print(). This commit cleans up ipmi_event_fromfile() to simply call ipmi_send_platform_event() with all the prepared data read from the file. That function in its turn calls ipmi_event_msg_print(). This commit also replaces the dummy generator ID 2 that was printed to the user with a more relevant generator ID that will actually be sent by ipmi_send_platform_event(). Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
parent
82d6629a66
commit
b7db637984
@ -69,7 +69,8 @@ ipmi_event_msg_print(struct ipmi_intf * intf, struct platform_event_msg * pmsg)
|
|||||||
memset(&sel_event, 0, sizeof(struct sel_event_record));
|
memset(&sel_event, 0, sizeof(struct sel_event_record));
|
||||||
|
|
||||||
sel_event.record_id = 0;
|
sel_event.record_id = 0;
|
||||||
sel_event.sel_type.standard_type.gen_id = 2;
|
htoipmi16(EVENT_GENERATOR(SMS, 0),
|
||||||
|
(void *)&sel_event.sel_type.standard_type.gen_id);
|
||||||
|
|
||||||
sel_event.sel_type.standard_type.evm_rev = pmsg->evm_rev;
|
sel_event.sel_type.standard_type.evm_rev = pmsg->evm_rev;
|
||||||
sel_event.sel_type.standard_type.sensor_type = pmsg->sensor_type;
|
sel_event.sel_type.standard_type.sensor_type = pmsg->sensor_type;
|
||||||
@ -498,42 +499,18 @@ static int
|
|||||||
ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
||||||
{
|
{
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
struct ipmi_rs * rsp;
|
/* For ease of filling in from file data */
|
||||||
struct ipmi_rq req;
|
union {
|
||||||
struct sel_event_record sel_event;
|
struct platform_event_msg emsg;
|
||||||
uint8_t rqdata[PLATFORM_EVENT_DATA_LEN_MAX];
|
uint8_t bytes[sizeof(struct platform_event_msg)];
|
||||||
uint8_t *rqdata_start = rqdata;
|
} __attribute__ ((packed)) rqdata;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char * ptr, * tok;
|
char * ptr, * tok;
|
||||||
struct channel_info_t chinfo;
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(rqdata, 0, sizeof(rqdata));
|
|
||||||
|
|
||||||
/* setup Platform Event Message command */
|
|
||||||
memset(&req, 0, sizeof(req));
|
|
||||||
req.msg.netfn = IPMI_NETFN_SE;
|
|
||||||
req.msg.cmd = IPMI_CMD_PLATFORM_EVENT;
|
|
||||||
req.msg.data = rqdata;
|
|
||||||
req.msg.data_len = PLATFORM_EVENT_DATA_LEN_NON_SI;
|
|
||||||
|
|
||||||
ipmi_current_channel_info(intf, &chinfo);
|
|
||||||
if (chinfo.channel == CH_UNKNOWN) {
|
|
||||||
lprintf(LOG_ERR, "Failed to send the event from file "
|
|
||||||
"via an unknown channel");
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_system(&chinfo)) {
|
|
||||||
/* system interface, need extra generator ID, see Fig. 29-2 */
|
|
||||||
rqdata[0] = EVENT_GENERATOR(REMOTE_CONSOLE, 1);
|
|
||||||
req.msg.data_len = PLATFORM_EVENT_DATA_LEN_SI;
|
|
||||||
rqdata_start++;
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = ipmi_open_file_read(file);
|
fp = ipmi_open_file_read(file);
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return -1;
|
return -1;
|
||||||
@ -543,6 +520,9 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
|||||||
if (!fgets(buf, 1024, fp))
|
if (!fgets(buf, 1024, fp))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* Each line is a new event */
|
||||||
|
memset(&rqdata, 0, sizeof(rqdata));
|
||||||
|
|
||||||
/* clip off optional comment tail indicated by # */
|
/* clip off optional comment tail indicated by # */
|
||||||
ptr = strchr(buf, '#');
|
ptr = strchr(buf, '#');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
@ -566,7 +546,7 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
|||||||
while (tok) {
|
while (tok) {
|
||||||
if (count == sizeof(struct platform_event_msg))
|
if (count == sizeof(struct platform_event_msg))
|
||||||
break;
|
break;
|
||||||
if (0 > str2uchar(tok, &rqdata_start[count])) {
|
if (0 > str2uchar(tok, &rqdata.bytes[count])) {
|
||||||
lprintf(LOG_ERR, "Invalid token in file: [%s]", tok);
|
lprintf(LOG_ERR, "Invalid token in file: [%s]", tok);
|
||||||
rc = -1;
|
rc = -1;
|
||||||
break;
|
break;
|
||||||
@ -576,35 +556,14 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
|||||||
}
|
}
|
||||||
if (count < sizeof(struct platform_event_msg)) {
|
if (count < sizeof(struct platform_event_msg)) {
|
||||||
lprintf(LOG_ERR, "Invalid Event: %s",
|
lprintf(LOG_ERR, "Invalid Event: %s",
|
||||||
buf2str(rqdata, sizeof(rqdata)));
|
buf2str(rqdata.bytes, sizeof(rqdata.bytes)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sel_event, 0, sizeof(struct sel_event_record));
|
/* Now actually send it, failures will be logged by the sender */
|
||||||
sel_event.record_id = 0;
|
rc = ipmi_send_platform_event(intf, &rqdata.emsg);
|
||||||
sel_event.sel_type.standard_type.gen_id = 2;
|
if (IPMI_CC_OK != rc)
|
||||||
|
break;
|
||||||
/*
|
|
||||||
* Standard SEL record matches the platform event message
|
|
||||||
* format starting with the evm_rev field.
|
|
||||||
* Hence, just copy the message to the record at evm_rev.
|
|
||||||
*/
|
|
||||||
memcpy(&sel_event.sel_type.standard_type.evm_rev,
|
|
||||||
rqdata_start,
|
|
||||||
sizeof(struct platform_event_msg));
|
|
||||||
|
|
||||||
ipmi_sel_print_std_entry(intf, &sel_event);
|
|
||||||
|
|
||||||
rsp = intf->sendrecv(intf, &req);
|
|
||||||
if (!rsp) {
|
|
||||||
lprintf(LOG_ERR, "Platform Event Message command failed");
|
|
||||||
rc = -1;
|
|
||||||
}
|
|
||||||
else if (rsp->ccode) {
|
|
||||||
lprintf(LOG_ERR, "Platform Event Message command failed: %s",
|
|
||||||
val2str(rsp->ccode, completion_code_vals));
|
|
||||||
rc = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user