blob: abb03c432f59ac154b35537fabb08178732cb331 [file] [log] [blame]
Andrew Geissler378fe112022-02-03 16:39:44 -06001#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>
Patrick Williams7a7c38d2023-09-06 22:00:15 -050012#include <xyz/openbmc_project/Common/error.hpp>
Andrew Geissler378fe112022-02-03 16:39:44 -060013
14#include <iostream>
15#include <map>
16#include <string>
17
18PHOSPHOR_LOG2_USING;
19
20using namespace phosphor::logging;
21using namespace sdbusplus::xyz::openbmc_project::Common::Error;
22
23int main(int argc, char** argv)
24{
25 std::string chassisPath = "/xyz/openbmc_project/state/chassis0";
26 int arg;
27 int optIndex = 0;
28
Pavithra Barithayaf15b9542024-06-21 08:18:48 -050029 static struct option longOpts[] = {
30 {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}};
Andrew Geissler378fe112022-02-03 16:39:44 -060031
32 while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1)
33 {
34 switch (arg)
35 {
36 case 'c':
37 chassisPath =
38 std::string("/xyz/openbmc_project/state/chassis") + optarg;
39 break;
40 default:
41 break;
42 }
43 }
44
45 auto bus = sdbusplus::bus::new_default();
46
47 // If the chassis power status is not good, log an error and exit with
48 // a non-zero rc so the system does not power on
49 auto currentPowerStatus = phosphor::state::manager::utils::getProperty(
50 bus, chassisPath, CHASSIS_BUSNAME, "CurrentPowerStatus");
51 if (currentPowerStatus !=
52 "xyz.openbmc_project.State.Chassis.PowerStatus.Good")
53 {
54 error("Chassis power status is not good: {CURRENT_PWR_STATUS}",
55 "CURRENT_PWR_STATUS", currentPowerStatus);
56
57 // Generate log telling user why system is not powering on
58 const std::string errorMsg =
59 "xyz.openbmc_project.State.ChassisPowerBad";
60 phosphor::state::manager::utils::createError(
61 bus, errorMsg,
Patrick Williams7e969cb2023-08-23 16:24:23 -050062 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level::
Andrew Geissler378fe112022-02-03 16:39:44 -060063 Critical);
64 return -1;
65 }
66 // all good
67 info("Chassis power status good, start power on");
68 return 0;
69}