| 178 | } /* extern "C" */ |
| 179 | |
| 180 | void react(int fd, const char* func, int _errno) { |
| 181 | // if this happens, there is a serious logical issue somewhere: |
| 182 | // 1) application accidentally close'd a descriptor that belongs to libvsomeip |
| 183 | // 2) libvsomeip itself double close'd a descriptor |
| 184 | |
| 185 | const int e = (_errno != 0) ? _errno : errno; |
| 186 | |
| 187 | char errno_buf[32]; |
| 188 | const char* errno_str; |
| 189 | // EBADF and EINVAL are handled differently in order to keep compatibility. |
| 190 | // Previous versions had a "EBADF" and `strerrorname_np` is GNU/Linux only. |
| 191 | if (errno == EBADF) { |
| 192 | errno_str = "EBADF"; |
| 193 | } else if (errno == EINVAL) { |
| 194 | errno_str = "EINVAL"; |
| 195 | } else { |
| 196 | snprintf(errno_buf, sizeof(errno_buf), "%d", e); |
| 197 | errno_str = errno_buf; |
| 198 | } |
| 199 | |
| 200 | std::string msg = std::string(func) + "(" + std::to_string(fd) + ") failed with errno " + std::string(errno_str) + ", descriptor leak!"; |
| 201 | |
| 202 | VSOMEIP_FATAL << msg; |
| 203 | std::cerr << "[libvsomeip] " << msg << "\n"; |
| 204 | |
| 205 | const auto st = boost::stacktrace::stacktrace(); |
| 206 | for (const auto& frame : st) { |
| 207 | VSOMEIP_FATAL << frame; |
| 208 | std::cerr << frame; |
| 209 | } |
| 210 | |
| 211 | VSOMEIP_TERMINATE(msg.c_str()); |
| 212 | } |
| 213 | |
| 214 | #endif |
no test coverage detected