Skip to content

Commit

Permalink
Honor TMPDIR environment variable if defined for Linux systems (COVES…
Browse files Browse the repository at this point in the history
  • Loading branch information
srchaitu2008 committed Nov 26, 2024
1 parent 4296a4c commit 021320a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions implementation/utility/include/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class utility {
private:
static std::uint16_t get_max_client_number(
const std::shared_ptr<configuration> &_config);
static std::string getTmpDirPath(const std::string &_network);

static std::mutex mutex__;
static std::map<std::string, data_t> data__; // network --> data
Expand Down
23 changes: 20 additions & 3 deletions implementation/utility/src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool utility::is_routing_manager(const std::string &_network) {

return (r.first->second.lock_handle_ != INVALID_HANDLE_VALUE);
#else
std::string its_base_path(VSOMEIP_BASE_PATH + _network);
std::string its_base_path = getTmpDirPath(_network);
std::string its_lockfile(its_base_path + ".lck");
int its_lock_ctrl(-1);

Expand Down Expand Up @@ -145,7 +145,7 @@ void utility::remove_lockfile(const std::string &_network) {
}
}
#else
std::string its_base_path(VSOMEIP_BASE_PATH + _network);
std::string its_base_path = getTmpDirPath(_network);
std::string its_lockfile(its_base_path + ".lck");

if (r->second.lock_fd_ != -1) {
Expand Down Expand Up @@ -186,7 +186,8 @@ bool utility::is_folder(const std::string &_path) {
}

std::string utility::get_base_path(const std::string &_network) {
return std::string(VSOMEIP_BASE_PATH + _network + "-");
std::string its_base_path = getTmpDirPath(_network);
return std::string(its_base_path + "-");
}

client_t
Expand Down Expand Up @@ -316,4 +317,20 @@ std::uint16_t utility::get_max_client_number(
return its_max_clients;
}

std::string utility::getTmpDirPath(const std::string &_network) {
std::string its_base_path;
#ifdef _WIN32
its_base_path = {VSOMEIP_BASE_PATH + _network};
#else
const char *env_tmpdir = getenv("TMPDIR");
if(nullptr != env_tmpdir) {
VSOMEIP_INFO<<"TMPDIR is "<<env_tmpdir;
its_base_path = {std::string(env_tmpdir) + "/" + _network};
} else {
its_base_path = {VSOMEIP_BASE_PATH + _network};
}
#endif
return its_base_path;
}

} // namespace vsomeip_v3

0 comments on commit 021320a

Please sign in to comment.