George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 1 | #include "libpldm/base.h" |
| 2 | #include "libpldm/bios.h" |
| 3 | #include "libpldm/pdr.h" |
| 4 | #include "libpldm/platform.h" |
| 5 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 6 | #include "common/utils.hpp" |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 7 | #include "dbus_impl_pdr.hpp" |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 8 | #include "dbus_impl_requester.hpp" |
Deepak Kodihalli | ac19bd6 | 2020-06-16 08:25:23 -0500 | [diff] [blame] | 9 | #include "host-bmc/dbus_to_host_effecters.hpp" |
| 10 | #include "host-bmc/host_pdr_handler.hpp" |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 11 | #include "invoker.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 12 | #include "libpldmresponder/base.hpp" |
| 13 | #include "libpldmresponder/bios.hpp" |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 14 | #include "libpldmresponder/fru.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 15 | #include "libpldmresponder/platform.hpp" |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 16 | |
| 17 | #include <err.h> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 18 | #include <getopt.h> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 19 | #include <poll.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <sys/socket.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <sys/un.h> |
| 24 | #include <unistd.h> |
| 25 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 26 | #include <sdeventplus/event.hpp> |
| 27 | #include <sdeventplus/source/io.hpp> |
| 28 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 29 | #include <cstdio> |
| 30 | #include <cstring> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 31 | #include <fstream> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 32 | #include <iomanip> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 33 | #include <iostream> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 34 | #include <iterator> |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 35 | #include <memory> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 36 | #include <sstream> |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 37 | #include <stdexcept> |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 38 | #include <string> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 39 | #include <vector> |
| 40 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 41 | #ifdef OEM_IBM |
| 42 | #include "libpldmresponder/file_io.hpp" |
| 43 | #endif |
| 44 | |
| 45 | constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1; |
| 46 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 47 | using namespace pldm::responder; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 48 | using namespace pldm; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 49 | using namespace sdeventplus; |
| 50 | using namespace sdeventplus::source; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 51 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 52 | static Response processRxMsg(const std::vector<uint8_t>& requestMsg, |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 53 | Invoker& invoker, dbus_api::Requester& requester) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 54 | { |
| 55 | |
| 56 | Response response; |
| 57 | uint8_t eid = requestMsg[0]; |
| 58 | uint8_t type = requestMsg[1]; |
| 59 | pldm_header_info hdrFields{}; |
| 60 | auto hdr = reinterpret_cast<const pldm_msg_hdr*>( |
| 61 | requestMsg.data() + sizeof(eid) + sizeof(type)); |
| 62 | if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields)) |
| 63 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 64 | std::cerr << "Empty PLDM request header \n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 65 | } |
| 66 | else if (PLDM_RESPONSE != hdrFields.msg_type) |
| 67 | { |
| 68 | auto request = reinterpret_cast<const pldm_msg*>(hdr); |
| 69 | size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) - |
| 70 | sizeof(eid) - sizeof(type); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 71 | try |
| 72 | { |
| 73 | response = invoker.handle(hdrFields.pldm_type, hdrFields.command, |
| 74 | request, requestLen); |
| 75 | } |
| 76 | catch (const std::out_of_range& e) |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 77 | { |
| 78 | uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 79 | response.resize(sizeof(pldm_msg_hdr)); |
| 80 | auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data()); |
| 81 | pldm_header_info header{}; |
| 82 | header.msg_type = PLDM_RESPONSE; |
| 83 | header.instance = hdrFields.instance; |
| 84 | header.pldm_type = hdrFields.pldm_type; |
| 85 | header.command = hdrFields.command; |
| 86 | auto result = pack_pldm_header(&header, responseHdr); |
| 87 | if (PLDM_SUCCESS != result) |
| 88 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 89 | std::cerr << "Failed adding response header \n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 90 | } |
| 91 | response.insert(response.end(), completion_code); |
| 92 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 93 | } |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 94 | else |
| 95 | { |
| 96 | requester.markFree(eid, hdr->instance_id); |
| 97 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 98 | return response; |
| 99 | } |
| 100 | |
| 101 | void printBuffer(const std::vector<uint8_t>& buffer) |
| 102 | { |
| 103 | std::ostringstream tempStream; |
| 104 | tempStream << "Buffer Data: "; |
| 105 | if (!buffer.empty()) |
| 106 | { |
| 107 | for (int byte : buffer) |
| 108 | { |
| 109 | tempStream << std::setfill('0') << std::setw(2) << std::hex << byte |
| 110 | << " "; |
| 111 | } |
| 112 | } |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 113 | std::cout << tempStream.str().c_str() << std::endl; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 116 | void optionUsage(void) |
| 117 | { |
| 118 | std::cerr << "Usage: pldmd [options]\n"; |
| 119 | std::cerr << "Options:\n"; |
| 120 | std::cerr |
| 121 | << " --verbose=<0/1> 0 - Disable verbosity, 1 - Enable verbosity\n"; |
| 122 | std::cerr << "Defaulted settings: --verbose=0 \n"; |
| 123 | } |
| 124 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 125 | int main(int argc, char** argv) |
| 126 | { |
| 127 | |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 128 | bool verbose = false; |
| 129 | static struct option long_options[] = { |
| 130 | {"verbose", required_argument, 0, 'v'}, {0, 0, 0, 0}}; |
| 131 | |
| 132 | auto argflag = getopt_long(argc, argv, "v:", long_options, nullptr); |
| 133 | switch (argflag) |
| 134 | { |
| 135 | case 'v': |
| 136 | switch (std::stoi(optarg)) |
| 137 | { |
| 138 | case 0: |
| 139 | verbose = false; |
| 140 | break; |
| 141 | case 1: |
| 142 | verbose = true; |
| 143 | break; |
| 144 | default: |
| 145 | optionUsage(); |
| 146 | break; |
| 147 | } |
| 148 | break; |
| 149 | default: |
| 150 | optionUsage(); |
| 151 | break; |
| 152 | } |
| 153 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 154 | /* Create local socket. */ |
| 155 | int returnCode = 0; |
| 156 | int sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
| 157 | if (-1 == sockfd) |
| 158 | { |
| 159 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 160 | std::cerr << "Failed to create the socket, RC= " << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 161 | exit(EXIT_FAILURE); |
| 162 | } |
| 163 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 164 | auto event = Event::get_default(); |
| 165 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo( |
| 166 | pldm_pdr_init(), pldm_pdr_destroy); |
| 167 | std::unique_ptr<pldm_entity_association_tree, |
| 168 | decltype(&pldm_entity_association_tree_destroy)> |
| 169 | entityTree(pldm_entity_association_tree_init(), |
| 170 | pldm_entity_association_tree_destroy); |
| 171 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 172 | dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm"); |
| 173 | std::unique_ptr<HostPDRHandler> hostPDRHandler; |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 174 | std::unique_ptr<pldm::host_effecters::HostEffecterParser> |
| 175 | hostEffecterParser; |
| 176 | DBusHandler dbusHandler; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 177 | auto hostEID = pldm::utils::readHostEID(); |
| 178 | if (hostEID) |
| 179 | { |
| 180 | hostPDRHandler = std::make_unique<HostPDRHandler>( |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 181 | sockfd, hostEID, event, pdrRepo.get(), entityTree.get(), |
| 182 | dbusImplReq); |
Sampa Misra | c0c6054 | 2020-07-01 02:34:25 -0500 | [diff] [blame] | 183 | hostEffecterParser = |
| 184 | std::make_unique<pldm::host_effecters::HostEffecterParser>( |
| 185 | &dbusImplReq, sockfd, pdrRepo.get(), &dbusHandler, |
| 186 | HOST_JSONS_DIR, verbose); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | Invoker invoker{}; |
| 190 | invoker.registerHandler(PLDM_BASE, std::make_unique<base::Handler>()); |
| 191 | invoker.registerHandler(PLDM_BIOS, std::make_unique<bios::Handler>()); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 192 | auto fruHandler = std::make_unique<fru::Handler>( |
| 193 | FRU_JSONS_DIR, pdrRepo.get(), entityTree.get()); |
| 194 | // FRU table is built lazily when a FRU command or Get PDR command is |
| 195 | // handled. To enable building FRU table, the FRU handler is passed to the |
| 196 | // Platform handler. |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 197 | invoker.registerHandler(PLDM_PLATFORM, |
| 198 | std::make_unique<platform::Handler>( |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 199 | dbusHandler, PDR_JSONS_DIR, EVENTS_JSONS_DIR, |
| 200 | pdrRepo.get(), hostPDRHandler.get(), |
| 201 | fruHandler.get())); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 202 | invoker.registerHandler(PLDM_FRU, std::move(fruHandler)); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 203 | |
| 204 | #ifdef OEM_IBM |
| 205 | invoker.registerHandler(PLDM_OEM, std::make_unique<oem_ibm::Handler>()); |
| 206 | #endif |
| 207 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 208 | pldm::utils::CustomFD socketFd(sockfd); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 209 | |
| 210 | struct sockaddr_un addr |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 211 | {}; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 212 | addr.sun_family = AF_UNIX; |
| 213 | const char path[] = "\0mctp-mux"; |
| 214 | memcpy(addr.sun_path, path, sizeof(path) - 1); |
| 215 | int result = connect(socketFd(), reinterpret_cast<struct sockaddr*>(&addr), |
| 216 | sizeof(path) + sizeof(addr.sun_family) - 1); |
| 217 | if (-1 == result) |
| 218 | { |
| 219 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 220 | std::cerr << "Failed to connect to the socket, RC= " << returnCode |
| 221 | << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 222 | exit(EXIT_FAILURE); |
| 223 | } |
| 224 | |
| 225 | result = write(socketFd(), &MCTP_MSG_TYPE_PLDM, sizeof(MCTP_MSG_TYPE_PLDM)); |
| 226 | if (-1 == result) |
| 227 | { |
| 228 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 229 | std::cerr << "Failed to send message type as pldm to mctp, RC= " |
| 230 | << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 231 | exit(EXIT_FAILURE); |
| 232 | } |
| 233 | |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 234 | dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get()); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 235 | auto callback = [verbose, &invoker, &dbusImplReq](IO& /*io*/, int fd, |
| 236 | uint32_t revents) { |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 237 | if (!(revents & EPOLLIN)) |
| 238 | { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | // Outgoing message. |
| 243 | struct iovec iov[2]{}; |
| 244 | |
| 245 | // This structure contains the parameter information for the response |
| 246 | // message. |
| 247 | struct msghdr msg |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 248 | {}; |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 249 | |
| 250 | int returnCode = 0; |
| 251 | ssize_t peekedLength = recv(fd, nullptr, 0, MSG_PEEK | MSG_TRUNC); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 252 | if (0 == peekedLength) |
| 253 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 254 | std::cerr << "Socket has been closed \n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 255 | } |
| 256 | else if (peekedLength <= -1) |
| 257 | { |
| 258 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 259 | std::cerr << "recv system call failed, RC= " << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 260 | } |
| 261 | else |
| 262 | { |
| 263 | std::vector<uint8_t> requestMsg(peekedLength); |
| 264 | auto recvDataLength = recv( |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 265 | fd, static_cast<void*>(requestMsg.data()), peekedLength, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 266 | if (recvDataLength == peekedLength) |
| 267 | { |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 268 | if (verbose) |
| 269 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 270 | std::cout << "Received Msg" << std::endl; |
Jinu Joy Thomas | 75dd442 | 2019-07-22 12:47:12 +0530 | [diff] [blame] | 271 | printBuffer(requestMsg); |
| 272 | } |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 273 | if (MCTP_MSG_TYPE_PLDM != requestMsg[1]) |
| 274 | { |
| 275 | // Skip this message and continue. |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 276 | std::cerr << "Encountered Non-PLDM type message" |
| 277 | << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 278 | } |
| 279 | else |
| 280 | { |
| 281 | // process message and send response |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 282 | auto response = |
| 283 | processRxMsg(requestMsg, invoker, dbusImplReq); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 284 | if (!response.empty()) |
| 285 | { |
Deepak Kodihalli | 8ffbbe0 | 2019-08-14 06:51:38 -0500 | [diff] [blame] | 286 | if (verbose) |
| 287 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 288 | std::cout << "Sending Msg" << std::endl; |
Deepak Kodihalli | 8ffbbe0 | 2019-08-14 06:51:38 -0500 | [diff] [blame] | 289 | printBuffer(response); |
| 290 | } |
| 291 | |
Zahed Hossain | 09a96e0 | 2019-08-06 07:42:37 -0500 | [diff] [blame] | 292 | iov[0].iov_base = &requestMsg[0]; |
| 293 | iov[0].iov_len = |
| 294 | sizeof(requestMsg[0]) + sizeof(requestMsg[1]); |
| 295 | iov[1].iov_base = response.data(); |
| 296 | iov[1].iov_len = response.size(); |
| 297 | |
| 298 | msg.msg_iov = iov; |
| 299 | msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]); |
| 300 | |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 301 | int result = sendmsg(fd, &msg, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 302 | if (-1 == result) |
| 303 | { |
| 304 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 305 | std::cerr << "sendto system call failed, RC= " |
| 306 | << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | else |
| 312 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 313 | std::cerr |
| 314 | << "Failure to read peeked length packet. peekedLength= " |
| 315 | << peekedLength << " recvDataLength=" << recvDataLength |
| 316 | << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 317 | } |
| 318 | } |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 319 | }; |
| 320 | |
Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 321 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 322 | bus.request_name("xyz.openbmc_project.PLDM"); |
Deepak Kodihalli | 37998bf | 2019-11-11 04:06:53 -0600 | [diff] [blame] | 323 | IO io(event, socketFd(), EPOLLIN, std::move(callback)); |
| 324 | event.loop(); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 325 | |
| 326 | result = shutdown(sockfd, SHUT_RDWR); |
| 327 | if (-1 == result) |
| 328 | { |
| 329 | returnCode = -errno; |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 330 | std::cerr << "Failed to shutdown the socket, RC=" << returnCode << "\n"; |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 331 | exit(EXIT_FAILURE); |
| 332 | } |
| 333 | exit(EXIT_FAILURE); |
| 334 | } |