aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2023-11-27 11:57:59 +0100
committerAki Tomita <121511582+atomita-ni@users.noreply.github.com>2023-12-04 11:40:51 -0600
commit21ac37c737c5884138e3d4003510c0254c599925 (patch)
tree38b66bd835e6857bbdc40803dc209b05dcfb3603 /host
parentmulti_usrp: Improve dual-rate behavior (diff)
downloaduhd-21ac37c737c5884138e3d4003510c0254c599925.tar.xz
uhd-21ac37c737c5884138e3d4003510c0254c599925.zip
lib: Fix issue with undefined HOME or XDG_CONFIG_HOME
The path-search algorithms of UHD were incorrectly assuming the presence of either a XDG_CONFIG_HOME or HOME, as well as XDG_CONFIG_DATA environment variables. This fixes the issue: If no such variables exist (e.g., because UHD is being run as part of a system process, where no user is defined) then it simply ignores them.
Diffstat (limited to 'host')
-rw-r--r--host/lib/include/uhdlib/utils/paths.hpp10
-rw-r--r--host/lib/utils/paths.cpp22
2 files changed, 13 insertions, 19 deletions
diff --git a/host/lib/include/uhdlib/utils/paths.hpp b/host/lib/include/uhdlib/utils/paths.hpp
index 8b365c185..0aa6048ae 100644
--- a/host/lib/include/uhdlib/utils/paths.hpp
+++ b/host/lib/include/uhdlib/utils/paths.hpp
@@ -28,6 +28,10 @@ std::string get_appdata_path(void);
//
// Even on non-Linux systems, this should return the place where app data is
// written to. For UHD, this is data such as calibration data.
+//
+// There are valid scenarios when there is no such variable, e.g., when a process
+// is being spawned as a system process (there is no 'user' specified). If no
+// such path can be found, an empty string is returned.
boost::filesystem::path get_xdg_data_home();
//! Return a path to XDG_CONFIG_HOME
@@ -36,9 +40,15 @@ boost::filesystem::path get_xdg_data_home();
//
// Even on non-Linux systems, this should return the place where the
// configuration file can be stored.
+//
+// There are valid scenarios when there is no such variable, e.g., when a process
+// is being spawned as a system process (there is no 'user' specified). If no
+// such path can be found, an empty string is returned.
boost::filesystem::path get_xdg_config_home();
//! Return a path to ~/.uhd
+//
+// If no home directory can be found, an empty string is returned.
boost::filesystem::path get_legacy_config_home();
} /* namespace uhd */
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index 73b4cc25a..8fb57848a 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -148,15 +148,7 @@ fs::path uhd::get_xdg_data_home()
#endif
const std::string home = get_env_var("HOME", "");
if (home.empty()) {
-#ifdef UHD_PLATFORM_WIN32
- const std::string err_msg =
- "get_xdg_data_home(): Unable to find \%HOME\%, \%XDG_DATA_HOME\%, "
- "\%LOCALAPPDATA\% or \%APPDATA\%.";
-#else
- const std::string err_msg =
- "get_xdg_data_home(): Unable to find $HOME or $XDG_DATA_HOME.";
-#endif
- throw uhd::runtime_error(err_msg);
+ return fs::path("");
}
return fs::path(home) / ".local" / "share";
}
@@ -180,15 +172,7 @@ fs::path uhd::get_xdg_config_home()
#endif
const std::string home = get_env_var("HOME", "");
if (home.empty()) {
-#ifdef UHD_PLATFORM_WIN32
- const std::string err_msg =
- "get_xdg_config_home(): Unable to find \%HOME\%, \%XDG_CONFIG_HOME\%, "
- "\%LOCALAPPDATA\% or \%APPDATA\%.";
-#else
- const std::string err_msg =
- "get_xdg_config_home(): Unable to find $HOME or $XDG_CONFIG_HOME.";
-#endif
- throw uhd::runtime_error(err_msg);
+ return fs::path("");
}
return fs::path(home) / ".config";
}
@@ -207,7 +191,7 @@ fs::path uhd::get_legacy_config_home()
#endif
const std::string home = get_env_var("HOME", "");
if (home.empty()) {
- throw uhd::runtime_error("Unable to find $HOME.");
+ return fs::path("");
}
return fs::path(home) / ".uhd";
}