From 793f469035b4e8ffe165d140ea1895b994fae117 Mon Sep 17 00:00:00 2001 From: Cavernosa <42952107+Cavernosa@users.noreply.github.com> Date: Sun, 14 Aug 2022 01:01:30 +0000 Subject: [PATCH] Use `.config/ly` instead of dumping in `.config/` Using `.config/ly` (`XDG_CONFIG_HOME/ly`) instead of `.config/` (`XDG_CONFIG_HOME`) Added many safety checks so it's impossible to break --- src/login.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/login.c b/src/login.c index 551f52e..44f2111 100644 --- a/src/login.c +++ b/src/login.c @@ -307,18 +307,35 @@ void xauth(const char* display_name, const char* shell, char* pwd) if ((xauth_dir == NULL) || (*xauth_dir == '\0')) { xauth_dir = getenv("XDG_CONFIG_HOME"); + struct stat sb; if ((xauth_dir == NULL) || (*xauth_dir == '\0')) { xauth_dir = strdup(pwd); strcat(xauth_dir, "/.config"); - struct stat sb; stat(xauth_dir, &sb); - if (!S_ISDIR(sb.st_mode)) + if (S_ISDIR(sb.st_mode)) + { + strcat(xauth_dir, "/ly"); + } + else { xauth_dir = pwd; xauth_file = ".lyxauth"; } } + else + { + strcat(xauth_dir, "/ly"); + } + + // If .config/ly/ or XDG_CONFIG_HOME/ly/ doesn't exist and can't create the directory, use pwd + // Passing pwd beforehand is safe since stat will always evaluate false + stat(xauth_dir, &sb); + if (!S_ISDIR(sb.st_mode) && mkdir(xauth_dir, 0777) == -1) + { + xauth_dir = pwd; + xauth_file = ".lyxauth"; + } } // trim trailing slashes