Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 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> |
Patrick Williams | 7a7c38d | 2023-09-06 22:00:15 -0500 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Common/error.hpp> |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 13 | |
| 14 | #include <iostream> |
| 15 | #include <map> |
| 16 | #include <string> |
| 17 | |
| 18 | PHOSPHOR_LOG2_USING; |
| 19 | |
| 20 | using namespace phosphor::logging; |
| 21 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 22 | |
| 23 | int main(int argc, char** argv) |
| 24 | { |
| 25 | std::string chassisPath = "/xyz/openbmc_project/state/chassis0"; |
| 26 | int arg; |
| 27 | int optIndex = 0; |
| 28 | |
Pavithra Barithaya | f15b954 | 2024-06-21 08:18:48 -0500 | [diff] [blame^] | 29 | static struct option longOpts[] = { |
| 30 | {"chassis", required_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}}; |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 31 | |
| 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 Williams | 7e969cb | 2023-08-23 16:24:23 -0500 | [diff] [blame] | 62 | sdbusplus::server::xyz::openbmc_project::logging::Entry::Level:: |
Andrew Geissler | 378fe11 | 2022-02-03 16:39:44 -0600 | [diff] [blame] | 63 | Critical); |
| 64 | return -1; |
| 65 | } |
| 66 | // all good |
| 67 | info("Chassis power status good, start power on"); |
| 68 | return 0; |
| 69 | } |