From 30a41b7145248fb1e57ee7072435d81325e962d4 Mon Sep 17 00:00:00 2001 From: Lulu_Su <63627630+LuluTHSu@users.noreply.github.com> Date: Wed, 21 Sep 2022 02:12:06 +0800 Subject: [PATCH] user_mgmt: Recover corrupted nv files (#17) 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 Signed-off-by: LuluTHSu --- 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 5f44818..677d35a 100644 --- a/user_channel/channel_mgmt.cpp +++ b/user_channel/channel_mgmt.cpp @@ -1083,6 +1083,15 @@ int ChannelConfig::readChannelPersistData() log("Error in opening IPMI Channel data file"); return -EIO; } + else if (!std::experimental::filesystem::file_size(channelNvDataFilename)) + { + log("NV file (channelNvDataFilename) has a size of zero"); + if (std::experimental::filesystem::remove(channelNvDataFilename)) + { + log("NV file (channelNvDataFilename) is deleted"); + } + return -EIO; + } try { // Fill in global structure