Remove record ID rollover

When adding SEL entries, record IDs no longer rollover from 0xFFFE to
0x0001. Instead, it is up to the SMS or the user to clear the SEL. When
a SEL entry is attempted to be added when the SEL is full, that SEL
entry is ignored and lost.

Change-Id: Ifa38be893eb26c3949194aa83f4312a7c327ff7a
Signed-off-by: Jonico Eustaquio <jonico.eustaquio@fii-na.com>
diff --git a/src/sel_logger.cpp b/src/sel_logger.cpp
index d04e841..6df8e44 100644
--- a/src/sel_logger.cpp
+++ b/src/sel_logger.cpp
@@ -81,17 +81,17 @@
     return !selLogFiles.empty();
 }
 
-static unsigned int initializeRecordId(void)
+static unsigned int initializeRecordId()
 {
     std::vector<std::filesystem::path> selLogFiles;
     if (!getSELLogFiles(selLogFiles))
     {
-        return selInvalidRecID;
+        return 0;
     }
     std::ifstream logStream(selLogFiles.front());
     if (!logStream.is_open())
     {
-        return selInvalidRecID;
+        return 0;
     }
     std::string line;
     std::string newestEntry;
@@ -105,7 +105,7 @@
                  boost::token_compress_on);
     if (newestEntryFields.size() < 4)
     {
-        return selInvalidRecID;
+        return 0;
     }
 
     return std::stoul(newestEntryFields[1]);
@@ -146,7 +146,7 @@
         }
     }
 
-    recordId = selInvalidRecID;
+    recordId = 0;
 
     // Reload rsyslog so it knows to start new log files
     boost::asio::io_context io;
@@ -165,11 +165,11 @@
     }
 }
 
-static unsigned int getNewRecordId(void)
+static unsigned int getNewRecordId()
 {
     if (++recordId >= selInvalidRecID)
     {
-        recordId = 1;
+        recordId = selInvalidRecID;
     }
     return recordId;
 }
@@ -224,13 +224,16 @@
     return 0;
 #else
     unsigned int recordId = getNewRecordId();
-    sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", selPriority,
-                    "MESSAGE_ID=%s", selMessageId, "IPMI_SEL_RECORD_ID=%d",
-                    recordId, "IPMI_SEL_RECORD_TYPE=%x", selSystemType,
-                    "IPMI_SEL_GENERATOR_ID=%x", genId,
-                    "IPMI_SEL_SENSOR_PATH=%s", path.c_str(),
-                    "IPMI_SEL_EVENT_DIR=%x", assert, "IPMI_SEL_DATA=%s",
-                    selDataStr.c_str(), std::forward<T>(metadata)..., NULL);
+    if (recordId < selInvalidRecID)
+    {
+        sd_journal_send(
+            "MESSAGE=%s", message.c_str(), "PRIORITY=%i", selPriority,
+            "MESSAGE_ID=%s", selMessageId, "IPMI_SEL_RECORD_ID=%d", recordId,
+            "IPMI_SEL_RECORD_TYPE=%x", selSystemType,
+            "IPMI_SEL_GENERATOR_ID=%x", genId, "IPMI_SEL_SENSOR_PATH=%s",
+            path.c_str(), "IPMI_SEL_EVENT_DIR=%x", assert, "IPMI_SEL_DATA=%s",
+            selDataStr.c_str(), std::forward<T>(metadata)..., NULL);
+    }
     return recordId;
 #endif
 }
@@ -270,10 +273,14 @@
     return 0;
 #else
     unsigned int recordId = getNewRecordId();
-    sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", selPriority,
-                    "MESSAGE_ID=%s", selMessageId, "IPMI_SEL_RECORD_ID=%d",
-                    recordId, "IPMI_SEL_RECORD_TYPE=%x", recordType,
-                    "IPMI_SEL_DATA=%s", selDataStr.c_str(), NULL);
+    if (recordId < selInvalidRecID)
+    {
+        sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i",
+                        selPriority, "MESSAGE_ID=%s", selMessageId,
+                        "IPMI_SEL_RECORD_ID=%d", recordId,
+                        "IPMI_SEL_RECORD_TYPE=%x", recordType,
+                        "IPMI_SEL_DATA=%s", selDataStr.c_str(), NULL);
+    }
     return recordId;
 #endif
 }