Skip to content

Commit

Permalink
functions: bios-attr: Check that PLDM is running
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
anoo1 committed Jul 30, 2021
1 parent ae0998f commit fd4a608
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> interfaces;
method.append(interfaces);

std::vector<std::pair<std::string, std::vector<std::string>>> 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
*
Expand Down Expand Up @@ -643,6 +674,16 @@ std::shared_ptr<void> updateBiosAttrTable(
std::make_shared<decltype(elementsJsonFilePath)>(
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");
Expand Down

0 comments on commit fd4a608

Please sign in to comment.