#include "rpc/platform/runtime_paths.hpp" #include #include #include #include #include namespace velox::daemon::rpc::platform { namespace { std::error_code errc(int e) { return std::error_code(e, std::generic_category()); } } // namespace std::error_code runtime_base_dir(std::string& out) { if (const char* xdg = ::getenv("XDG_RUNTIME_DIR"); xdg != nullptr && xdg[0] != '\0') { out = xdg; return {}; } const std::string base = "/run/user/" + std::to_string(::geteuid()); struct stat st{}; if (::stat(base.c_str(), &st) != 0 || !S_ISDIR(st.st_mode)) { // No XDG_RUNTIME_DIR and no /run/user/: refuse rather than pick an insecure // fallback. The caller surfaces this as "cannot start". return errc(ENOENT); } out = base; return {}; } std::error_code data_base_dir(std::string& out) { if (const char* xdg = ::getenv("XDG_DATA_HOME"); xdg != nullptr && xdg[0] != '\0') { out = xdg; return {}; } if (const char* home = ::getenv("HOME"); home != nullptr && home[0] != '\0') { out = std::string(home) + "/.local/share"; return {}; } return errc(ENOENT); } } // namespace velox::daemon::rpc::platform