From ffa3642e436b559d8062f777f00458cc7b5ecb01 Mon Sep 17 00:00:00 2001 From: James Feist Date: Thu, 11 Jun 2020 13:30:02 -0700 Subject: [PATCH 1/1] Add error reporting to pfr_image_manager This uses report functionality to update error return status for redfish updates. Tested: Got 400 error with different messages based on failure type { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "/redfish/v1/$metadata#Message.v1_0_0.Message", "Message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid archive.", "MessageArgs": [ "/redfish/v1/UpdateService", "invalid archive" ], "MessageId": "OpenBMC.0.1.0.InvalidFile", "Resolution": "None.", "Severity": "Warning" } ], "code": "OpenBMC.0.1.0.InvalidFile", "message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid archive." } } { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "/redfish/v1/$metadata#Message.v1_0_0.Message", "Message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid image format.", "MessageArgs": [ "/redfish/v1/UpdateService", "invalid image format" ], "MessageId": "OpenBMC.0.1.0.InvalidFile", "Resolution": "None.", "Severity": "Warning" } ], "code": "OpenBMC.0.1.0.InvalidFile", "message": "Invalid file uploaded to /redfish/v1/UpdateService: invalid image format." } } { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_0_0.Message", "Message": "The resource /redfish/v1/UpdateService was unable to satisfy the request due to unavailability of resources.", "MessageArgs": [ "/redfish/v1/UpdateService" ], "MessageId": "Base.1.4.0.ResourceExhaustion", "Resolution": "Ensure that the resources are available and resubmit the request.", "Severity": "Critical" } ], "code": "Base.1.4.0.ResourceExhaustion", "message": "The resource /redfish/v1/UpdateService was unable to satisfy the request due to unavailability of resources." } } Signed-off-by: James Feist --- dbus_helpers.hpp | 30 ++++++++++++++++++++++++++++++ pfr_image_manager.cpp | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 dbus_helpers.hpp diff --git a/dbus_helpers.hpp b/dbus_helpers.hpp new file mode 100644 index 0000000..b9ffa36 --- /dev/null +++ b/dbus_helpers.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "config.h" + +#include +inline bool isFwupdScriptRunning(sdbusplus::bus::bus& bus) +{ + using ObjectPath = sdbusplus::message::object_path; + // type is ssssssouso + using ListUnitsType = + std::tuple; + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "ListUnits"); + + auto reply = bus.call(method); + std::vector resp; + reply.read(resp); + + for (const auto& unit : resp) + { + if (std::get<0>(unit).find("fwupd@") != std::string::npos && + std::get<3>(unit) != "failed") + { + return true; + } + } + return false; +} diff --git a/pfr_image_manager.cpp b/pfr_image_manager.cpp index 1a41cbe..fe1e6f9 100644 --- a/pfr_image_manager.cpp +++ b/pfr_image_manager.cpp @@ -2,6 +2,7 @@ #include "pfr_image_manager.hpp" +#include "dbus_helpers.hpp" #include "version.hpp" #include "watch.hpp" @@ -33,6 +34,9 @@ namespace manager using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error; namespace Software = phosphor::logging::xyz::openbmc_project::Software; +using UnTarFail = Software::Image::UnTarFailure; +using ImageFail = Software::Image::ImageFailure; +using BusyFail = Software::Image::BusyFailure; static constexpr const uint32_t pfmPos = 2054; static constexpr const uint32_t block0Magic = 0xB6EAFD19; @@ -76,6 +80,8 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath, phosphor::logging::log( "Image magic number match failed", phosphor::logging::entry("IMAGEMAGIC=0x%x", imgMagic)); + phosphor::logging::report( + UnTarFail::PATH(imgPath.c_str())); return -1; } @@ -110,6 +116,9 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath, phosphor::logging::log( "Unknown image type"); + phosphor::logging::report( + ImageFail::FAIL("Unknown image type"), + ImageFail::PATH(imgPath.c_str())); return -1; } @@ -153,6 +162,9 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath, "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(), "REDFISH_MESSAGE_ARGS=%s", "Image HASH check fail", NULL); + phosphor::logging::report( + ImageFail::FAIL("Security violation: hash mismatch"), + ImageFail::PATH(imgPath.c_str())); return -1; } @@ -167,6 +179,9 @@ int Manager::verifyPFRImage(const std::filesystem::path imgPath, catch (std::exception& e) { phosphor::logging::log(e.what()); + phosphor::logging::report( + ImageFail::FAIL("Unhandled exception"), + ImageFail::PATH(imgPath.c_str())); return -1; } } @@ -182,6 +197,12 @@ int Manager::processImage(const std::string& imgFilePath) if (!std::filesystem::exists(imgPath)) return -1; + if (isFwupdScriptRunning(bus)) + { + phosphor::logging::report(BusyFail::PATH(imgPath.c_str())); + return -1; + } + int retry = 3; std::string ver; std::string purposeString; -- 2.17.1