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>
dev
Ossama Othman 12 years ago committed by Kristian Høgsberg
parent 95eb3a2eb4
commit a50e6e4c50
  1. 8
      clients/desktop-shell.c
  2. 8
      clients/tablet-shell.c
  3. 8
      clients/terminal.c
  4. 8
      clients/window.c
  5. 12
      man/weston.ini.man
  6. 96
      shared/config-parser.c
  7. 6
      shared/config-parser.h
  8. 4
      src/cms-static.c
  9. 10
      src/compositor-drm.c
  10. 8
      src/compositor-fbdev.c
  11. 8
      src/compositor-headless.c
  12. 4
      src/compositor-rdp.c
  13. 8
      src/compositor-rpi.c
  14. 8
      src/compositor-wayland.c
  15. 10
      src/compositor-x11.c
  16. 31
      src/compositor.c
  17. 8
      src/compositor.h
  18. 8
      src/shell.c
  19. 2
      src/tablet-shell.c
  20. 9
      src/text-backend.c
  21. 2
      src/xwayland/launcher.c
  22. 2
      tests/weston-test.c

@ -1090,7 +1090,7 @@ add_default_launcher(struct desktop *desktop)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct desktop desktop = { 0 }; struct desktop desktop = { 0 };
char *config_file; int config_fd;
struct output *output; struct output *output;
int ret; int ret;
@ -1122,11 +1122,11 @@ int main(int argc, char *argv[])
grab_surface_create(&desktop); grab_surface_create(&desktop);
config_file = config_file_path("weston.ini"); config_fd = open_config_file("weston.ini");
ret = parse_config_file(config_file, ret = parse_config_file(config_fd,
config_sections, ARRAY_LENGTH(config_sections), config_sections, ARRAY_LENGTH(config_sections),
&desktop); &desktop);
free(config_file); close(config_fd);
if (ret < 0) if (ret < 0)
add_default_launcher(&desktop); add_default_launcher(&desktop);

