Files
dragonpilot/common/prefix.h
Dragonpilot Team 1f2e3aa8b6 dragonpilot 2022-12-30T07:51:42 for EON/C2
version: dragonpilot v0.9.1 beta for EON/C2
date: 2022-12-30T07:51:42
dp-dev(priv2) master commit: 4e8e00606410c2bbe03b93fc89a91caec37d1f3a
2022-12-30 07:51:55 +00:00

35 lines
856 B
C++

#pragma once
#include <cassert>
#include <string>
#include "common/params.h"
#include "common/util.h"
class OpenpilotPrefix {
public:
OpenpilotPrefix(std::string prefix = {}) {
if (prefix.empty()) {
prefix = util::random_string(15);
}
msgq_path = "/dev/shm/" + prefix;
bool ret = util::create_directories(msgq_path, 0777);
assert(ret);
setenv("OPENPILOT_PREFIX", prefix.c_str(), 1);
}
~OpenpilotPrefix() {
auto param_path = Params().getParamPath();
if (util::file_exists(param_path)) {
std::string real_path = util::readlink(param_path);
system(util::string_format("rm %s -rf", real_path.c_str()).c_str());
unlink(param_path.c_str());
}
system(util::string_format("rm %s -rf", msgq_path.c_str()).c_str());
unsetenv("OPENPILOT_PREFIX");
}
private:
std::string msgq_path;
};