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