compositor: add option to specify a weston.ini

Add a command line option to specify a file to be read instead of
weston.ini.

IVI-shell testing will at least temporarily need to specify a config
file, because it cannot run without. That is why this is being added,
but should be convenient for everybody, too.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Reviewed-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
diff --git a/src/compositor.c b/src/compositor.c
index 3a90cce..4de8fbf 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -5213,25 +5213,39 @@
 }
 
 static int
-load_configuration(struct weston_config **config, int32_t noconfig)
+load_configuration(struct weston_config **config, int32_t noconfig,
+		   const char *config_file)
 {
+	const char *file = "weston.ini";
 	const char *full_path;
 
 	*config = NULL;
 
+	if (config_file)
+		file = config_file;
+
 	if (noconfig == 0)
-		*config = weston_config_parse("weston.ini");
+		*config = weston_config_parse(file);
 
 	if (*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;
 	}
 
+	if (config_file && noconfig == 0) {
+		weston_log("fatal: error opening or reading config file"
+			   " '%s'.\n", config_file);
+
+		return -1;
+	}
+
+	weston_log("Starting with no config file.\n");
+	setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
+
 	return 0;
 }
 
@@ -5259,6 +5273,7 @@
 	int32_t version = 0;
 	int32_t noconfig = 0;
 	int32_t numlock_on;
+	char *config_file = NULL;
 	struct weston_config *config;
 	struct weston_config_section *section;
 	struct wl_client *primary_client;
@@ -5275,6 +5290,7 @@
 		{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
 		{ WESTON_OPTION_BOOLEAN, "version", 0, &version },
 		{ WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig },
+		{ WESTON_OPTION_STRING, "config", 'c', &config_file },
 	};
 
 	parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
@@ -5316,7 +5332,7 @@
 	if (!signals[0] || !signals[1] || !signals[2] || !signals[3])
 		goto out_signals;
 
-	if (load_configuration(&config, noconfig) < 0)
+	if (load_configuration(&config, noconfig, config_file) < 0)
 		goto out_signals;
 
 	section = weston_config_get_section(config, "core", NULL, NULL);
@@ -5436,6 +5452,7 @@
 
 	weston_log_file_close();
 
+	free(config_file);
 	free(backend);
 	free(shell);
 	free(socket_name);