1 #include "config.h" 2 3 #include "utils.hpp" 4 5 #include <getopt.h> 6 #include <systemd/sd-bus.h> 7 8 #include <phosphor-logging/elog-errors.hpp> 9 #include <phosphor-logging/lg2.hpp> 10 #include <sdbusplus/exception.hpp> 11 #include <sdbusplus/server.hpp> 12 #include <xyz/openbmc_project/Common/error.hpp> 13 #include <xyz/openbmc_project/State/Chassis/client.hpp> 14 15 #include <iostream> 16 #include <map> 17 #include <string> 18 19 PHOSPHOR_LOG2_USING; 20 21 using namespace phosphor::logging; 22 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 23 24 using ChassisState = sdbusplus::client::xyz::openbmc_project::state::Chassis<>; 25 26 int main(int argc, char** argv) 27 { 28 size_t chassisId = 0; 29 const auto* objPath = ChassisState::namespace_path::value; 30 auto chassisBusName = ChassisState::interface + std::to_string(chassisId); 31 int arg; 32 int optIndex = 0; 33 34 static struct option longOpts[] = { 35 {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}}; 36 37 while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1) 38 { 39 switch (arg) 40 { 41 case 'c': 42 chassisId = std::stoul(optarg); 43 break; 44 default: 45 break; 46 } 47 } 48 49 auto chassisName = std::string(ChassisState::namespace_path::chassis) + 50 std::to_string(chassisId); 51 std::string chassisPath = 52 sdbusplus::message::object_path(objPath) / chassisName; 53 auto bus = sdbusplus::bus::new_default(); 54 55 // If the chassis power status is not good, log an error and exit with 56 // a non-zero rc so the system does not power on 57 auto currentPowerStatus = phosphor::state::manager::utils::getProperty( 58 bus, chassisPath, ChassisState::interface, "CurrentPowerStatus"); 59 if (currentPowerStatus != 60 "xyz.openbmc_project.State.Chassis.PowerStatus.Good") 61 { 62 error("Chassis power status is not good: {CURRENT_PWR_STATUS}", 63 "CURRENT_PWR_STATUS", currentPowerStatus); 64 65 // Generate log telling user why system is not powering on 66 const std::string errorMsg = 67 "xyz.openbmc_project.State.ChassisPowerBad"; 68 phosphor::state::manager::utils::createError( 69 bus, errorMsg, 70 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level:: 71 Critical); 72 return -1; 73 } 74 // all good 75 info("Chassis power status good, start power on"); 76 return 0; 77 } 78