From 2e995355dc396e89e2e29e41bd7bb7afac2688d2 Mon Sep 17 00:00:00 2001 From: Rafael Date: Fri, 19 Jan 2024 02:24:55 +0000 Subject: [PATCH] fix(linux)!: use XDG spec for fetching Linux configuration directory (#2034) --- src/platform/linux/misc.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/platform/linux/misc.cpp b/src/platform/linux/misc.cpp index 543d6c38..27697c2d 100644 --- a/src/platform/linux/misc.cpp +++ b/src/platform/linux/misc.cpp @@ -99,12 +99,22 @@ namespace platf { fs::path appdata() { - const char *homedir; - if ((homedir = getenv("HOME")) == nullptr) { - homedir = getpwuid(geteuid())->pw_dir; + const char *dir; + + // May be set if running under a systemd service with the ConfigurationDirectory= option set. + if ((dir = getenv("CONFIGURATION_DIRECTORY")) != nullptr) { + return fs::path { dir } / "sunshine"sv; + } + // Otherwise, follow the XDG base directory specification: + // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html + if ((dir = getenv("XDG_CONFIG_HOME")) != nullptr) { + return fs::path { dir } / "sunshine"sv; + } + if ((dir = getenv("HOME")) == nullptr) { + dir = getpwuid(geteuid())->pw_dir; } - return fs::path { homedir } / ".config/sunshine"sv; + return fs::path { dir } / ".config/sunshine"sv; } std::string