@ -456,7 +456,7 @@ int main(int argc, char *argv[])
{ {
struct tablet tablet = { 0 }; struct tablet tablet = { 0 };
struct display *display; struct display *display;
char *config_file; int config_fd;
struct output *output; struct output *output;
display = display_create(&argc, argv); display = display_create(&argc, argv);
@ -478,11 +478,11 @@ int main(int argc, char *argv[])
wl_list_init(&tablet.homescreen->launcher_list); wl_list_init(&tablet.homescreen->launcher_list);
config_file = config_file_path("weston.ini"); config_fd = open_config_file("weston.ini");
parse_config_file(config_file, parse_config_file(config_fd,
config_sections, ARRAY_LENGTH(config_sections), config_sections, ARRAY_LENGTH(config_sections),
&tablet); &tablet);
free(config_file); close(config_fd);
signal(SIGCHLD, sigchild_handler); signal(SIGCHLD, sigchild_handler);

@ -2671,17 +2671,17 @@ int main(int argc, char *argv[])
{ {
struct display *d; struct display *d;
struct terminal *terminal; struct terminal *terminal;
char *config_file; int config_fd;
option_shell = getenv("SHELL"); option_shell = getenv("SHELL");
if (!option_shell) if (!option_shell)
option_shell = "/bin/bash"; option_shell = "/bin/bash";
config_file = config_file_path("weston.ini"); config_fd = open_config_file("weston.ini");
parse_config_file(config_file, parse_config_file(config_fd,
config_sections, ARRAY_LENGTH(config_sections), config_sections, ARRAY_LENGTH(config_sections),
NULL); NULL);
free(config_file); close(config_fd);
parse_options(terminal_options, parse_options(terminal_options,
ARRAY_LENGTH(terminal_options), &argc, argv); ARRAY_LENGTH(terminal_options), &argc, argv);

@ -1188,7 +1188,7 @@ static const struct cursor_alternatives cursors[] = {
static void static void
create_cursors(struct display *display) create_cursors(struct display *display)
{ {
char *config_file; int config_fd;
char *theme = NULL; char *theme = NULL;
unsigned int size = 32; unsigned int size = 32;
unsigned int i, j; unsigned int i, j;
@ -1201,9 +1201,9 @@ create_cursors(struct display *display)
{ "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL }, { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
}; };
config_file = config_file_path("weston.ini"); config_fd = open_config_file("weston.ini");
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), NULL); parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), NULL);
free(config_file); close(config_fd);
display->cursor_theme = wl_cursor_theme_load(theme, size, display->shm); display->cursor_theme = wl_cursor_theme_load(theme, size, display->shm);
display->cursors = display->cursors =

@ -24,7 +24,10 @@ server is started:
.nf .nf
.BR "$XDG_CONFIG_HOME/weston.ini " "(if $XDG_CONFIG_HOME is set)" .BR "$XDG_CONFIG_HOME/weston.ini " "(if $XDG_CONFIG_HOME is set)"
.BR "$HOME/.config/weston.ini " "(if $HOME is set)" .BR "$HOME/.config/weston.ini " "(if $HOME is set)"
.BR "<current dir>/weston.ini " "(if both variables were not set)" .B "weston/weston.ini in each"
.BR "\ \ \ \ $XDG_CONFIG_DIR " "(if $XDG_CONFIG_DIRS is set)"
.BR "/etc/xdg/weston/weston.ini " "(if $XDG_CONFIG_DIRS is not set)"
.BR "<current dir>/weston.ini " "(if no variables were set)"
.fi .fi
.RE .RE
.PP .PP
@ -32,7 +35,12 @@ where environment variable
.B $HOME .B $HOME
is the user's home directory, and is the user's home directory, and
.B $XDG_CONFIG_HOME .B $XDG_CONFIG_HOME
is the user specific configuration directory. is the user specific configuration directory, and
.B $XDG_CONFIG_DIRS
is a colon
.B ':'
delimited listed of configuration base directories, such as
.BR /etc/xdg-foo:/etc/xdg .
.PP .PP
The The
.I weston.ini .I weston.ini

@ -20,11 +20,17 @@
* OF THIS SOFTWARE. * OF THIS SOFTWARE.
*/ */
#define _GNU_SOURCE /* for stchrnul() */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "config-parser.h" #include "config-parser.h"
@ -86,7 +92,7 @@ handle_key(const struct config_key *key, const char *value)
} }
int int
parse_config_file(const char *path, parse_config_file(int fd,
const struct config_section *sections, int num_sections, const struct config_section *sections, int num_sections,
void *data) void *data)
{ {
@ -95,12 +101,17 @@ parse_config_file(const char *path,
const struct config_section *current = NULL; const struct config_section *current = NULL;
int i; int i;
fp = fopen(path, "r"); if (fd == -1)
return -1;
fp = fdopen(dup(fd), "r");
if (fp == NULL) { if (fp == NULL) {
fprintf(stderr, "couldn't open %s\n", path); perror("couldn't open config file");
return -1; return -1;
} }
rewind(fp);
while (fgets(line, sizeof line, fp)) { while (fgets(line, sizeof line, fp)) {
if (line[0] == '#' || line[0] == '\n') { if (line[0] == '#' || line[0] == '\n') {
continue; continue;
@ -151,37 +162,62 @@ parse_config_file(const char *path,
return 0; return 0;
} }
char * int
config_file_path(const char *name) open_config_file(const char *name)
{ {
const char dotconf[] = "/.config/"; const char *config_dir = getenv("XDG_CONFIG_HOME");
const char *config_dir; const char *home_dir = getenv("HOME");
const char *home_dir; const char *config_dirs = getenv("XDG_CONFIG_DIRS");
char *path; char path[PATH_MAX];
size_t size; const char *p, *next;
int fd;
config_dir = getenv("XDG_CONFIG_HOME");
if (!config_dir) { /* Precedence is given to config files in the home directory,
home_dir = getenv("HOME"); * and then to directories listed in XDG_CONFIG_DIRS and
if (!home_dir) { * finally to the current working directory. */
fprintf(stderr, "HOME is not set, using cwd.\n");
return strdup(name); /* $XDG_CONFIG_HOME */
} if (config_dir) {
snprintf(path, sizeof path, "%s/%s", config_dir, name);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
return fd;
}
/* $HOME/.config */
if (home_dir) {
snprintf(path, sizeof path, "%s/.config/%s", home_dir, name);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
return fd;
}
size = strlen(home_dir) + sizeof dotconf + strlen(name); /* For each $XDG_CONFIG_DIRS: weston/<config_file> */
path = malloc(size); if (!config_dirs)
if (!path) config_dirs = "/etc/xdg"; /* See XDG base dir spec. */
return NULL;
snprintf(path, size, "%s%s%s", home_dir, dotconf, name); for (p = config_dirs; *p != '\0'; p = next) {
return path; next = strchrnul(p, ':');
snprintf(path, sizeof path,
"%.*s/weston/%s", (int)(next - p), p, name);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
return fd;
if (*next == ':')
next++;
} }
size = strlen(config_dir) + 1 + strlen(name) + 1; /* Current working directory. */
path = malloc(size); snprintf(path, sizeof path, "./%s", name);
if (!path) fd = open(path, O_RDONLY | O_CLOEXEC);
return NULL;
if (fd >= 0)
fprintf(stderr,
"using config in current working directory: %s\n",
path);
else
fprintf(stderr, "config file \"%s\" not found.\n", name);
snprintf(path, size, "%s/%s", config_dir, name); return fd;
return path;
} }

@ -48,12 +48,12 @@ struct config_section {
}; };
int int
parse_config_file(const char *path, parse_config_file(int config_fd,
const struct config_section *sections, int num_sections, const struct config_section *sections, int num_sections,
void *data); void *data);
char * int
config_file_path(const char *name); open_config_file(const char *name);
enum weston_option_type { enum weston_option_type {
WESTON_OPTION_INTEGER, WESTON_OPTION_INTEGER,

@ -131,7 +131,7 @@ output_section_done(void *data)
WL_EXPORT int WL_EXPORT int
module_init(struct weston_compositor *ec, module_init(struct weston_compositor *ec,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[])
{ {
struct cms_static *cms; struct cms_static *cms;
struct weston_output *output; struct weston_output *output;
@ -157,7 +157,7 @@ module_init(struct weston_compositor *ec,
ARRAY_LENGTH(drm_config_keys), output_section_done }, ARRAY_LENGTH(drm_config_keys), output_section_done },
}; };
parse_config_file(config_file, config_section, parse_config_file(ec->config_fd, config_section,
ARRAY_LENGTH(config_section), cms); ARRAY_LENGTH(config_section), cms);
cms->destroy_listener.notify = cms_notifier_destroy; cms->destroy_listener.notify = cms_notifier_destroy;

@ -2362,7 +2362,7 @@ planes_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data
static struct weston_compositor * static struct weston_compositor *
drm_compositor_create(struct wl_display *display, drm_compositor_create(struct wl_display *display,
int connector, const char *seat, int tty, int pixman, int connector, const char *seat, int tty, int pixman,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[], int config_fd)
{ {
struct drm_compositor *ec; struct drm_compositor *ec;
struct udev_device *drm_device; struct udev_device *drm_device;
@ -2385,7 +2385,7 @@ drm_compositor_create(struct wl_display *display,
ec->use_pixman = pixman; ec->use_pixman = pixman;
if (weston_compositor_init(&ec->base, display, argc, argv, if (weston_compositor_init(&ec->base, display, argc, argv,
config_file) < 0) { config_fd) < 0) {
weston_log("%s failed\n", __func__); weston_log("%s failed\n", __func__);
goto err_base; goto err_base;
} }
@ -2666,7 +2666,7 @@ output_section_done(void *data)
WL_EXPORT struct weston_compositor * WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
int connector = 0, tty = 0, use_pixman = 0; int connector = 0, tty = 0, use_pixman = 0;
const char *seat = default_seat; const char *seat = default_seat;
@ -2694,9 +2694,9 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
ARRAY_LENGTH(drm_config_keys), output_section_done }, ARRAY_LENGTH(drm_config_keys), output_section_done },
}; };
parse_config_file(config_file, config_section, parse_config_file(config_fd, config_section,
ARRAY_LENGTH(config_section), NULL); ARRAY_LENGTH(config_section), NULL);
return drm_compositor_create(display, connector, seat, tty, use_pixman, return drm_compositor_create(display, connector, seat, tty, use_pixman,
argc, argv, config_file); argc, argv, config_fd);
} }

@ -835,7 +835,7 @@ switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *d
static struct weston_compositor * static struct weston_compositor *
fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[], fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
const char *config_file, struct fbdev_parameters *param) int config_fd, struct fbdev_parameters *param)
{ {
struct fbdev_compositor *compositor; struct fbdev_compositor *compositor;
const char *seat = default_seat; const char *seat = default_seat;
@ -848,7 +848,7 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
return NULL; return NULL;
if (weston_compositor_init(&compositor->base, display, argc, argv, if (weston_compositor_init(&compositor->base, display, argc, argv,
config_file) < 0) config_fd) < 0)
goto out_free; goto out_free;
compositor->udev = udev_new(); compositor->udev = udev_new();
@ -906,7 +906,7 @@ out_free:
WL_EXPORT struct weston_compositor * WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
/* TODO: Ideally, available frame buffers should be enumerated using /* TODO: Ideally, available frame buffers should be enumerated using
* udev, rather than passing a device node in as a parameter. */ * udev, rather than passing a device node in as a parameter. */
@ -922,6 +922,6 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv); parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
return fbdev_compositor_create(display, argc, argv, config_file, return fbdev_compositor_create(display, argc, argv, config_fd,
&param); &param);
} }

@ -158,7 +158,7 @@ headless_destroy(struct weston_compositor *ec)
static struct weston_compositor * static struct weston_compositor *
headless_compositor_create(struct wl_display *display, headless_compositor_create(struct wl_display *display,
int width, int height, const char *display_name, int width, int height, const char *display_name,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[], int config_fd)
{ {
struct headless_compositor *c; struct headless_compositor *c;
@ -169,7 +169,7 @@ headless_compositor_create(struct wl_display *display,
memset(c, 0, sizeof *c); memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, if (weston_compositor_init(&c->base, display, argc, argv,
config_file) < 0) config_fd) < 0)
goto err_free; goto err_free;
weston_seat_init(&c->fake_seat, &c->base); weston_seat_init(&c->fake_seat, &c->base);
@ -194,7 +194,7 @@ err_free:
WL_EXPORT struct weston_compositor * WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
int width = 1024, height = 640; int width = 1024, height = 640;
char *display_name = NULL; char *display_name = NULL;
@ -208,5 +208,5 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
ARRAY_LENGTH(headless_options), argc, argv); ARRAY_LENGTH(headless_options), argc, argv);
return headless_compositor_create(display, width, height, display_name, return headless_compositor_create(display, width, height, display_name,
argc, argv, config_file); argc, argv, config_fd);
} }

