mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-02-05 19:39:50 +08:00
Create rtipc directories on startup
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <unordered_set>
|
||||
#include <iterator>
|
||||
#include <ios>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static std::ostream &operator<<(std::ostream &os, const sdo_address &a)
|
||||
{
|
||||
@@ -420,13 +421,37 @@ static const char *getName()
|
||||
return "FakeEtherCAT";
|
||||
}
|
||||
|
||||
static int mkpath(const std::string &file_path)
|
||||
{
|
||||
if (file_path.empty())
|
||||
return 0;
|
||||
|
||||
std::size_t offset = 0;
|
||||
do
|
||||
{
|
||||
offset = file_path.find('/', offset + 1);
|
||||
const auto subpath = file_path.substr(0, offset);
|
||||
if (mkdir(subpath.c_str(), 0755) == -1)
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} while (offset != std::string::npos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::string getRtIpcDir(int idx)
|
||||
{
|
||||
if (const auto ans = getenv("FAKE_EC_HOMEDIR"))
|
||||
std::string ans;
|
||||
if (const auto e = getenv("FAKE_EC_HOMEDIR"))
|
||||
{
|
||||
return ans + std::string("/") + std::to_string(idx);
|
||||
ans = e + std::string("/") + std::to_string(idx);
|
||||
}
|
||||
return "/tmp/FakeEtherCAT/" + std::to_string(idx);
|
||||
ans = "/tmp/FakeEtherCAT/" + std::to_string(idx);
|
||||
mkpath(ans);
|
||||
return ans;
|
||||
}
|
||||
|
||||
ec_master::ec_master(int id) : rt_ipc_dir(getRtIpcDir(id)), rt_ipc_name(getName()), rt_ipc(rtipc_create(rt_ipc_name.c_str(), rt_ipc_dir.c_str())), id_(id)
|
||||
|
||||
Reference in New Issue
Block a user