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>
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 21304a0..ea0d4b9 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -1383,7 +1383,7 @@
int fullscreen,
int no_input,
int use_pixman,
- int *argc, char *argv[], const char *config_file)
+ int *argc, char *argv[], int config_fd)
{
struct x11_compositor *c;
struct x11_configured_output *o;
@@ -1401,7 +1401,7 @@
memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv,
- config_file) < 0)
+ config_fd) < 0)
goto err_free;
c->dpy = XOpenDisplay(NULL);
@@ -1574,7 +1574,7 @@
WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
- const char *config_file)
+ int config_fd)
{
int fullscreen = 0;
int no_input = 0;
@@ -1604,12 +1604,12 @@
ARRAY_LENGTH(x11_config_keys), output_section_done },
};
- parse_config_file(config_file, config_section,
+ parse_config_file(config_fd, config_section,
ARRAY_LENGTH(config_section), NULL);
return x11_compositor_create(display,
fullscreen,
no_input,
use_pixman,
- argc, argv, config_file);
+ argc, argv, config_fd);
}