Add an environment variable for custom temp dirs

This would be useful if you need to do some elaborate namespacing setup
and want all sockets and other temporary files in a single directory
instead of in `${XDG_RUNTIME_DIR:/tmp}`.

This resolves #139.
This commit is contained in:
Robbert van der Helm
2021-10-16 01:41:48 +02:00
parent e79d1ec03a
commit 3257b9c32e
3 changed files with 22 additions and 2 deletions
+10 -1
View File
@@ -32,9 +32,18 @@ using namespace std::literals::string_view_literals;
*/
constexpr char disable_watchdog_timer_env_var[] = "YABRIDGE_NO_WATCHDOG";
/**
* If this environment variable is set, yabridge will store its sockets and
* other temporary files here instead of in `$XDG_RUNTIME_DIR` or `/tmp`. This
* is only relevant when using some namespacing setup for sandboxing.
*/
constexpr char temp_dir_override_env_var[] = "YABRIDGE_TEMP_PATH";
fs::path get_temporary_directory() {
bp::environment env = boost::this_process::environment();
if (!env["XDG_RUNTIME_DIR"].empty()) {
if (!env[temp_dir_override_env_var].empty()) {
return env[temp_dir_override_env_var].to_string();
} else if (!env["XDG_RUNTIME_DIR"].empty()) {
return env["XDG_RUNTIME_DIR"].to_string();
} else {
return fs::temp_directory_path();