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
main(int argc,char ** argv)26 int main(int argc, char** argv)
27 {
28 size_t chassisId = 0;
29 const auto* objPath = ChassisState::namespace_path::value;
30 int arg;
31 int optIndex = 0;
32
33 static struct option longOpts[] = {
34 {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}};
35
36 while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1)
37 {
38 switch (arg)
39 {
40 case 'c':
41 chassisId = std::stoul(optarg);
42 break;
43 default:
44 break;
45 }
46 }
47
48 auto chassisName = std::string(ChassisState::namespace_path::chassis) +
49 std::to_string(chassisId);
50 std::string chassisPath =
51 sdbusplus::message::object_path(objPath) / chassisName;
52 auto bus = sdbusplus::bus::new_default();
53
54 // If the chassis power status is not good, log an error and exit with
55 // a non-zero rc so the system does not power on
56 auto currentPowerStatus = phosphor::state::manager::utils::getProperty(
57 bus, chassisPath, ChassisState::interface,
58 ChassisState::property_names::current_power_status);
59 if (currentPowerStatus != ChassisState::convertPowerStatusToString(
60 ChassisState::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