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