config-parser: Honor XDG_CONFIG_DIRS

This set of changes adds support for searching for a given config file
in the directories listed in $XDG_CONFIG_DIRS if it wasn't found in
$XDG_CONFIG_HOME or ~/.config.  This allows packages to install custom
config files in /etc/xdg/weston, for example, thus allowing them to
avoid dealing with home directories.

To avoid a TOCTOU race the config file is actually open()ed during the
search.  Its file descriptor is returned and stored in the compositor
for later use when performing subsequent config file parses.

Signed-off-by: Ossama Othman <ossama.othman@intel.com>
This commit is contained in:
Ossama Othman
2013-05-14 09:48:26 -07:00
committed by Kristian Høgsberg
parent 95eb3a2eb4
commit a50e6e4c50
22 changed files with 158 additions and 110 deletions
+4 -4
View File
@@ -1090,7 +1090,7 @@ add_default_launcher(struct desktop *desktop)
int main(int argc, char *argv[])
{
struct desktop desktop = { 0 };
char *config_file;
int config_fd;
struct output *output;
int ret;
@@ -1122,11 +1122,11 @@ int main(int argc, char *argv[])
grab_surface_create(&desktop);
config_file = config_file_path("weston.ini");
ret = parse_config_file(config_file,
config_fd = open_config_file("weston.ini");
ret = parse_config_file(config_fd,
config_sections, ARRAY_LENGTH(config_sections),
&desktop);
free(config_file);
close(config_fd);
if (ret < 0)
add_default_launcher(&desktop);
+4 -4
View File
@@ -456,7 +456,7 @@ int main(int argc, char *argv[])
{
struct tablet tablet = { 0 };
struct display *display;
char *config_file;
int config_fd;
struct output *output;
display = display_create(&argc, argv);
@@ -478,11 +478,11 @@ int main(int argc, char *argv[])
wl_list_init(&tablet.homescreen->launcher_list);
config_file = config_file_path("weston.ini");
parse_config_file(config_file,
config_fd = open_config_file("weston.ini");
parse_config_file(config_fd,
config_sections, ARRAY_LENGTH(config_sections),
&tablet);
free(config_file);
close(config_fd);
signal(SIGCHLD, sigchild_handler);
+4 -4
View File
@@ -2671,17 +2671,17 @@ int main(int argc, char *argv[])
{
struct display *d;
struct terminal *terminal;
char *config_file;
int config_fd;
option_shell = getenv("SHELL");
if (!option_shell)
option_shell = "/bin/bash";
config_file = config_file_path("weston.ini");
parse_config_file(config_file,
config_fd = open_config_file("weston.ini");
parse_config_file(config_fd,
config_sections, ARRAY_LENGTH(config_sections),
NULL);
free(config_file);
close(config_fd);
parse_options(terminal_options,
ARRAY_LENGTH(terminal_options), &argc, argv);
+4 -4
View File
@@ -1188,7 +1188,7 @@ static const struct cursor_alternatives cursors[] = {
static void
create_cursors(struct display *display)
{
char *config_file;
int config_fd;
char *theme = NULL;
unsigned int size = 32;
unsigned int i, j;
@@ -1201,9 +1201,9 @@ create_cursors(struct display *display)
{ "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
};
config_file = config_file_path("weston.ini");
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), NULL);
free(config_file);
config_fd = open_config_file("weston.ini");
parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), NULL);
close(config_fd);
display->cursor_theme = wl_cursor_theme_load(theme, size, display->shm);
display->cursors =