From fd4a608888b688e6204ef65011933d818c1ed844 Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Mon, 21 Jun 2021 15:53:34 +0000 Subject: [PATCH] functions: bios-attr: Check that PLDM is running The BIOS attribute table can only be updated if PLDM is running. Check that the service is running, and if it's not, return. A subsequent commit will add D-Bus matches to trigger if PLDM starts after the bios attr function. Change-Id: Id64bffc3b6465091f2df60304a0c95c9e34312dc Signed-off-by: Adriana Kobylak --- functions.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/functions.cpp b/functions.cpp index 40bfc83..7e684f1 100644 --- a/functions.cpp +++ b/functions.cpp @@ -31,6 +31,37 @@ namespace process_hostfirmware using namespace phosphor::logging; +/** + * @brief GetObject function to find the service given an object path. + * It is used to determine if a service is running, so there is no need + * to specify interfaces as a parameter to constrain the search. + */ +std::string getObject(sdbusplus::bus::bus& bus, const std::string& path) +{ + auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, + MAPPER_BUSNAME, "GetObject"); + method.append(path); + std::vector interfaces; + method.append(interfaces); + + std::vector>> response; + + try + { + auto reply = bus.call(method); + reply.read(response); + if (response.empty()) + { + return std::string{}; + } + } + catch (const sdbusplus::exception::SdBusError& e) + { + return std::string{}; + } + return response[0].first; +} + /** * @brief Issue callbacks safely * @@ -643,6 +674,16 @@ std::shared_ptr updateBiosAttrTable( std::make_shared( std::move(elementsJsonFilePath)); + // The BIOS attribute table can only be updated if PLDM is running because + // PLDM is the one that exposes this property. Return if it's not running. + constexpr auto pldmPath = "/xyz/openbmc_project/pldm"; + auto pldmObject = getObject(bus, pldmPath); + if (pldmObject.empty()) + { + loop.exit(0); + return nullptr; + } + auto getManagedObjects = bus.new_method_call( "xyz.openbmc_project.EntityManager", "/", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");