blob: 474a04d1646f007dd92a10aad6e1d2272f9cb2e8 [file] [log] [blame]
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -08001#include "health_utils.hpp"
2
3#include <phosphor-logging/lg2.hpp>
Patrick Williams6662be32024-02-22 13:35:46 -06004#include <xyz/openbmc_project/ObjectMapper/client.hpp>
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -08005
6PHOSPHOR_LOG2_USING;
7
8namespace phosphor::health::utils
9{
10
11void startUnit(sdbusplus::bus_t& bus, const std::string& sysdUnit)
12{
13 if (sysdUnit.empty())
14 {
15 return;
16 }
17 sdbusplus::message_t msg = bus.new_method_call(
18 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
19 "org.freedesktop.systemd1.Manager", "StartUnit");
20 msg.append(sysdUnit, "replace");
21 bus.call_noreply(msg);
22}
23
Patrick Williams6662be32024-02-22 13:35:46 -060024auto findPaths(sdbusplus::async::context& ctx, const std::string& iface,
25 const std::string& subpath) -> sdbusplus::async::task<paths_t>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080026{
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080027 try
28 {
Patrick Williams6662be32024-02-22 13:35:46 -060029 using ObjectMapper =
30 sdbusplus::client::xyz::openbmc_project::ObjectMapper<>;
31
32 auto mapper = ObjectMapper(ctx)
33 .service(ObjectMapper::default_service)
34 .path(ObjectMapper::instance_path);
35
36 std::vector<std::string> ifaces = {iface};
37 co_return co_await mapper.get_sub_tree_paths(subpath, 0, ifaces);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080038 }
39 catch (std::exception& e)
40 {
41 error("Exception occurred for GetSubTreePaths for {PATH}: {ERROR}",
Patrick Williams6662be32024-02-22 13:35:46 -060042 "PATH", subpath, "ERROR", e);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080043 }
Patrick Williams6662be32024-02-22 13:35:46 -060044 co_return {};
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080045}
46
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -080047} // namespace phosphor::health::utils