diff --git a/src/lib/cc/cc_messages.mes b/src/lib/cc/cc_messages.mes index 05052f1a73..c19cc5cd7d 100644 --- a/src/lib/cc/cc_messages.mes +++ b/src/lib/cc/cc_messages.mes @@ -13,3 +13,23 @@ # PERFORMANCE OF THIS SOFTWARE. $NAMESPACE isc::cc + +% CC_CONN_ERROR error connecting to message queue (%1) + +% CC_NO_MSGQ unable to connect to message queue (%1) + +% CC_WRITE_ERROR error writing data to command channel (%1) + +% CC_LENGTH_NOT_READY length not ready + +% CC_READ_EXCEPTION error reading data from command channel (%1) + +% CC_TIMEOUT timeout reading data from command channel + +% CC_READ_ERROR error reading data from command channel (%1) + +% CC_ZERO_LENGTH invalid message length (0) + +% CC_ASYNC_READ_FAILED asynchronous read failed + +% CC_INVALID_LENGTHS invalid length parameters (%1, %2) diff --git a/src/lib/cc/session.cc b/src/lib/cc/session.cc index e911a86a63..4729a0e490 100644 --- a/src/lib/cc/session.cc +++ b/src/lib/cc/session.cc @@ -14,6 +14,7 @@ #include #include +#include #include @@ -121,9 +122,11 @@ SessionImpl::establish(const char& socket_file) { socket_.connect(asio::local::stream_protocol::endpoint(&socket_file), error_); } catch(const asio::system_error& se) { + LOG_FATAL(logger, CC_CONN_ERROR).arg(se.what()); isc_throw(SessionError, se.what()); } if (error_) { + LOG_FATAL(logger, CC_NO_MSGQ).arg(error_.message()); isc_throw(SessionError, "Unable to connect to message queue: " << error_.message()); } @@ -140,6 +143,7 @@ SessionImpl::writeData(const void* data, size_t datalen) { try { asio::write(socket_, asio::buffer(data, datalen)); } catch (const asio::system_error& asio_ex) { + LOG_FATAL(logger, CC_WRITE_ERROR).arg(asio_ex.what()); isc_throw(SessionError, "ASIO write failed: " << asio_ex.what()); } } @@ -151,6 +155,7 @@ SessionImpl::readDataLength() { if (ret_len == 0) { readData(&data_length_, sizeof(data_length_)); if (data_length_ == 0) { + LOG_ERROR(logger, CC_LENGTH_NOT_READY); isc_throw(SessionError, "ASIO read: data length is not ready"); } ret_len = ntohl(data_length_); @@ -199,9 +204,11 @@ SessionImpl::readData(void* data, size_t datalen) { // asio::error_code evaluates to false if there was no error if (*read_result) { if (*read_result == asio::error::operation_aborted) { + LOG_ERROR(logger, CC_TIMEOUT); isc_throw(SessionTimeout, "Timeout while reading data from cc session"); } else { + LOG_ERROR(logger, CC_READ_ERROR).arg(read_result->message()); isc_throw(SessionError, "Error while reading data from cc session: " << read_result->message()); @@ -210,6 +217,7 @@ SessionImpl::readData(void* data, size_t datalen) { } catch (const asio::system_error& asio_ex) { // to hide ASIO specific exceptions, we catch them explicitly // and convert it to SessionError. + LOG_FATAL(logger, CC_READ_EXCEPTION).arg(asio_ex.what()); isc_throw(SessionError, "ASIO read failed: " << asio_ex.what()); } } @@ -233,10 +241,12 @@ SessionImpl::internalRead(const asio::error_code& error, assert(bytes_transferred == sizeof(data_length_)); data_length_ = ntohl(data_length_); if (data_length_ == 0) { + LOG_ERROR(logger, CC_ZERO_LENGTH); isc_throw(SessionError, "Invalid message length (0)"); } user_handler_(); } else { + LOG_ERROR(logger, CC_ASYNC_READ_FAILED); isc_throw(SessionError, "asynchronous read failed"); } } @@ -374,6 +384,7 @@ Session::recvmsg(ConstElementPtr& env, ConstElementPtr& msg, unsigned short header_length = ntohs(header_length_net); if (header_length > length || length < 2) { + LOG_ERROR(logger, CC_INVALID_LENGTHS).arg(length).arg(header_length); isc_throw(SessionError, "Length parameters invalid: total=" << length << ", header=" << header_length); } diff --git a/src/lib/cc/tests/run_unittests.cc b/src/lib/cc/tests/run_unittests.cc index eeef955399..299bd967c0 100644 --- a/src/lib/cc/tests/run_unittests.cc +++ b/src/lib/cc/tests/run_unittests.cc @@ -14,9 +14,13 @@ #include #include +#include int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); + + isc::log::initLogger(); + return (isc::util::unittests::run_all()); }