mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[client] config: optionally load config from XDG_CONFIG_HOME
We look for the client config in $XDG_CONFIG_HOME/looking-glass/client.ini. This is done because it's more conventional, and also allows us to add additional configuration files, e.g. for the host. We fallback to $HOME/.config as is standard, and then as a last resort use getpwuid(getuid())->pw_dir. This is also recommended by the getpwuid manpage: > An application that wants to determine its user's home directory should > inspect the value of HOME (rather than the value getpwuid(getuid())->pw_dir) > since this allows the user to modify their notion of "the home directory" > during a login session.
This commit is contained in:
parent
68d8d95266
commit
75e57baf6c
@ -480,7 +480,7 @@ bool config_load(int argc, char * argv[])
|
||||
return false;
|
||||
}
|
||||
|
||||
// load user's local options
|
||||
// load config from user's home directory
|
||||
struct passwd * pw = getpwuid(getuid());
|
||||
char * localFile;
|
||||
alloc_sprintf(&localFile, "%s/.looking-glass-client.ini", pw->pw_dir);
|
||||
@ -495,6 +495,28 @@ bool config_load(int argc, char * argv[])
|
||||
}
|
||||
free(localFile);
|
||||
|
||||
// load config from XDG_CONFIG_HOME
|
||||
char * xdgFile;
|
||||
char * dir;
|
||||
|
||||
if ((dir = getenv("XDG_CONFIG_HOME")) != NULL)
|
||||
alloc_sprintf(&xdgFile, "%s/looking-glass/client.ini", dir);
|
||||
else if ((dir = getenv("HOME")) != NULL)
|
||||
alloc_sprintf(&xdgFile, "%s/.config/looking-glass/client.ini", dir);
|
||||
else
|
||||
alloc_sprintf(&xdgFile, "%s/.config/looking-glass/client.ini", pw->pw_dir);
|
||||
|
||||
if (xdgFile && stat(xdgFile, &st) >= 0 && S_ISREG(st.st_mode))
|
||||
{
|
||||
DEBUG_INFO("Loading config from: %s", xdgFile);
|
||||
if (!option_load(xdgFile))
|
||||
{
|
||||
free(xdgFile);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
free(xdgFile);
|
||||
|
||||
// parse the command line arguments
|
||||
if (!option_parse(argc, argv))
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user