From: Romain Forlot Date: Thu, 21 Nov 2019 15:13:52 +0000 (+0100) Subject: socket: Raise an error if open function failed. X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=3111212de145f0bb8b939856ea659c3a86b348d9;p=apps%2Fagl-service-can-low-level.git socket: Raise an error if open function failed. The socket opening wasn't tested and we fails later on another function using the wrongly opened socket. This would not happens anymore. Change-Id: I9b30bd9fc13b99277cbef6f7aeaddadc57ad0b18 Signed-off-by: Romain Forlot --- diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp index 5cc96eda..000999ff 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp @@ -169,6 +169,8 @@ namespace utils { socket_ = socketcan_t::open(PF_CAN, SOCK_DGRAM, CAN_J1939); + if (socket_ < 0) + return socket_; define_tx_address(device_name, name, pgn, addr); diff --git a/low-can-binding/utils/socketcan.cpp b/low-can-binding/utils/socketcan.cpp index 50dfafb3..e8e01980 100644 --- a/low-can-binding/utils/socketcan.cpp +++ b/low-can-binding/utils/socketcan.cpp @@ -73,6 +73,9 @@ namespace utils { close(); socket_ = ::socket(domain, type, protocol); + if (socket_ < 0) + AFB_ERROR("Open failed. %s", strerror(errno)); + return socket_; }