diff options
Diffstat (limited to 'host_check_main.cpp')
-rw-r--r-- | host_check_main.cpp | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/host_check_main.cpp b/host_check_main.cpp index eec4acc..54a182a 100644 --- a/host_check_main.cpp +++ b/host_check_main.cpp @@ -19,12 +19,11 @@ constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; constexpr auto CONTROL_HOST_PATH = "/xyz/openbmc_project/control/host0"; constexpr auto CONTROL_HOST_INTERFACE = "xyz.openbmc_project.Control.Host"; -bool cmdDone = false; +bool cmdDone = false; bool hostRunning = false; // Function called on host control signals -static int hostControlSignal(sd_bus_message* msg, - void* userData, +static int hostControlSignal(sd_bus_message* msg, void* userData, sd_bus_error* retError) { std::string cmdCompleted{}; @@ -34,15 +33,16 @@ static int hostControlSignal(sd_bus_message* msg, sdPlusMsg.read(cmdCompleted, cmdStatus); log<level::DEBUG>("Host control signal values", - entry("COMMAND=%s",cmdCompleted.c_str()), - entry("STATUS=%s",cmdStatus.c_str())); + entry("COMMAND=%s", cmdCompleted.c_str()), + entry("STATUS=%s", cmdStatus.c_str())); // Verify it's the command this code is interested in and then check status - if(Host::convertCommandFromString(cmdCompleted) == Host::Command::Heartbeat) + if (Host::convertCommandFromString(cmdCompleted) == + Host::Command::Heartbeat) { cmdDone = true; - if(Host::convertResultFromString(cmdStatus) == Host::Result::Success) + if (Host::convertResultFromString(cmdStatus) == Host::Result::Success) { hostRunning = true; } @@ -54,10 +54,8 @@ static int hostControlSignal(sd_bus_message* msg, // Send hearbeat to host to determine if it's running void sendHeartbeat(sdbusplus::bus::bus& bus) { - auto mapper = bus.new_method_call(MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject"); + auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, + MAPPER_INTERFACE, "GetObject"); mapper.append(CONTROL_HOST_PATH, std::vector<std::string>({CONTROL_HOST_INTERFACE})); @@ -81,10 +79,8 @@ void sendHeartbeat(sdbusplus::bus::bus& bus) const auto& host = mapperResponse.begin()->first; - auto method = bus.new_method_call(host.c_str(), - CONTROL_HOST_PATH, - CONTROL_HOST_INTERFACE, - "Execute"); + auto method = bus.new_method_call(host.c_str(), CONTROL_HOST_PATH, + CONTROL_HOST_INTERFACE, "Execute"); method.append(convertForMessage(Host::Command::Heartbeat).c_str()); auto reply = bus.call(method); @@ -97,42 +93,40 @@ void sendHeartbeat(sdbusplus::bus::bus& bus) return; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { log<level::INFO>("Check if host is running"); auto bus = sdbusplus::bus::new_default(); auto s = "type='signal',member='CommandComplete',path='"s + - CONTROL_HOST_PATH + "',interface='" + - CONTROL_HOST_INTERFACE + "'"; + CONTROL_HOST_PATH + "',interface='" + CONTROL_HOST_INTERFACE + "'"; // Setup Signal Handler - sdbusplus::bus::match::match hostControlSignals(bus, - s.c_str(), - hostControlSignal, - nullptr); + sdbusplus::bus::match::match hostControlSignals(bus, s.c_str(), + hostControlSignal, nullptr); sendHeartbeat(bus); // Wait for signal - while(!cmdDone) + while (!cmdDone) { bus.process_discard(); - if (cmdDone) break; + if (cmdDone) + break; bus.wait(); } // If host running then create file - if(hostRunning) + if (hostRunning) { log<level::INFO>("Host is running!"); // Create file for host instance and create in filesystem to indicate // to services that host is running - auto size = std::snprintf(nullptr,0,HOST_RUNNING_FILE,0); + auto size = std::snprintf(nullptr, 0, HOST_RUNNING_FILE, 0); size++; // null std::unique_ptr<char[]> buf(new char[size]); - std::snprintf(buf.get(),size,HOST_RUNNING_FILE,0); + std::snprintf(buf.get(), size, HOST_RUNNING_FILE, 0); std::ofstream outfile(buf.get()); outfile.close(); } |