Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame^] | 1 | #include <libpdbg.h> |
| 2 | |
| 3 | #include <phosphor-logging/log.hpp> |
| 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include <watchdog_common.hpp> |
| 6 | #include <watchdog_logging.hpp> |
| 7 | |
| 8 | #include <map> |
| 9 | |
| 10 | namespace watchdog |
| 11 | { |
| 12 | namespace dump |
| 13 | { |
| 14 | |
| 15 | using namespace phosphor::logging; |
| 16 | |
| 17 | void transitionHost(const std::string& target) |
| 18 | { |
| 19 | constexpr auto systemdService = "org.freedesktop.systemd1"; |
| 20 | constexpr auto systemdObjPath = "/org/freedesktop/systemd1"; |
| 21 | constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager"; |
| 22 | |
| 23 | auto bus = sdbusplus::bus::new_system(); |
| 24 | auto method = bus.new_method_call(systemdService, systemdObjPath, |
| 25 | systemdInterface, "StartUnit"); |
| 26 | |
| 27 | method.append(target); // target unit to start |
| 28 | method.append("replace"); |
| 29 | |
| 30 | bus.call_noreply(method); // start the service |
| 31 | } |
| 32 | |
| 33 | bool isAutoRebootEnabled() |
| 34 | { |
| 35 | constexpr auto settingsService = "xyz.openbmc_project.Settings"; |
| 36 | constexpr auto settingsPath = |
| 37 | "/xyz/openbmc_project/control/host0/auto_reboot"; |
| 38 | constexpr auto settingsIntf = "org.freedesktop.DBus.Properties"; |
| 39 | constexpr auto rebootPolicy = |
| 40 | "xyz.openbmc_project.Control.Boot.RebootPolicy"; |
| 41 | |
| 42 | auto bus = sdbusplus::bus::new_system(); |
| 43 | auto method = |
| 44 | bus.new_method_call(settingsService, settingsPath, settingsIntf, "Get"); |
| 45 | |
| 46 | method.append(rebootPolicy); |
| 47 | method.append("AutoReboot"); |
| 48 | |
| 49 | bool autoReboot = false; |
| 50 | try |
| 51 | { |
| 52 | auto reply = bus.call(method); |
| 53 | std::variant<bool> result; |
| 54 | reply.read(result); |
| 55 | autoReboot = std::get<bool>(result); |
| 56 | } |
| 57 | catch (const sdbusplus::exception::SdBusError& e) |
| 58 | { |
| 59 | log<level::ERR>("Error in AutoReboot Get", entry("ERROR=%s", e.what())); |
| 60 | } |
| 61 | |
| 62 | return autoReboot; |
| 63 | } |
| 64 | |
| 65 | } // namespace dump |
| 66 | } // namespace watchdog |