Skip to content

Commit

Permalink
Fixes for the XDG Base Dirs implementation (#330) (#419)
Browse files Browse the repository at this point in the history
Fix XDG Base Dirs implementation
  • Loading branch information
Cavernosa authored Aug 14, 2022
1 parent 0cefb3d commit 59aae77
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,41 @@ void remove_utmp_entry(struct utmp *entry) {

void xauth(const char* display_name, const char* shell, char* pwd)
{
const char* xauth_file = ".lyxauth";
const char* xauth_file = "lyxauth";
char* xauth_dir = getenv("XDG_RUNTIME_DIR");
if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
{
xauth_dir = getenv("XDG_CONFIG_DIR");
xauth_dir = getenv("XDG_CONFIG_HOME");
struct stat sb;
if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
{
xauth_dir = strdup(pwd);
strcat(xauth_dir, "/.config");
stat(xauth_dir, &sb);
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";
xauth_file = ".lyxauth";
}
}
else
{
xauth_file = "lyxauth";
}

// trim trailing slashes
int i = strlen(xauth_dir) - 1;
Expand Down

0 comments on commit 59aae77

Please sign in to comment.