Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 17 | #ifdef ENABLE_IPMI_SNOOP |
| 18 | #include "ipmisnoop/ipmisnoop.hpp" |
| 19 | #endif |
| 20 | |
Patrick Venture | b5754fd | 2018-09-10 13:13:58 -0700 | [diff] [blame] | 21 | #include "lpcsnoop/snoop.hpp" |
| 22 | |
William A. Kennington III | 6dac4c5 | 2019-12-13 15:05:00 -0800 | [diff] [blame] | 23 | #include <endian.h> |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 24 | #include <fcntl.h> |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 25 | #include <getopt.h> |
Patrick Venture | b5754fd | 2018-09-10 13:13:58 -0700 | [diff] [blame] | 26 | #include <sys/epoll.h> |
| 27 | #include <systemd/sd-event.h> |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 30 | #include <cstdint> |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 31 | #include <exception> |
Willy Tu | d1ac197 | 2022-03-21 16:20:39 -0700 | [diff] [blame] | 32 | #include <functional> |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 33 | #include <iostream> |
William A. Kennington III | b3baa68 | 2021-12-19 20:47:05 -0800 | [diff] [blame] | 34 | #include <optional> |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 35 | #include <sdeventplus/event.hpp> |
| 36 | #include <sdeventplus/source/event.hpp> |
| 37 | #include <sdeventplus/source/io.hpp> |
William A. Kennington III | 6a5e0a1 | 2021-12-19 20:47:34 -0800 | [diff] [blame] | 38 | #include <sdeventplus/source/signal.hpp> |
William A. Kennington III | 30751ec | 2022-11-21 18:38:36 -0800 | [diff] [blame] | 39 | #include <sdeventplus/utility/sdbus.hpp> |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 40 | #include <span> |
William A. Kennington III | 6a5e0a1 | 2021-12-19 20:47:34 -0800 | [diff] [blame] | 41 | #include <stdplus/signal.hpp> |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 42 | #include <thread> |
| 43 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 44 | #ifdef ENABLE_IPMI_SNOOP |
| 45 | #include <xyz/openbmc_project/State/Boot/Raw/server.hpp> |
| 46 | #endif |
| 47 | |
Benjamin Fair | f69ad7e | 2018-07-13 13:41:10 -0700 | [diff] [blame] | 48 | static size_t codeSize = 1; /* Size of each POST code in bytes */ |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 49 | const char* defaultHostInstances = "0"; |
Brad Bishop | 8f6c0ce | 2022-05-03 17:29:05 -0400 | [diff] [blame] | 50 | #ifdef ENABLE_IPMI_SNOOP |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 51 | const uint8_t minPositionVal = 0; |
| 52 | const uint8_t maxPositionVal = 5; |
Brad Bishop | 8f6c0ce | 2022-05-03 17:29:05 -0400 | [diff] [blame] | 53 | #endif |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 54 | |
| 55 | #ifdef ENABLE_IPMI_SNOOP |
| 56 | std::vector<std::unique_ptr<IpmiPostReporter>> reporters; |
| 57 | #endif |
| 58 | |
| 59 | #ifdef ENABLE_IPMI_SNOOP |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 60 | void IpmiPostReporter::getSelectorPositionSignal(sdbusplus::bus_t& bus) |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 61 | { |
| 62 | size_t posVal = 0; |
| 63 | |
| 64 | matchSignal = std::make_unique<sdbusplus::bus::match_t>( |
| 65 | bus, |
| 66 | sdbusplus::bus::match::rules::propertiesChanged(selectorObject, |
| 67 | selectorIface), |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 68 | [&](sdbusplus::message_t& msg) { |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 69 | std::string objectName; |
| 70 | std::map<std::string, Selector::PropertiesVariant> msgData; |
| 71 | msg.read(objectName, msgData); |
| 72 | |
| 73 | auto valPropMap = msgData.find("Position"); |
| 74 | { |
| 75 | if (valPropMap == msgData.end()) |
| 76 | { |
| 77 | std::cerr << "Position property not found " << std::endl; |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | posVal = std::get<size_t>(valPropMap->second); |
| 82 | |
| 83 | if (posVal > minPositionVal && posVal < maxPositionVal) |
| 84 | { |
| 85 | std::tuple<uint64_t, secondary_post_code_t> postcodes = |
| 86 | reporters[posVal - 1]->value(); |
| 87 | uint64_t postcode = std::get<uint64_t>(postcodes); |
| 88 | |
| 89 | // write postcode into seven segment display |
| 90 | if (postCodeDisplay(postcode) < 0) |
| 91 | { |
| 92 | fprintf(stderr, "Error in display the postcode\n"); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | }); |
| 97 | } |
| 98 | #endif |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 99 | |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 100 | static void usage(const char* name) |
| 101 | { |
| 102 | fprintf(stderr, |
| 103 | "Usage: %s [-d <DEVICE>]\n" |
Benjamin Fair | f69ad7e | 2018-07-13 13:41:10 -0700 | [diff] [blame] | 104 | " -b, --bytes <SIZE> set POST code length to <SIZE> bytes. " |
| 105 | "Default is %zu\n" |
Manojkiran Eda | aade4ad | 2021-02-19 11:20:33 +0530 | [diff] [blame] | 106 | " -d, --device <DEVICE> use <DEVICE> file.\n" |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 107 | " -h, --host <host instances> . Default is '%s'\n" |
William A. Kennington III | 66efa63 | 2020-04-16 18:46:20 -0700 | [diff] [blame] | 108 | " -v, --verbose Prints verbose information while running\n\n", |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 109 | name, codeSize, defaultHostInstances); |
Benjamin Fair | f69ad7e | 2018-07-13 13:41:10 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 112 | /* |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 113 | * Callback handling IO event from the POST code fd. i.e. there is new |
| 114 | * POST code available to read. |
| 115 | */ |
Willy Tu | d1ac197 | 2022-03-21 16:20:39 -0700 | [diff] [blame] | 116 | void PostCodeEventHandler(PostReporter* reporter, bool verbose, |
| 117 | sdeventplus::source::IO& s, int postFd, uint32_t) |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 118 | { |
William A. Kennington III | 6dac4c5 | 2019-12-13 15:05:00 -0800 | [diff] [blame] | 119 | uint64_t code = 0; |
William A. Kennington III | 0f964b4 | 2020-04-16 18:46:03 -0700 | [diff] [blame] | 120 | ssize_t readb; |
| 121 | while ((readb = read(postFd, &code, codeSize)) > 0) |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 122 | { |
William A. Kennington III | f21475a | 2019-12-13 17:21:24 -0800 | [diff] [blame] | 123 | code = le64toh(code); |
William A. Kennington III | 66efa63 | 2020-04-16 18:46:20 -0700 | [diff] [blame] | 124 | if (verbose) |
| 125 | { |
| 126 | fprintf(stderr, "Code: 0x%" PRIx64 "\n", code); |
| 127 | } |
William A. Kennington III | f21475a | 2019-12-13 17:21:24 -0800 | [diff] [blame] | 128 | // HACK: Always send property changed signal even for the same code |
| 129 | // since we are single threaded, external users will never see the |
| 130 | // first value. |
Manojkiran Eda | ba5258f | 2021-02-25 13:23:33 +0530 | [diff] [blame] | 131 | reporter->value(std::make_tuple(~code, secondary_post_code_t{}), true); |
| 132 | reporter->value(std::make_tuple(code, secondary_post_code_t{})); |
William A. Kennington III | 0f964b4 | 2020-04-16 18:46:03 -0700 | [diff] [blame] | 133 | |
| 134 | // read depends on old data being cleared since it doens't always read |
| 135 | // the full code size |
| 136 | code = 0; |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 137 | } |
William A. Kennington III | 0f964b4 | 2020-04-16 18:46:03 -0700 | [diff] [blame] | 138 | |
| 139 | if (readb < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) |
| 140 | { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | /* Read failure. */ |
| 145 | if (readb == 0) |
| 146 | { |
| 147 | fprintf(stderr, "Unexpected EOF reading postcode\n"); |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | fprintf(stderr, "Failed to read postcode: %s\n", strerror(errno)); |
| 152 | } |
| 153 | s.get_event().exit(1); |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 156 | #ifdef ENABLE_IPMI_SNOOP |
| 157 | // handle muti-host D-bus |
| 158 | int postCodeIpmiHandler(const std::string& snoopObject, |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 159 | const std::string& snoopDbus, sdbusplus::bus_t& bus, |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 160 | std::span<std::string> host) |
| 161 | { |
| 162 | int ret = 0; |
| 163 | |
| 164 | try |
| 165 | { |
| 166 | for (size_t iteration = 0; iteration < host.size(); iteration++) |
| 167 | { |
| 168 | std::string objPathInst = snoopObject + host[iteration]; |
| 169 | |
| 170 | sdbusplus::server::manager_t m{bus, objPathInst.c_str()}; |
| 171 | |
| 172 | /* Create a monitor object and let it do all the rest */ |
| 173 | reporters.emplace_back( |
| 174 | std::make_unique<IpmiPostReporter>(bus, objPathInst.c_str())); |
| 175 | |
| 176 | reporters[iteration]->emit_object_added(); |
| 177 | } |
| 178 | |
| 179 | bus.request_name(snoopDbus.c_str()); |
Kumar Thangavel | aee6540 | 2022-08-09 17:21:48 +0530 | [diff] [blame] | 180 | |
| 181 | /* sevenSegmentLedEnabled flag is unset when GPIO pins are not there 7 |
| 182 | seg display for fewer platforms. So, the code for postcode dispay and |
| 183 | Get Selector position can be skipped in those platforms. |
| 184 | */ |
| 185 | if (sevenSegmentLedEnabled) |
| 186 | { |
| 187 | reporters[0]->getSelectorPositionSignal(bus); |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | reporters.clear(); |
| 192 | } |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 193 | } |
| 194 | catch (const std::exception& e) |
| 195 | { |
| 196 | fprintf(stderr, "%s\n", e.what()); |
| 197 | } |
| 198 | |
| 199 | // Configure seven segment dsiplay connected to GPIOs as output |
| 200 | ret = configGPIODirOutput(); |
| 201 | if (ret < 0) |
| 202 | { |
Kumar Thangavel | aee6540 | 2022-08-09 17:21:48 +0530 | [diff] [blame] | 203 | fprintf(stderr, "Failed find the gpio line. Cannot display postcodes " |
| 204 | "in seven segment display..\n"); |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | while (true) |
| 208 | { |
| 209 | bus.process_discard(); |
| 210 | bus.wait(); |
| 211 | } |
| 212 | exit(EXIT_SUCCESS); |
| 213 | } |
| 214 | #endif |
| 215 | |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 216 | /* |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 217 | * TODO(venture): this only listens one of the possible snoop ports, but |
| 218 | * doesn't share the namespace. |
| 219 | * |
| 220 | * This polls() the lpc snoop character device and it owns the dbus object |
| 221 | * whose value is the latest port 80h value. |
| 222 | */ |
| 223 | int main(int argc, char* argv[]) |
| 224 | { |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 225 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 226 | #ifndef ENABLE_IPMI_SNOOP |
| 227 | int postFd = -1; |
| 228 | #endif |
| 229 | |
| 230 | int opt; |
| 231 | bool verbose = false; |
| 232 | |
| 233 | #ifdef ENABLE_IPMI_SNOOP |
| 234 | std::vector<std::string> host; |
| 235 | #endif |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 236 | /* |
| 237 | * These string constants are only used in this method within this object |
| 238 | * and this object is the only object feeding into the final binary. |
| 239 | * |
| 240 | * If however, another object is added to this binary it would be proper |
| 241 | * to move these declarations to be global and extern to the other object. |
| 242 | */ |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 243 | |
Patrick Venture | 1ceb21b | 2018-08-08 11:29:36 -0700 | [diff] [blame] | 244 | // clang-format off |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 245 | static const struct option long_options[] = { |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 246 | #ifdef ENABLE_IPMI_SNOOP |
| 247 | {"host", optional_argument, NULL, 'h'}, |
| 248 | #endif |
Patrick Venture | 1ceb21b | 2018-08-08 11:29:36 -0700 | [diff] [blame] | 249 | {"bytes", required_argument, NULL, 'b'}, |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 250 | #ifndef ENABLE_IPMI_SNOOP |
Manojkiran Eda | aade4ad | 2021-02-19 11:20:33 +0530 | [diff] [blame] | 251 | {"device", optional_argument, NULL, 'd'}, |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 252 | #endif |
William A. Kennington III | 66efa63 | 2020-04-16 18:46:20 -0700 | [diff] [blame] | 253 | {"verbose", no_argument, NULL, 'v'}, |
Patrick Venture | 1ceb21b | 2018-08-08 11:29:36 -0700 | [diff] [blame] | 254 | {0, 0, 0, 0} |
| 255 | }; |
| 256 | // clang-format on |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 257 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 258 | while ((opt = getopt_long(argc, argv, "h:b:d:v", long_options, NULL)) != -1) |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 259 | { |
| 260 | switch (opt) |
| 261 | { |
| 262 | case 0: |
| 263 | break; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 264 | #ifdef ENABLE_IPMI_SNOOP |
| 265 | case 'h': { |
| 266 | std::string_view instances = optarg; |
| 267 | size_t pos = 0; |
| 268 | |
| 269 | while ((pos = instances.find(" ")) != std::string::npos) |
| 270 | { |
| 271 | host.emplace_back(instances.substr(0, pos)); |
| 272 | instances.remove_prefix(pos + 1); |
| 273 | } |
| 274 | host.emplace_back(instances); |
| 275 | break; |
| 276 | } |
| 277 | #endif |
| 278 | case 'b': { |
Benjamin Fair | f69ad7e | 2018-07-13 13:41:10 -0700 | [diff] [blame] | 279 | codeSize = atoi(optarg); |
| 280 | |
| 281 | if (codeSize < 1 || codeSize > 8) |
| 282 | { |
| 283 | fprintf(stderr, |
| 284 | "Invalid POST code size '%s'. Must be " |
| 285 | "an integer from 1 to 8.\n", |
| 286 | optarg); |
| 287 | exit(EXIT_FAILURE); |
| 288 | } |
| 289 | break; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 290 | } |
| 291 | #ifndef ENABLE_IPMI_SNOOP |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 292 | case 'd': |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 293 | |
Manojkiran Eda | aade4ad | 2021-02-19 11:20:33 +0530 | [diff] [blame] | 294 | postFd = open(optarg, O_NONBLOCK); |
| 295 | if (postFd < 0) |
| 296 | { |
| 297 | fprintf(stderr, "Unable to open: %s\n", optarg); |
| 298 | return -1; |
| 299 | } |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 300 | break; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 301 | #endif |
William A. Kennington III | 66efa63 | 2020-04-16 18:46:20 -0700 | [diff] [blame] | 302 | case 'v': |
| 303 | verbose = true; |
| 304 | break; |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 305 | default: |
| 306 | usage(argv[0]); |
Benjamin Fair | e7b07f0 | 2018-07-02 09:51:37 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 310 | auto bus = sdbusplus::bus::new_default(); |
| 311 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 312 | #ifdef ENABLE_IPMI_SNOOP |
| 313 | std::cout << "Verbose = " << verbose << std::endl; |
| 314 | int ret = postCodeIpmiHandler(ipmiSnoopObject, snoopDbus, bus, host); |
| 315 | if (ret < 0) |
| 316 | { |
| 317 | fprintf(stderr, "Error in postCodeIpmiHandler\n"); |
| 318 | return ret; |
| 319 | } |
| 320 | return 0; |
| 321 | #endif |
| 322 | |
| 323 | #ifndef ENABLE_IPMI_SNOOP |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 324 | |
| 325 | bool deferSignals = true; |
| 326 | |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 327 | // Add systemd object manager. |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 328 | sdbusplus::server::manager_t snoopdManager(bus, snoopObject); |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 329 | |
| 330 | PostReporter reporter(bus, snoopObject, deferSignals); |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 331 | reporter.emit_object_added(); |
| 332 | bus.request_name(snoopDbus); |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 333 | |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 334 | // Create sdevent and add IO source |
| 335 | try |
| 336 | { |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 337 | sdeventplus::Event event = sdeventplus::Event::get_default(); |
Harvey.Wu | 4f26b3e | 2022-05-12 08:54:30 +0800 | [diff] [blame] | 338 | std::optional<sdeventplus::source::IO> reporterSource; |
Manojkiran Eda | aade4ad | 2021-02-19 11:20:33 +0530 | [diff] [blame] | 339 | if (postFd > 0) |
| 340 | { |
Harvey.Wu | 4f26b3e | 2022-05-12 08:54:30 +0800 | [diff] [blame] | 341 | reporterSource.emplace( |
Manojkiran Eda | aade4ad | 2021-02-19 11:20:33 +0530 | [diff] [blame] | 342 | event, postFd, EPOLLIN | EPOLLET, |
Willy Tu | d1ac197 | 2022-03-21 16:20:39 -0700 | [diff] [blame] | 343 | std::bind_front(PostCodeEventHandler, &reporter, verbose)); |
Manojkiran Eda | aade4ad | 2021-02-19 11:20:33 +0530 | [diff] [blame] | 344 | } |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 345 | // Enable bus to handle incoming IO and bus events |
William A. Kennington III | 30751ec | 2022-11-21 18:38:36 -0800 | [diff] [blame] | 346 | auto intCb = [](sdeventplus::source::Signal& source, |
| 347 | const struct signalfd_siginfo*) { |
William A. Kennington III | 6a5e0a1 | 2021-12-19 20:47:34 -0800 | [diff] [blame] | 348 | source.get_event().exit(0); |
| 349 | }; |
| 350 | stdplus::signal::block(SIGINT); |
| 351 | sdeventplus::source::Signal(event, SIGINT, intCb).set_floating(true); |
| 352 | stdplus::signal::block(SIGTERM); |
| 353 | sdeventplus::source::Signal(event, SIGTERM, std::move(intCb)) |
| 354 | .set_floating(true); |
William A. Kennington III | 30751ec | 2022-11-21 18:38:36 -0800 | [diff] [blame] | 355 | return sdeventplus::utility::loopWithBus(event, bus); |
Kun Yi | 1c16ad8 | 2018-09-12 10:01:49 -0700 | [diff] [blame] | 356 | } |
| 357 | catch (const std::exception& e) |
| 358 | { |
| 359 | fprintf(stderr, "%s\n", e.what()); |
| 360 | } |
Kun Yi | eb31231 | 2018-06-13 09:20:50 -0700 | [diff] [blame] | 361 | |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 362 | if (postFd > -1) |
| 363 | { |
| 364 | close(postFd); |
| 365 | } |
| 366 | |
Sunita Kumari | 56127ef | 2022-10-12 05:01:20 +0000 | [diff] [blame] | 367 | return 0; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 368 | #endif |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 369 | } |