From 95bc5a871b6a3e823cc6ed1c7564e3540456fda0 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 6 Jun 2020 13:56:35 +0200 Subject: [PATCH] improved diagnostic messages for linux --- devicehandlers/DeviceHandlerBase.cpp | 2 +- osal/linux/MessageQueue.cpp | 32 ++++++++++++++++++++++------ osal/linux/MessageQueue.h | 2 +- osal/linux/PosixThread.cpp | 2 +- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index c73cf618..965959af 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -36,7 +36,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode( SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { - commandQueue = QueueFactory::instance()->createMessageQueue(1, + commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; insertInCommandMap(RAW_COMMAND_ID); diff --git a/osal/linux/MessageQueue.cpp b/osal/linux/MessageQueue.cpp index 08a9ab20..493c2aca 100644 --- a/osal/linux/MessageQueue.cpp +++ b/osal/linux/MessageQueue.cpp @@ -1,12 +1,14 @@ #include #include + +#include + #include /* For O_* constants */ #include /* For mode constants */ #include #include - MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize): id(0), lastPartner(0), defaultDestination(NO_QUEUE) { //debug << "MessageQueue::MessageQueue: Creating a queue" << std::endl; @@ -22,10 +24,11 @@ MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize): id(0), // Create a nonblocking queue if the name is available (the queue is read // and writable for the owner as well as the group) - mqd_t tempId = mq_open(name, O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL, - S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH, &attributes); + int oflag = O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL; + mode_t mode = S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH; + mqd_t tempId = mq_open(name, oflag, mode, &attributes); if (tempId == -1) { - handleError(&attributes); + handleError(&attributes, messageDepth); } else { //Successful mq_open call @@ -46,10 +49,27 @@ MessageQueue::~MessageQueue() { } } -ReturnValue_t MessageQueue::handleError(mq_attr* attributes) { +ReturnValue_t MessageQueue::handleError(mq_attr* attributes, + uint32_t messageDepth) { switch(errno) { case(EINVAL): { - sif::error << "MessageQueue::MessageQueue: Invalid Name " << std::endl; + sif::error << "MessageQueue::MessageQueue: Invalid Name or attributes" + " for message size" << std::endl; + size_t defaultMqMaxMsg; + if(std::ifstream("/proc/sys/fs/mqueue/msg_max",std::ios::in) >> + defaultMqMaxMsg and defaultMqMaxMsg < messageDepth) { + // See: https://www.man7.org/linux/man-pages/man3/mq_open.3.html + // This happens if the msg_max value is not large enough + // It is ignored if the executable is run in privileged mode. + // Run the unlockRealtime script or grant the mode manully by using: + // sudo setcap 'CAP_SYS_RESOURCE=+ep' + + // Permanent solution: + // echo msg_max | sudo tee /proc/sys/fs/mqueue/msg_max + sif::error << "MessageQueue::MessageQueue: Default MQ size " + << defaultMqMaxMsg << " is too small for requested size " + << messageDepth << std::endl; + } break; } case(EEXIST): { diff --git a/osal/linux/MessageQueue.h b/osal/linux/MessageQueue.h index debf9cd1..2808d36e 100644 --- a/osal/linux/MessageQueue.h +++ b/osal/linux/MessageQueue.h @@ -175,7 +175,7 @@ private: static uint16_t queueCounter; - ReturnValue_t handleError(mq_attr* attributes); + ReturnValue_t handleError(mq_attr* attributes, uint32_t messageDepth); }; #endif /* MESSAGEQUEUE_H_ */ diff --git a/osal/linux/PosixThread.cpp b/osal/linux/PosixThread.cpp index 899700f0..e8d624ca 100644 --- a/osal/linux/PosixThread.cpp +++ b/osal/linux/PosixThread.cpp @@ -138,7 +138,7 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) { void* sp; status = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stackSize); if(status != 0){ - sif::error << "Posix Thread stack init failed with: " << + sif::error << "PosixThread::createTask: Stack init failed with: " << strerror(status) << std::endl; }