mirror of https://github.com/fairyglade/ly.git
Fix XDG Base Dirs implementation
This commit is contained in:
parent
0cefb3da8e
commit
59aae77f49
36
src/login.c
36
src/login.c
|
@ -303,20 +303,40 @@ void remove_utmp_entry(struct utmp *entry) {
|
||||||
|
|
||||||
void xauth(const char* display_name, const char* shell, char* pwd)
|
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");
|
char* xauth_dir = getenv("XDG_RUNTIME_DIR");
|
||||||
if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
|
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'))
|
if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
|
||||||
{
|
{
|
||||||
xauth_dir = pwd;
|
xauth_dir = strdup(pwd);
|
||||||
xauth_file = "lyxauth";
|
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";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
xauth_file = "lyxauth";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim trailing slashes
|
// trim trailing slashes
|
||||||
|
|
Loading…
Reference in New Issue