From f29c8f79bc5f6a828d393a715045634ea5a925bb 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 2d492e0..4920f6e 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