From 177bc413f78579d0be19ada7ee1fa093b79afb7c Mon Sep 17 00:00:00 2001 From: grekiki Date: Fri, 11 Sep 2020 14:45:47 +0200 Subject: [PATCH] fix the isssue 41 (#87) * fix the isssue * Improve code style * Improve code style2, remove failing test * less changes * style3 --- messaging/msgq.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/messaging/msgq.cc b/messaging/msgq.cc index 2630101..d8fb0e5 100644 --- a/messaging/msgq.cc +++ b/messaging/msgq.cc @@ -21,6 +21,8 @@ #include +#include "services.h" + #include "msgq.hpp" void sigusr2_handler(int signal) { @@ -81,11 +83,20 @@ void msgq_wait_for_subscriber(msgq_queue_t *q){ return; } - +bool service_exists(std::string path){ + for (const auto& it : services) { + if (it.name == path) { + return true; + } + } + return false; +} int msgq_new_queue(msgq_queue_t * q, const char * path, size_t size){ assert(size < 0xFFFFFFFF); // Buffer must be smaller than 2^32 bytes - + if (!service_exists(std::string(path))){ + std::cout << "Warning, " << std::string(path) << " is not in service list." << std::endl; + } std::signal(SIGUSR2, sigusr2_handler); const char * prefix = "/dev/shm/"; @@ -102,15 +113,15 @@ int msgq_new_queue(msgq_queue_t * q, const char * path, size_t size){ delete[] full_path; int rc = ftruncate(fd, size + sizeof(msgq_header_t)); - if (rc < 0) + if (rc < 0){ return -1; - + } char * mem = (char*)mmap(NULL, size + sizeof(msgq_header_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); - if (mem == NULL) + if (mem == NULL){ return -1; - + } q->mmap_p = mem; msgq_header_t *header = (msgq_header_t *)mem;