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