aboutsummaryrefslogtreecommitdiffstats
path: root/common/os
diff options
context:
space:
mode:
author90 <hi@90.gripe>2024-03-15 22:00:17 +0000
committer90 <hi@90.gripe>2024-03-15 22:00:17 +0000
commit119a5ff7d2e2543e51947d35be7c5f84f74b3243 (patch)
tree57ede81fe7e4a45e865ee341645fce177d555937 /common/os
parent90e9db2dadccec9f614e33092f3b41d82966ae74 (diff)
downloadtigervnc-119a5ff7d2e2543e51947d35be7c5f84f74b3243.tar.gz
tigervnc-119a5ff7d2e2543e51947d35be7c5f84f74b3243.zip
Begin work on XDGBDS compliance and overrideable configs
Diffstat (limited to 'common/os')
-rw-r--r--common/os/os.cxx36
-rw-r--r--common/os/os.h30
2 files changed, 56 insertions, 10 deletions
diff --git a/common/os/os.cxx b/common/os/os.cxx
index 2dfabc46..5c49ce12 100644
--- a/common/os/os.cxx
+++ b/common/os/os.cxx
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#else
#include <windows.h>
@@ -39,12 +40,12 @@
#include <shlobj.h>
#endif
-static const char* gethomedir(bool userDir)
+static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_def)
{
static char dir[PATH_MAX];
#ifndef WIN32
- char *homedir;
+ char *homedir, *xdgdir;
uid_t uid;
struct passwd *passwd;
#else
@@ -66,7 +67,20 @@ static const char* gethomedir(bool userDir)
if (userDir)
return homedir;
+ // check if (deprecated) legacy path exists and use that if so
snprintf(dir, sizeof(dir), "%s/.vnc", homedir);
+ struct stat st;
+
+ if (stat(dir, &st) == 0)
+ return dir;
+
+ if (xdg_def != NULL) {
+ xdgdir = getenv(xdg_env);
+ if (xdgdir != NULL)
+ snprintf(dir, sizeof(dir), "%s/tigervnc", xdgdir);
+ else
+ snprintf(dir, sizeof(dir), "%s/%s/tigervnc", homedir, xdg_def);
+ }
return dir;
#else
@@ -90,13 +104,23 @@ static const char* gethomedir(bool userDir)
#endif
}
-const char* os::getvnchomedir()
+const char* os::getuserhomedir()
{
- return gethomedir(false);
+ return getvncdir(true, NULL, NULL);
}
-const char* os::getuserhomedir()
+const char* os::getvncconfigdir()
{
- return gethomedir(true);
+ return getvncdir(false, "XDG_CONFIG_HOME", ".config");
}
+const char* os::getvncstatedir()
+{
+ return getvncdir(false, "XDG_STATE_HOME", ".local/state");
+}
+
+/* deprecated */
+const char* os::getvnchomedir()
+{
+ return getvncdir(false, NULL, NULL);
+}
diff --git a/common/os/os.h b/common/os/os.h
index 5f927fef..0561d36c 100644
--- a/common/os/os.h
+++ b/common/os/os.h
@@ -23,22 +23,44 @@
namespace os {
/*
- * Get VNC home directory ($HOME/.vnc or %APPDATA%/vnc/).
+ * Get user home directory.
* If HOME environment variable is set then it is used.
* Otherwise home directory is obtained via getpwuid function.
*
* Returns NULL on failure.
*/
- const char* getvnchomedir();
+ const char* getuserhomedir();
/*
- * Get user home directory.
+ * Get VNC config directory. On Unix-like systems, this is either:
+ * - $XDG_CONFIG_HOME/tigervnc
+ * - $HOME/.config/tigervnc
+ * On Windows, this is simply %APPDATA%/vnc/.
+ *
+ * Returns NULL on failure.
+ */
+ const char* getvncconfigdir();
+
+ /*
+ * Get VNC state (logs) directory. On Unix-like systems, this is either:
+ * - $XDG_STATE_HOME/tigervnc
+ * - $HOME/.local/state/tigervnc
+ * On Windows, this is simply %APPDATA%/vnc/.
+ *
+ * Returns NULL on failure.
+ */
+ const char* getvncstatedir();
+
+ /*
+ * Get legacy VNC home directory ($HOME/.vnc on Unix-likes).
* If HOME environment variable is set then it is used.
* Otherwise home directory is obtained via getpwuid function.
*
* Returns NULL on failure.
+ *
+ * Deprecated.
*/
- const char* getuserhomedir();
+ const char* getvnchomedir();
}