From c03e3bcfc5e3df96139ff66502eada20451a1d57 Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Tue, 4 Jun 2024 15:37:47 -0500 Subject: [PATCH] user_mgmt: Recover corrupted nv files (#17) (#24) For unknown reasons the nv file size become to 0. To not affect the service, add this condition: If the file is 0 in size, delete the file and throw the exception. Related Issue: openbmc/phosphor-host-ipmid#185 Tested: Make an empty size file, restart ipmid and confirm the recovery was successful. $ rm /var/lib/ipmi/channel_access_nv.json $ touch /var/lib/ipmi/channel_access_nv.json $ systemctl restart phosphor-ipmi-host.service Signed-off-by: LuluTHSu Co-authored-by: Lulu_Su <63627630+LuluTHSu@users.noreply.github.com> --- user_channel/channel_mgmt.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp index a179b37..f9df4db 100644 --- a/user_channel/channel_mgmt.cpp +++ b/user_channel/channel_mgmt.cpp @@ -1106,6 +1106,15 @@ int ChannelConfig::readChannelPersistData() log("Error in opening IPMI Channel data file"); return -EIO; } + else if (!std::filesystem::file_size(channelNvDataFilename)) + { + log("NV file (channelNvDataFilename) has a size of zero"); + if (std::filesystem::remove(channelNvDataFilename)) + { + log("NV file (channelNvDataFilename) is deleted"); + } + return -EIO; + } try { // Fill in global structure