[PATCH weston 5/6] Pass config file from compositor to everything

Pekka Paalanen ppaalanen at gmail.com
Tue Mar 24 06:56:19 PDT 2015


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

We have the Weston command line option '--no-config' which is meant to
prevent loading weston.ini at all. It works for Weston itself, but it
does not work for any clients that also want to read weston.ini.

To fix that, introduce a new environment variable WESTON_CONFIG_FILE.
Weston will set it to the absolute path of the config file it loads.
Clients will load the config file pointed to by WESTON_CONFIG_FILE. If
the environment variable is set but empty, no config file will be
loaded. If the variable is unset, things fall back to the default
"weston.ini".

Note, that Weston will only set WESTON_CONFIG_FILE, it never reads it.
The ability to specify a custom config file to load will be another patch.

All programs that loaded "weston.ini" are modified to honour
WESTON_CONFIG_FILE.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 clients/desktop-shell.c            |  4 +++-
 clients/ivi-shell-user-interface.c |  4 +++-
 clients/terminal.c                 |  4 +++-
 clients/window.c                   |  4 +++-
 man/weston.man                     |  9 +++++++++
 shared/config-parser.c             | 12 ++++++++++++
 shared/config-parser.h             |  5 +++++
 src/compositor.c                   |  9 +++++++--
 8 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 961a9b2..ac2928f 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -1328,11 +1328,13 @@ int main(int argc, char *argv[])
 	struct desktop desktop = { 0 };
 	struct output *output;
 	struct weston_config_section *s;
+	const char *config_file;
 
 	desktop.unlock_task.run = unlock_dialog_finish;
 	wl_list_init(&desktop.outputs);
 
-	desktop.config = weston_config_parse("weston.ini");
+	config_file = weston_config_get_name_from_env();
+	desktop.config = weston_config_parse(config_file);
 	s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
 	weston_config_section_get_bool(s, "locking", &desktop.locking, 1);
 
diff --git a/clients/ivi-shell-user-interface.c b/clients/ivi-shell-user-interface.c
index 324ea7a..a83f9ad 100644
--- a/clients/ivi-shell-user-interface.c
+++ b/clients/ivi-shell-user-interface.c
@@ -1073,6 +1073,7 @@ create_launchers(struct wlContextCommon *cmm, struct wl_list *launcher_list)
 static struct hmi_homescreen_setting *
 hmi_homescreen_setting_create(void)
 {
+	const char *config_file;
 	struct weston_config *config = NULL;
 	struct weston_config_section *shellSection = NULL;
 	struct hmi_homescreen_setting *setting = MEM_ALLOC(sizeof(*setting));
@@ -1084,7 +1085,8 @@ hmi_homescreen_setting_create(void)
 	wl_list_init(&setting->workspace_list);
 	wl_list_init(&setting->launcher_list);
 
-	config = weston_config_parse("weston.ini");
+	config_file = weston_config_get_name_from_env();
+	config = weston_config_parse(config_file);
 
 	shellSection =
 		weston_config_get_section(config, "ivi-shell", NULL, NULL);
diff --git a/clients/terminal.c b/clients/terminal.c
index 7c37101..3e89bdf 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -3050,6 +3050,7 @@ int main(int argc, char *argv[])
 {
 	struct display *d;
 	struct terminal *terminal;
+	const char *config_file;
 	struct weston_config *config;
 	struct weston_config_section *s;
 
@@ -3061,7 +3062,8 @@ int main(int argc, char *argv[])
 	if (!option_shell)
 		option_shell = "/bin/bash";
 
-	config = weston_config_parse("weston.ini");
+	config_file = weston_config_get_name_from_env();
+	config = weston_config_parse(config_file);
 	s = weston_config_get_section(config, "terminal", NULL, NULL);
 	weston_config_section_get_string(s, "font", &option_font, "mono");
 	weston_config_section_get_int(s, "font-size", &option_font_size, 14);
diff --git a/clients/window.c b/clients/window.c
index 62b5185..282e594 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1288,6 +1288,7 @@ static const struct cursor_alternatives cursors[] = {
 static void
 create_cursors(struct display *display)
 {
+	const char *config_file;
 	struct weston_config *config;
 	struct weston_config_section *s;
 	int size;
@@ -1295,7 +1296,8 @@ create_cursors(struct display *display)
 	unsigned int i, j;
 	struct wl_cursor *cursor;
 
-	config = weston_config_parse("weston.ini");
+	config_file = weston_config_get_name_from_env();
+	config = weston_config_parse(config_file);
 	s = weston_config_get_section(config, "shell", NULL, NULL);
 	weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
 	weston_config_section_get_int(s, "cursor-size", &size, 32);
diff --git a/man/weston.man b/man/weston.man
index d8d924e..86ed67b 100644
--- a/man/weston.man
+++ b/man/weston.man
@@ -255,6 +255,15 @@ This allows launching Weston as a nested server.
 For Wayland clients, holds the file descriptor of an open local socket
 to a Wayland server.
 .TP
+.B WESTON_CONFIG_FILE
+Weston sets this variable to the absolute path of the configuration file
+it loads, or to the empty string if no file is used. Programs that use
+.I weston.ini
+will read the file specified by this variable instead, or do not read any
+file if it is empty. Unset variable causes falling back to the default
+name
+.IR weston.ini .
+.TP
 .B XCURSOR_PATH
 Set the list of paths to look for cursors in. It changes both
 libwayland-cursor and libXcursor, so it affects both Wayland and X11 based
diff --git a/shared/config-parser.c b/shared/config-parser.c
index ff6814c..8519eb6 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -294,6 +294,18 @@ weston_config_get_libexec_dir(void)
 	return LIBEXECDIR;
 }
 
+const char *
+weston_config_get_name_from_env(void)
+{
+	const char *name;
+
+	name = getenv(WESTON_CONFIG_FILE_ENV_VAR);
+	if (name)
+		return name;
+
+	return "weston.ini";
+}
+
 static struct weston_config_section *
 config_add_section(struct weston_config *config, const char *name)
 {
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 1ecc8cc..9b76619 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -27,6 +27,8 @@
 extern "C" {
 #endif
 
+#define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE"
+
 enum config_key_type {
 	CONFIG_KEY_INTEGER,		/* typeof data = int */
 	CONFIG_KEY_UNSIGNED_INTEGER,	/* typeof data = unsigned int */
@@ -95,6 +97,9 @@ weston_config_section_get_bool(struct weston_config_section *section,
 const char *
 weston_config_get_libexec_dir(void);
 
+const char *
+weston_config_get_name_from_env(void);
+
 struct weston_config *
 weston_config_parse(const char *name);
 
diff --git a/src/compositor.c b/src/compositor.c
index 2a0e66c..7d5c2e1 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -5213,16 +5213,21 @@ weston_transform_to_string(uint32_t output_transform)
 static int
 load_configuration(struct weston_config **config, int32_t noconfig)
 {
+	const char *full_path;
+
 	*config = NULL;
 
 	if (noconfig == 0)
 		*config = weston_config_parse("weston.ini");
 
 	if (*config) {
-		weston_log("Using config file '%s'\n",
-			   weston_config_get_full_path(*config));
+		full_path = weston_config_get_full_path(*config);
+
+		weston_log("Using config file '%s'\n", full_path);
+		setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
 	} else {
 		weston_log("Starting with no config file.\n");
+		setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
 	}
 
 	return 0;
-- 
2.0.5



More information about the wayland-devel mailing list