Blob Blame History Raw
From e9b21fcf6820f074f7166ddd993fb1dbb55d5ffc Mon Sep 17 00:00:00 2001
From: Boris Ranto <branto@redhat.com>
Date: Mon, 11 Jan 2016 14:10:15 +0100
Subject: [PATCH] ID 408 - fix sel list last X listing

The events can be removed as desired on certain machines so the only way
to get the proper last X events is to traverse them all not outputting
the first NR_EVENTS - X events.

Signed-off-by: Boris Ranto <branto@redhat.com>
---
 lib/ipmi_sel.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c
index 243f268..769fbc2 100644
--- a/lib/ipmi_sel.c
+++ b/lib/ipmi_sel.c
@@ -2239,7 +2239,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
 
 	if (count < 0) {
 		/** Show only the most recent 'count' records. */
-		int delta;
+		int i;
 		uint16_t entries;
 
 		req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
@@ -2257,15 +2257,20 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
 		if (-count > entries)
 			count = -entries;
 
-		/* Get first record. */
-		next_id = ipmi_sel_get_std_entry(intf, 0, &evt);
-
-		delta = next_id - evt.record_id;
-
-		/* Get last record. */
-		next_id = ipmi_sel_get_std_entry(intf, 0xffff, &evt);
-
-		next_id = evt.record_id + count * delta + delta;
+		for(i = 0; i < entries + count; i++) {
+			next_id = ipmi_sel_get_std_entry(intf, next_id, &evt);
+			if (next_id == 0) {
+				/*
+				 * usually next_id of zero means end but
+				 * retry because some hardware has quirks
+				 * and will return 0 randomly.
+				 */
+				next_id = ipmi_sel_get_std_entry(intf, next_id, &evt);
+				if (next_id == 0) {
+					break;
+				}
+			}
+		}
 	}
 
 	if (savefile != NULL) {
-- 
2.5.5