@ -928,7 +928,7 @@ rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
static struct weston_compositor * static struct weston_compositor *
rdp_compositor_create(struct wl_display *display, rdp_compositor_create(struct wl_display *display,
struct rdp_compositor_config *config, struct rdp_compositor_config *config,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[], int config_fd)
{ {
struct rdp_compositor *c; struct rdp_compositor *c;
char *fd_str; char *fd_str;
@ -941,7 +941,7 @@ rdp_compositor_create(struct wl_display *display,
memset(c, 0, sizeof *c); memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, if (weston_compositor_init(&c->base, display, argc, argv,
config_file) < 0) config_fd) < 0)
goto err_free; goto err_free;
weston_seat_init(&c->main_seat, &c->base); weston_seat_init(&c->main_seat, &c->base);

@ -1441,7 +1441,7 @@ struct rpi_parameters {
static struct weston_compositor * static struct weston_compositor *
rpi_compositor_create(struct wl_display *display, int *argc, char *argv[], rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
const char *config_file, struct rpi_parameters *param) int config_fd, struct rpi_parameters *param)
{ {
struct rpi_compositor *compositor; struct rpi_compositor *compositor;
const char *seat = default_seat; const char *seat = default_seat;
@ -1464,7 +1464,7 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
return NULL; return NULL;
if (weston_compositor_init(&compositor->base, display, argc, argv, if (weston_compositor_init(&compositor->base, display, argc, argv,
config_file) < 0) config_fd) < 0)
goto out_free; goto out_free;
compositor->udev = udev_new(); compositor->udev = udev_new();
@ -1554,7 +1554,7 @@ out_free:
WL_EXPORT struct weston_compositor * WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
struct rpi_parameters param = { struct rpi_parameters param = {
.tty = 0, /* default to current tty */ .tty = 0, /* default to current tty */
@ -1571,5 +1571,5 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
parse_options(rpi_options, ARRAY_LENGTH(rpi_options), argc, argv); parse_options(rpi_options, ARRAY_LENGTH(rpi_options), argc, argv);
return rpi_compositor_create(display, argc, argv, config_file, &param); return rpi_compositor_create(display, argc, argv, config_fd, &param);
} }

@ -721,7 +721,7 @@ wayland_destroy(struct weston_compositor *ec)
static struct weston_compositor * static struct weston_compositor *
wayland_compositor_create(struct wl_display *display, wayland_compositor_create(struct wl_display *display,
int width, int height, const char *display_name, int width, int height, const char *display_name,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[], int config_fd)
{ {
struct wayland_compositor *c; struct wayland_compositor *c;
struct wl_event_loop *loop; struct wl_event_loop *loop;
@ -734,7 +734,7 @@ wayland_compositor_create(struct wl_display *display,
memset(c, 0, sizeof *c); memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, if (weston_compositor_init(&c->base, display, argc, argv,
config_file) < 0) config_fd) < 0)
goto err_free; goto err_free;
c->parent.wl_display = wl_display_connect(display_name); c->parent.wl_display = wl_display_connect(display_name);
@ -797,7 +797,7 @@ err_free:
WL_EXPORT struct weston_compositor * WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
int width = 1024, height = 640; int width = 1024, height = 640;
char *display_name = NULL; char *display_name = NULL;
@ -812,5 +812,5 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
ARRAY_LENGTH(wayland_options), argc, argv); ARRAY_LENGTH(wayland_options), argc, argv);
return wayland_compositor_create(display, width, height, display_name, return wayland_compositor_create(display, width, height, display_name,
argc, argv, config_file); argc, argv, config_fd);
} }

@ -1383,7 +1383,7 @@ x11_compositor_create(struct wl_display *display,
int fullscreen, int fullscreen,
int no_input, int no_input,
int use_pixman, int use_pixman,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[], int config_fd)
{ {
struct x11_compositor *c; struct x11_compositor *c;
struct x11_configured_output *o; struct x11_configured_output *o;
@ -1401,7 +1401,7 @@ x11_compositor_create(struct wl_display *display,
memset(c, 0, sizeof *c); memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, if (weston_compositor_init(&c->base, display, argc, argv,
config_file) < 0) config_fd) < 0)
goto err_free; goto err_free;
c->dpy = XOpenDisplay(NULL); c->dpy = XOpenDisplay(NULL);
@ -1574,7 +1574,7 @@ err_free:
WL_EXPORT struct weston_compositor * WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
int fullscreen = 0; int fullscreen = 0;
int no_input = 0; int no_input = 0;
@ -1604,12 +1604,12 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
ARRAY_LENGTH(x11_config_keys), output_section_done }, 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); ARRAY_LENGTH(config_section), NULL);
return x11_compositor_create(display, return x11_compositor_create(display,
fullscreen, fullscreen,
no_input, no_input,
use_pixman, use_pixman,
argc, argv, config_file); argc, argv, config_fd);
} }

