From 6a24cf472ec644ee58ce7c184b906bd02ab605cc 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 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