mirror of
https://github.com/commaai/msgq.git
synced 2026-06-10 23:14:26 +08:00
messaging: support OPENPILOT_PREFIX (#299)
* messaging prefix * cleanup * cleanup * cleanup * bin * clean dir * max dirs working * increase max dirs * check if file exists * filesystem except * cleanup * dont delete manager folder * dont delete manager folder fix * default dir * create file structure * tab size * assert no prefix when zmq * PR feedback * create dir in test * Update messaging/messaging.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * import Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#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(){
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user