@ -2686,7 +2686,7 @@ WL_EXPORT int
weston_compositor_init(struct weston_compositor *ec, weston_compositor_init(struct weston_compositor *ec,
struct wl_display *display, struct wl_display *display,
int *argc, char *argv[], int *argc, char *argv[],
const char *config_file) int config_fd)
{ {
struct wl_event_loop *loop; struct wl_event_loop *loop;
struct xkb_rule_names xkb_names; struct xkb_rule_names xkb_names;
@ -2703,7 +2703,9 @@ weston_compositor_init(struct weston_compositor *ec,
}; };
memset(&xkb_names, 0, sizeof(xkb_names)); memset(&xkb_names, 0, sizeof(xkb_names));
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), ec);
ec->config_fd = config_fd;
parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), ec);
ec->wl_display = display; ec->wl_display = display;
wl_signal_init(&ec->destroy_signal); wl_signal_init(&ec->destroy_signal);
@ -2789,6 +2791,8 @@ weston_compositor_shutdown(struct weston_compositor *ec)
weston_plane_release(&ec->primary_plane); weston_plane_release(&ec->primary_plane);
wl_event_loop_destroy(ec->input_loop); wl_event_loop_destroy(ec->input_loop);
close(ec->config_fd);
} }
WL_EXPORT void WL_EXPORT void
@ -2945,12 +2949,12 @@ load_module(const char *name, const char *entrypoint)
static int static int
load_modules(struct weston_compositor *ec, const char *modules, load_modules(struct weston_compositor *ec, const char *modules,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[])
{ {
const char *p, *end; const char *p, *end;
char buffer[256]; char buffer[256];
int (*module_init)(struct weston_compositor *ec, int (*module_init)(struct weston_compositor *ec,
int *argc, char *argv[], const char *config_file); int *argc, char *argv[]);
if (modules == NULL) if (modules == NULL)
return 0; return 0;
@ -2961,7 +2965,7 @@ load_modules(struct weston_compositor *ec, const char *modules,
snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p); snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
module_init = load_module(buffer, "module_init"); module_init = load_module(buffer, "module_init");
if (module_init) if (module_init)
module_init(ec, argc, argv, config_file); module_init(ec, argc, argv);
p = end; p = end;
while (*p == ',') while (*p == ',')
p++; p++;
@ -3087,8 +3091,8 @@ int main(int argc, char *argv[])
struct wl_event_loop *loop; struct wl_event_loop *loop;
struct weston_compositor struct weston_compositor
*(*backend_init)(struct wl_display *display, *(*backend_init)(struct wl_display *display,
int *argc, char *argv[], const char *config_file); int *argc, char *argv[], int config_fd);
int i; int i, config_fd;
char *backend = NULL; char *backend = NULL;
const char *modules = "desktop-shell.so", *option_modules = NULL; const char *modules = "desktop-shell.so", *option_modules = NULL;
char *log = NULL; char *log = NULL;
@ -3096,7 +3100,6 @@ int main(int argc, char *argv[])
int32_t help = 0; int32_t help = 0;
char *socket_name = "wayland-0"; char *socket_name = "wayland-0";
int32_t version = 0; int32_t version = 0;
char *config_file;
const struct config_key core_config_keys[] = { const struct config_key core_config_keys[] = {
{ "modules", CONFIG_KEY_STRING, &modules }, { "modules", CONFIG_KEY_STRING, &modules },
@ -3162,14 +3165,14 @@ int main(int argc, char *argv[])
backend = WESTON_NATIVE_BACKEND; backend = WESTON_NATIVE_BACKEND;
} }
config_file = config_file_path("weston.ini"); config_fd = open_config_file("weston.ini");
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), NULL); parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), NULL);
backend_init = load_module(backend, "backend_init"); backend_init = load_module(backend, "backend_init");
if (!backend_init) if (!backend_init)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
ec = backend_init(display, &argc, argv, config_file); ec = backend_init(display, &argc, argv, config_fd);
if (ec == NULL) { if (ec == NULL) {
weston_log("fatal: failed to create compositor\n"); weston_log("fatal: failed to create compositor\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -3182,13 +3185,11 @@ int main(int argc, char *argv[])
setenv("WAYLAND_DISPLAY", socket_name, 1); setenv("WAYLAND_DISPLAY", socket_name, 1);
if (load_modules(ec, modules, &argc, argv, config_file) < 0) if (load_modules(ec, modules, &argc, argv) < 0)
goto out; goto out;
if (load_modules(ec, option_modules, &argc, argv, config_file) < 0) if (load_modules(ec, option_modules, &argc, argv) < 0)
goto out; goto out;
free(config_file);
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
weston_log("fatal: unhandled option: %s\n", argv[i]); weston_log("fatal: unhandled option: %s\n", argv[i]);
if (argc > 1) { if (argc > 1) {

@ -545,6 +545,8 @@ struct weston_compositor {
struct xkb_rule_names xkb_names; struct xkb_rule_names xkb_names;
struct xkb_context *xkb_context; struct xkb_context *xkb_context;
struct weston_xkb_info xkb_info; struct weston_xkb_info xkb_info;
int config_fd;
}; };
struct weston_buffer_reference { struct weston_buffer_reference {
@ -987,7 +989,7 @@ weston_compositor_get_time(void);
int int
weston_compositor_init(struct weston_compositor *ec, struct wl_display *display, weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
int *argc, char *argv[], const char *config_file); int *argc, char *argv[], int config_fd);
void void
weston_compositor_shutdown(struct weston_compositor *ec); weston_compositor_shutdown(struct weston_compositor *ec);
void void
@ -1125,11 +1127,11 @@ noop_renderer_init(struct weston_compositor *ec);
struct weston_compositor * struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct wl_display *display, int *argc, char *argv[],
const char *config_file); int config_fd);
int int
module_init(struct weston_compositor *compositor, module_init(struct weston_compositor *compositor,
int *argc, char *argv[], const char *config_file); int *argc, char *argv[]);
void void
weston_transformed_coord(int width, int height, weston_transformed_coord(int width, int height,

@ -375,7 +375,7 @@ get_animation_type(char *animation)
} }
static void static void
shell_configuration(struct desktop_shell *shell, const char *config_file) shell_configuration(struct desktop_shell *shell, int config_fd)
{ {
char *path = NULL; char *path = NULL;
int duration = 60; int duration = 60;
@ -400,7 +400,7 @@ shell_configuration(struct desktop_shell *shell, const char *config_file)
{ "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
}; };
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), shell);
shell->screensaver.path = path; shell->screensaver.path = path;
shell->screensaver.duration = duration * 1000; shell->screensaver.duration = duration * 1000;
@ -4286,7 +4286,7 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
WL_EXPORT int WL_EXPORT int
module_init(struct weston_compositor *ec, module_init(struct weston_compositor *ec,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[])
{ {
struct weston_seat *seat; struct weston_seat *seat;
struct desktop_shell *shell; struct desktop_shell *shell;
@ -4333,7 +4333,7 @@ module_init(struct weston_compositor *ec,
wl_array_init(&shell->workspaces.array); wl_array_init(&shell->workspaces.array);
wl_list_init(&shell->workspaces.client_list); wl_list_init(&shell->workspaces.client_list);
shell_configuration(shell, config_file); shell_configuration(shell, ec->config_fd);
for (i = 0; i < shell->workspaces.num; i++) { for (i = 0; i < shell->workspaces.num; i++) {
pws = wl_array_add(&shell->workspaces.array, sizeof *pws); pws = wl_array_add(&shell->workspaces.array, sizeof *pws);

@ -527,7 +527,7 @@ tablet_shell_destroy(struct wl_listener *listener, void *data)
WL_EXPORT int WL_EXPORT int
module_init(struct weston_compositor *compositor, module_init(struct weston_compositor *compositor,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[])
{ {
struct tablet_shell *shell; struct tablet_shell *shell;
struct wl_event_loop *loop; struct wl_event_loop *loop;

@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "compositor.h" #include "compositor.h"
#include "text-server-protocol.h" #include "text-server-protocol.h"
@ -885,7 +886,7 @@ handle_seat_created(struct wl_listener *listener,
static void static void
text_backend_configuration(struct text_backend *text_backend) text_backend_configuration(struct text_backend *text_backend)
{ {
char *config_file; int config_fd;
char *path = NULL; char *path = NULL;
struct config_key input_method_keys[] = { struct config_key input_method_keys[] = {
@ -896,9 +897,9 @@ text_backend_configuration(struct text_backend *text_backend)
{ "input-method", input_method_keys, ARRAY_LENGTH(input_method_keys), NULL } { "input-method", input_method_keys, ARRAY_LENGTH(input_method_keys), NULL }
}; };
config_file = config_file_path("weston.ini"); config_fd = open_config_file("weston.ini");
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), text_backend); parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), text_backend);
free(config_file); close(config_fd);
if (path) if (path)
text_backend->input_method.path = path; text_backend->input_method.path = path;

@ -316,7 +316,7 @@ weston_xserver_destroy(struct wl_listener *l, void *data)
WL_EXPORT int WL_EXPORT int
module_init(struct weston_compositor *compositor, module_init(struct weston_compositor *compositor,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[])
{ {
struct wl_display *display = compositor->wl_display; struct wl_display *display = compositor->wl_display;

@ -225,7 +225,7 @@ idle_launch_client(void *data)
WL_EXPORT int WL_EXPORT int
module_init(struct weston_compositor *ec, module_init(struct weston_compositor *ec,
int *argc, char *argv[], const char *config_file) int *argc, char *argv[])
{ {
struct weston_test *test; struct weston_test *test;
struct wl_event_loop *loop; struct wl_event_loop *loop;

Loading…
Cancel
Save