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