diff options
author | 90 <hi@90.gripe> | 2024-03-15 22:00:17 +0000 |
---|---|---|
committer | 90 <hi@90.gripe> | 2024-03-15 22:00:17 +0000 |
commit | 119a5ff7d2e2543e51947d35be7c5f84f74b3243 (patch) | |
tree | 57ede81fe7e4a45e865ee341645fce177d555937 /vncviewer | |
parent | 90e9db2dadccec9f614e33092f3b41d82966ae74 (diff) | |
download | tigervnc-119a5ff7d2e2543e51947d35be7c5f84f74b3243.tar.gz tigervnc-119a5ff7d2e2543e51947d35be7c5f84f74b3243.zip |
Begin work on XDGBDS compliance and overrideable configs
Diffstat (limited to 'vncviewer')
-rw-r--r-- | vncviewer/ServerDialog.cxx | 16 | ||||
-rw-r--r-- | vncviewer/parameters.cxx | 16 | ||||
-rw-r--r-- | vncviewer/vncviewer.cxx | 44 |
3 files changed, 50 insertions, 26 deletions
diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index 6a766295..4d57b5fb 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -315,12 +315,12 @@ void ServerDialog::loadServerHistory() return; #endif - const char* homeDir = os::getvnchomedir(); - if (homeDir == NULL) - throw Exception(_("Could not obtain the home directory path")); + const char* stateDir = os::getvncstatedir(); + if (stateDir == NULL) + throw Exception(_("Could not obtain the state directory path")); char filepath[PATH_MAX]; - snprintf(filepath, sizeof(filepath), "%s/%s", homeDir, SERVER_HISTORY); + snprintf(filepath, sizeof(filepath), "%s/%s", stateDir, SERVER_HISTORY); /* Read server history from file */ FILE* f = fopen(filepath, "r"); @@ -381,12 +381,12 @@ void ServerDialog::saveServerHistory() return; #endif - const char* homeDir = os::getvnchomedir(); - if (homeDir == NULL) - throw Exception(_("Could not obtain the home directory path")); + const char* stateDir = os::getvncstatedir(); + if (stateDir == NULL) + throw Exception(_("Could not obtain the state directory path")); char filepath[PATH_MAX]; - snprintf(filepath, sizeof(filepath), "%s/%s", homeDir, SERVER_HISTORY); + snprintf(filepath, sizeof(filepath), "%s/%s", stateDir, SERVER_HISTORY); /* Write server history to file */ FILE* f = fopen(filepath, "w+"); diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index 75d46dca..15ea4ee8 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -629,11 +629,11 @@ void saveViewerParameters(const char *filename, const char *servername) { return; #endif - const char* homeDir = os::getvnchomedir(); - if (homeDir == NULL) - throw Exception(_("Could not obtain the home directory path")); + const char* configDir = os::getvncconfigdir(); + if (configDir == NULL) + throw Exception(_("Could not obtain the config directory path")); - snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", homeDir); + snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", configDir); } else { snprintf(filepath, sizeof(filepath), "%s", filename); } @@ -733,11 +733,11 @@ char* loadViewerParameters(const char *filename) { return loadFromReg(); #endif - const char* homeDir = os::getvnchomedir(); - if (homeDir == NULL) - throw Exception(_("Could not obtain the home directory path")); + const char* configDir = os::getvncconfigdir(); + if (configDir == NULL) + throw Exception(_("Could not obtain the config directory path")); - snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", homeDir); + snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", configDir); } else { snprintf(filepath, sizeof(filepath), "%s", filename); } diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 6eebf3d0..c5d6082e 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -429,17 +429,34 @@ static void init_fltk() #endif } -static void mkvnchomedir() +static int mkvncdir(const char *dir) { - // Create .vnc in the user's home directory if it doesn't already exist - const char* homeDir = os::getvnchomedir(); - if (homeDir == NULL) { - vlog.error(_("Could not obtain the home directory path")); - } else { - int result = mkdir(homeDir, 0755); - if (result == -1 && errno != EEXIST) - vlog.error(_("Could not create VNC home directory: %s"), strerror(errno)); + int result = mkdir(dir, 0755); + if (result == -1 && errno != EEXIST) { + vlog.error(_("Could not create VNC directory %s: %s"), dir, strerror(errno)); + return result; + } + return 0; +} + +static void mkdirrecursive(const char *dir) +{ + char *path = strdup(dir); + char *p; + + for (p = path + 1; *p; p++) { + if (*p == '/') { + *p = '\0'; + if (mkvncdir(path) != 0) { + free(path); + return; + } + *p = '/'; + } } + + mkvncdir(path); + free(path); } static void usage(const char *programName) @@ -728,7 +745,14 @@ int main(int argc, char** argv) migrateDeprecatedOptions(); - mkvnchomedir(); +#ifndef WIN32 + // Check if config and state dirs are both the same legacy ~/.vnc dir + struct stat st; + if (stat(os::getvnchomedir(), &st) == 0) + vlog.info(_("~/.vnc is deprecated, please migrate to XDGBDS-compliant paths!")); +#endif + mkdirrecursive(os::getvncconfigdir()); + mkdirrecursive(os::getvncstatedir()); CSecurity::upg = &dlg; #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE) |