diff --git a/messaging/messaging.cc b/messaging/messaging.cc index bfa634e..69c0e80 100644 --- a/messaging/messaging.cc +++ b/messaging/messaging.cc @@ -1,3 +1,6 @@ +#include +#include + #include "messaging.h" #include "impl_zmq.h" #include "impl_msgq.h" @@ -9,7 +12,14 @@ const bool MUST_USE_ZMQ = false; #endif bool messaging_use_zmq(){ - return std::getenv("ZMQ") || MUST_USE_ZMQ; + if (std::getenv("ZMQ") || MUST_USE_ZMQ) { + if (std::getenv("OPENPILOT_PREFIX")) { + std::cerr << "OPENPILOT_PREFIX not supported with ZMQ backend\n"; + assert(false); + } + return true; + } + return false; } Context * Context::create(){ diff --git a/messaging/msgq.cc b/messaging/msgq.cc index 23ae7e2..f527a56 100644 --- a/messaging/msgq.cc +++ b/messaging/msgq.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -81,23 +82,22 @@ void msgq_wait_for_subscriber(msgq_queue_t *q){ return; } - 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 std::signal(SIGUSR2, sigusr2_handler); - const char * prefix = "/dev/shm/"; - char * full_path = new char[strlen(path) + strlen(prefix) + 1]; - strcpy(full_path, prefix); - strcat(full_path, path); + std::string full_path = "/dev/shm/"; + const char* prefix = std::getenv("OPENPILOT_PREFIX"); + if (prefix) { + full_path += std::string(prefix) + "/"; + } + full_path += path; - auto fd = open(full_path, O_RDWR | O_CREAT, 0664); + auto fd = open(full_path.c_str(), O_RDWR | O_CREAT, 0664); if (fd < 0) { std::cout << "Warning, could not open: " << full_path << std::endl; - delete[] full_path; return -1; } - delete[] full_path; int rc = ftruncate(fd, size + sizeof(msgq_header_t)); if (rc < 0){