summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2014-09-08 11:47:19 +1200
committerRobert Ancell <robert.ancell@canonical.com>2014-09-08 11:47:19 +1200
commit55d5bd21685f2e5e64a62e9fbb23624fdb9e8ea3 (patch)
tree286c94e5b38fe5b987b3a789227f72ae546ba8ce
parente0096d5bb324462eba5e426442d154c3c9ace2a1 (diff)
downloadlightdm-git-55d5bd21685f2e5e64a62e9fbb23624fdb9e8ea3.tar.gz
Add --show-config option that shows combined configuration
-rw-r--r--common/configuration.c58
-rw-r--r--common/configuration.h6
-rw-r--r--src/lightdm.c87
-rw-r--r--src/seat-unity.c6
-rw-r--r--src/seat-xlocal.c6
5 files changed, 140 insertions, 23 deletions
diff --git a/common/configuration.c b/common/configuration.c
index aeba6e30..bf08c7d9 100644
--- a/common/configuration.c
+++ b/common/configuration.c
@@ -15,7 +15,10 @@
struct ConfigurationPrivate
{
+ gchar *dir;
GKeyFile *key_file;
+ GList *sources;
+ GHashTable *key_sources;
};
G_DEFINE_TYPE (Configuration, config, G_TYPE_OBJECT);
@@ -34,7 +37,7 @@ gboolean
config_load_from_file (Configuration *config, const gchar *path, GError **error)
{
GKeyFile *key_file;
- gchar **groups;
+ gchar *source_path, **groups;
int i;
key_file = g_key_file_new ();
@@ -44,6 +47,9 @@ config_load_from_file (Configuration *config, const gchar *path, GError **error)
return FALSE;
}
+ source_path = g_strdup (path);
+ config->priv->sources = g_list_append (config->priv->sources, source_path);
+
groups = g_key_file_get_groups (key_file, NULL);
for (i = 0; groups[i]; i++)
{
@@ -56,11 +62,14 @@ config_load_from_file (Configuration *config, const gchar *path, GError **error)
for (j = 0; keys[j]; j++)
{
- gchar *value;
+ gchar *value, *k;
value = g_key_file_get_value (key_file, groups[i], keys[j], NULL);
g_key_file_set_value (config->priv->key_file, groups[i], keys[j], value);
g_free (value);
+
+ k = g_strdup_printf ("%s]%s", groups[i], keys[j]);
+ g_hash_table_insert (config->priv->key_sources, k, source_path);
}
g_strfreev (keys);
@@ -159,25 +168,26 @@ load_config_directories (const gchar * const *dirs, GList **messages)
gboolean
config_load_from_standard_locations (Configuration *config, const gchar *config_path, GList **messages)
{
- gchar *config_dir, *config_d_dir = NULL, *path;
+ gchar *config_d_dir = NULL, *path;
gboolean success = TRUE;
GError *error = NULL;
+ g_return_val_if_fail (config->priv->dir == NULL, FALSE);
+
load_config_directories (g_get_system_data_dirs (), messages);
load_config_directories (g_get_system_config_dirs (), messages);
if (config_path)
{
- config_dir = path_make_absolute (g_path_get_basename (config_path));
path = g_strdup (config_path);
+ config->priv->dir = path_make_absolute (g_path_get_basename (config_path));
}
else
{
- config_dir = g_strdup (CONFIG_DIR);
- config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
- path = g_build_filename (config_dir, "lightdm.conf", NULL);
+ config->priv->dir = g_strdup (CONFIG_DIR);
+ config_d_dir = g_build_filename (config->priv->dir, "lightdm.conf.d", NULL);
+ path = g_build_filename (config->priv->dir, "lightdm.conf", NULL);
}
- config_set_string (config, "LightDM", "config-directory", config_dir);
if (config_d_dir)
load_config_directory (config_d_dir, messages);
@@ -199,13 +209,18 @@ config_load_from_standard_locations (Configuration *config, const gchar *config_
}
g_clear_error (&error);
- g_free (config_dir);
g_free (config_d_dir);
g_free (path);
return success;
}
+const gchar *
+config_get_directory (Configuration *config)
+{
+ return config->priv->dir;
+}
+
gchar **
config_get_groups (Configuration *config)
{
@@ -224,6 +239,25 @@ config_has_key (Configuration *config, const gchar *section, const gchar *key)
return g_key_file_has_key (config->priv->key_file, section, key, NULL);
}
+GList *
+config_get_sources (Configuration *config)
+{
+ return config->priv->sources;
+}
+
+const gchar *
+config_get_source (Configuration *config, const gchar *section, const gchar *key)
+{
+ gchar *k;
+ const gchar *source;
+
+ k = g_strdup_printf ("%s]%s", section, key);
+ source = g_hash_table_lookup (config->priv->key_sources, k);
+ g_free (k);
+
+ return source;
+}
+
void
config_set_string (Configuration *config, const gchar *section, const gchar *key, const gchar *value)
{
@@ -276,7 +310,8 @@ static void
config_init (Configuration *config)
{
config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, CONFIGURATION_TYPE, ConfigurationPrivate);
- config->priv->key_file = g_key_file_new ();
+ config->priv->key_file = g_key_file_new ();
+ config->priv->key_sources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
static void
@@ -286,7 +321,10 @@ config_finalize (GObject *object)
self = CONFIGURATION (object);
+ g_free (self->priv->dir);
g_key_file_free (self->priv->key_file);
+ g_list_free_full (self->priv->sources, g_free);
+ g_hash_table_destroy (self->priv->key_sources);
G_OBJECT_CLASS (config_parent_class)->finalize (object);
}
diff --git a/common/configuration.h b/common/configuration.h
index b689398e..5f3004cc 100644
--- a/common/configuration.h
+++ b/common/configuration.h
@@ -40,12 +40,18 @@ gboolean config_load_from_file (Configuration *config, const gchar *path, GError
gboolean config_load_from_standard_locations (Configuration *config, const gchar *config_path, GList **messages);
+const gchar *config_get_directory (Configuration *config);
+
gchar **config_get_groups (Configuration *config);
gchar **config_get_keys (Configuration *config, const gchar *group_name);
gboolean config_has_key (Configuration *config, const gchar *section, const gchar *key);
+GList *config_get_sources (Configuration *config);
+
+const gchar *config_get_source (Configuration *config, const gchar *section, const gchar *key);
+
void config_set_string (Configuration *config, const gchar *section, const gchar *key, const gchar *value);
gchar *config_get_string (Configuration *config, const gchar *section, const gchar *key);
diff --git a/src/lightdm.c b/src/lightdm.c
index 15e21bf0..97f6c0c7 100644
--- a/src/lightdm.c
+++ b/src/lightdm.c
@@ -828,14 +828,12 @@ bus_acquired_cb (GDBusConnection *connection,
key_name = config_get_string (config_get_instance (), "XDMCPServer", "key");
if (key_name)
{
- gchar *dir, *path;
+ gchar *path;
GKeyFile *keys;
gboolean result;
GError *error = NULL;
- dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
- path = g_build_filename (dir, "keys.conf", NULL);
- g_free (dir);
+ path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
keys = g_key_file_new ();
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
@@ -919,7 +917,7 @@ main (int argc, char **argv)
gchar *default_log_dir = g_strdup (LOG_DIR);
gchar *default_run_dir = g_strdup (RUN_DIR);
gchar *default_cache_dir = g_strdup (CACHE_DIR);
- gboolean show_version = FALSE;
+ gboolean show_config = FALSE, show_version = FALSE;
GList *link, *messages = NULL;
GOptionEntry options[] =
{
@@ -944,6 +942,9 @@ main (int argc, char **argv)
{ "cache-dir", 0, 0, G_OPTION_ARG_STRING, &cache_dir,
/* Help string for command line --cache-dir flag */
N_("Directory to cache information"), "DIRECTORY" },
+ { "show-config", 0, 0, G_OPTION_ARG_NONE, &show_config,
+ /* Help string for command line --show-config flag */
+ N_("Show combined configuration"), NULL },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
/* Help string for command line --version flag */
N_("Show release version"), NULL },
@@ -980,6 +981,82 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
+ /* Show combined configuration if user requested it */
+ if (show_config)
+ {
+ GList *sources, *link;
+ gchar **groups, *last_source, *empty_source;
+ GHashTable *source_ids;
+ int i;
+
+ if (!config_load_from_standard_locations (config_get_instance (), config_path, NULL))
+ return EXIT_FAILURE;
+
+ /* Number sources */
+ sources = config_get_sources (config_get_instance ());
+ source_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ last_source = "";
+ for (i = 0, link = sources; link; i++, link = link->next)
+ {
+ gchar *path, *id;
+
+ path = link->data;
+ if (i < 26)
+ id = g_strdup_printf ("%c", 'A' + i);
+ else
+ id = g_strdup_printf ("%d", i);
+ g_hash_table_insert (source_ids, g_strdup (path), id);
+ last_source = id;
+ }
+ empty_source = g_strdup (last_source);
+ for (i = 0; empty_source[i] != '\0'; i++)
+ empty_source[i] = ' ';
+
+ /* Print out keys */
+ groups = config_get_groups (config_get_instance ());
+ for (i = 0; groups[i]; i++)
+ {
+ gchar **keys;
+ int j;
+
+ if (i != 0)
+ g_printerr ("\n");
+ g_printerr ("%s [%s]\n", empty_source, groups[i]);
+
+ keys = config_get_keys (config_get_instance (), groups[i]);
+ for (j = 0; keys[j]; j++)
+ {
+ const gchar *source, *id;
+ gchar *value;
+
+ source = config_get_source (config_get_instance (), groups[i], keys[j]);
+ id = source ? g_hash_table_lookup (source_ids, source) : empty_source;
+ value = config_get_string (config_get_instance (), groups[i], keys[j]);
+ g_printerr ("%s %s=%s\n", id, keys[j], value);
+ g_free (value);
+ }
+
+ g_strfreev (keys);
+ }
+ g_strfreev (groups);
+
+ /* Show mapping from source number to path */
+ g_printerr ("\n");
+ g_printerr ("Sources:\n");
+ for (link = sources; link; link = link->next)
+ {
+ const gchar *path = link->data;
+ const gchar *source;
+
+ source = g_hash_table_lookup (source_ids, path);
+ g_printerr ("%s %s\n", source, path);
+ }
+
+ g_hash_table_destroy (source_ids);
+
+ return EXIT_SUCCESS;
+ }
+
if (show_version)
{
/* NOTE: Is not translated so can be easily parsed */
diff --git a/src/seat-unity.c b/src/seat-unity.c
index fb2aafef..15c23b8b 100644
--- a/src/seat-unity.c
+++ b/src/seat-unity.c
@@ -165,14 +165,12 @@ create_x_server (Seat *seat)
key_name = seat_get_string_property (seat, "xdmcp-key");
if (key_name)
{
- gchar *dir, *path;
+ gchar *path;
GKeyFile *keys;
gboolean result;
GError *error = NULL;
- dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
- path = g_build_filename (dir, "keys.conf", NULL);
- g_free (dir);
+ path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
keys = g_key_file_new ();
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
diff --git a/src/seat-xlocal.c b/src/seat-xlocal.c
index 4c0e77d9..8e9e70ba 100644
--- a/src/seat-xlocal.c
+++ b/src/seat-xlocal.c
@@ -138,14 +138,12 @@ create_x_server (Seat *seat)
key_name = seat_get_string_property (seat, "xdmcp-key");
if (key_name)
{
- gchar *dir, *path;
+ gchar *path;
GKeyFile *keys;
gboolean result;
GError *error = NULL;
- dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
- path = g_build_filename (dir, "keys.conf", NULL);
- g_free (dir);
+ path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
keys = g_key_file_new ();
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);