Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 3 | #include "systemd_service_parser.hpp" |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 4 | #include "systemd_target_parser.hpp" |
| 5 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/bus/match.hpp> |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 8 | |
| 9 | extern bool gVerbose; |
| 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace state |
| 14 | { |
| 15 | namespace manager |
| 16 | { |
| 17 | /** @class SystemdTargetLogging |
| 18 | * @brief Object to monitor input systemd targets and create corresponding |
| 19 | * input errors for on failures |
| 20 | */ |
| 21 | class SystemdTargetLogging |
| 22 | { |
| 23 | public: |
| 24 | SystemdTargetLogging() = delete; |
| 25 | SystemdTargetLogging(const SystemdTargetLogging&) = delete; |
| 26 | SystemdTargetLogging& operator=(const SystemdTargetLogging&) = delete; |
| 27 | SystemdTargetLogging(SystemdTargetLogging&&) = delete; |
| 28 | SystemdTargetLogging& operator=(SystemdTargetLogging&&) = delete; |
| 29 | virtual ~SystemdTargetLogging() = default; |
| 30 | |
| 31 | SystemdTargetLogging(const TargetErrorData& targetData, |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 32 | const ServiceMonitorData& serviceData, |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 33 | sdbusplus::bus::bus& bus) : |
| 34 | targetData(targetData), |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 35 | serviceData(serviceData), bus(bus), |
Andrew Geissler | b558ae7 | 2019-11-07 10:40:06 -0600 | [diff] [blame] | 36 | systemdJobRemovedSignal( |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 37 | bus, |
| 38 | sdbusplus::bus::match::rules::type::signal() + |
| 39 | sdbusplus::bus::match::rules::member("JobRemoved") + |
| 40 | sdbusplus::bus::match::rules::path( |
| 41 | "/org/freedesktop/systemd1") + |
| 42 | sdbusplus::bus::match::rules::interface( |
| 43 | "org.freedesktop.systemd1.Manager"), |
| 44 | std::bind(std::mem_fn(&SystemdTargetLogging::systemdUnitChange), |
Andrew Geissler | 38605ee | 2019-11-11 16:01:56 -0600 | [diff] [blame] | 45 | this, std::placeholders::_1)), |
| 46 | systemdNameOwnedChangedSignal( |
| 47 | bus, sdbusplus::bus::match::rules::nameOwnerChanged(), |
| 48 | std::bind( |
| 49 | std::mem_fn(&SystemdTargetLogging::processNameChangeSignal), |
| 50 | this, std::placeholders::_1)) |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 51 | {} |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * @brief subscribe to the systemd signals |
| 55 | * |
| 56 | * This object needs to monitor systemd target changes so it can create |
| 57 | * the required error logs on failures |
| 58 | * |
| 59 | **/ |
| 60 | void subscribeToSystemdSignals(); |
| 61 | |
| 62 | /** @brief Process the target fail and return error to log |
| 63 | * |
| 64 | * @note This is public for unit testing purposes |
| 65 | * |
| 66 | * @param[in] unit - The systemd unit that failed |
| 67 | * @param[in] result - The failure code from the system unit |
| 68 | * |
| 69 | * @return valid pointer to error to log, otherwise nullptr |
| 70 | */ |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 71 | const std::string processError(const std::string& unit, |
| 72 | const std::string& result); |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 73 | |
| 74 | private: |
Andrew Geissler | 21d305e | 2022-02-11 16:49:51 -0600 | [diff] [blame] | 75 | /** @brief Call phosphor-dump-manager to create BMC dump */ |
| 76 | void createBmcDump(); |
| 77 | |
Andrew Geissler | 73d2ac9 | 2022-02-17 16:55:50 -0600 | [diff] [blame] | 78 | /** @brief Start BMC Quiesce Target to indicate critical service failure */ |
| 79 | void startBmcQuiesceTarget(); |
| 80 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 81 | /** @brief Call phosphor-logging to create error |
| 82 | * |
| 83 | * @param[in] error - The error to log |
| 84 | * @param[in] result - The failure code from the systemd unit |
Andrew Geissler | e684103 | 2022-02-11 10:31:50 -0600 | [diff] [blame] | 85 | * @param[in] unit - The name of the failed unit |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 86 | */ |
Andrew Geissler | e684103 | 2022-02-11 10:31:50 -0600 | [diff] [blame] | 87 | void logError(const std::string& error, const std::string& result, |
| 88 | const std::string& unit); |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 89 | |
| 90 | /** @brief Check if systemd state change is one to monitor |
| 91 | * |
| 92 | * Instance specific interface to handle the detected systemd state |
| 93 | * change |
| 94 | * |
| 95 | * @param[in] msg - Data associated with subscribed signal |
| 96 | * |
| 97 | */ |
| 98 | void systemdUnitChange(sdbusplus::message::message& msg); |
| 99 | |
Andrew Geissler | 38605ee | 2019-11-11 16:01:56 -0600 | [diff] [blame] | 100 | /** @brief Wait for systemd to show up on dbus |
| 101 | * |
| 102 | * Once systemd is on dbus, this application can subscribe to systemd |
| 103 | * signal changes |
| 104 | * |
| 105 | * @param[in] msg - Data associated with subscribed signal |
| 106 | * |
| 107 | */ |
| 108 | void processNameChangeSignal(sdbusplus::message::message& msg); |
| 109 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 110 | /** @brief Systemd targets to monitor and error logs to create */ |
| 111 | const TargetErrorData& targetData; |
| 112 | |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 113 | /** @brief Systemd targets to monitor and error logs to create */ |
| 114 | const ServiceMonitorData& serviceData; |
| 115 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 116 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 117 | sdbusplus::bus::bus& bus; |
| 118 | |
Andrew Geissler | b558ae7 | 2019-11-07 10:40:06 -0600 | [diff] [blame] | 119 | /** @brief Used to subscribe to dbus systemd JobRemoved signals **/ |
| 120 | sdbusplus::bus::match_t systemdJobRemovedSignal; |
Andrew Geissler | 38605ee | 2019-11-11 16:01:56 -0600 | [diff] [blame] | 121 | |
| 122 | /** @brief Used to know when systemd has registered on dbus **/ |
| 123 | sdbusplus::bus::match_t systemdNameOwnedChangedSignal; |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace manager |
| 127 | } // namespace state |
| 128 | } // namespace phosphor |