76
path_make_absolute (gchar *path)
78
gchar *cwd, *abs_path;
83
if (g_path_is_absolute (path))
86
cwd = g_get_current_dir ();
87
abs_path = g_build_filename (cwd, path, NULL);
94
compare_strings (gconstpointer a, gconstpointer b)
100
load_config_directory (const gchar *path, GList **messages)
103
GList *files = NULL, *link;
104
GError *error = NULL;
106
/* Find configuration files */
107
dir = g_dir_open (path, 0, &error);
108
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
109
g_printerr ("Failed to open configuration directory %s: %s\n", path, error->message);
110
g_clear_error (&error);
114
while ((name = g_dir_read_name (dir)))
115
files = g_list_append (files, g_strdup (name));
119
/* Sort alphabetically and load onto existing configuration */
120
files = g_list_sort (files, compare_strings);
121
for (link = files; link; link = link->next)
123
gchar *filename = link->data;
126
conf_path = g_build_filename (path, filename, NULL);
127
if (g_str_has_suffix (filename, ".conf"))
130
*messages = g_list_append (*messages, g_strdup_printf ("Loading configuration from %s", conf_path));
131
config_load_from_file (config_get_instance (), conf_path, &error);
132
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
133
g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
134
g_clear_error (&error);
137
g_debug ("Ignoring configuration file %s, it does not have .conf suffix", conf_path);
140
g_list_free_full (files, g_free);
144
load_config_directories (const gchar * const *dirs, GList **messages)
148
/* Load in reverse order, because XDG_* fields are preference-ordered and the directories in front should override directories in back. */
149
for (i = g_strv_length ((gchar **)dirs) - 1; i >= 0; i--)
151
gchar *full_dir = g_build_filename (dirs[i], "lightdm", "lightdm.conf.d", NULL);
153
*messages = g_list_append (*messages, g_strdup_printf ("Loading configuration dirs from %s", full_dir));
154
load_config_directory (full_dir, messages);
160
config_load_from_standard_locations (Configuration *config, const gchar *config_path, GList **messages)
162
gchar *config_dir, *config_d_dir = NULL;
163
gboolean explicit_config = FALSE;
164
gboolean success = TRUE;
165
GError *error = NULL;
167
load_config_directories (g_get_system_data_dirs (), messages);
168
load_config_directories (g_get_system_config_dirs (), messages);
172
config_dir = g_path_get_basename (config_path);
173
config_dir = path_make_absolute (config_dir);
174
explicit_config = TRUE;
178
config_dir = g_strdup (CONFIG_DIR);
179
config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
180
config_path = g_build_filename (config_dir, "lightdm.conf", NULL);
182
config_set_string (config, "LightDM", "config-directory", config_dir);
186
load_config_directory (config_d_dir, messages);
187
g_free (config_d_dir);
190
*messages = g_list_append (*messages, g_strdup_printf ("Loading configuration from %s", config_path));
191
if (!config_load_from_file (config, config_path, &error))
195
is_empty = error && g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
197
if (explicit_config || !is_empty)
200
g_printerr ("Failed to load configuration from %s: %s\n", config_path, error->message);
204
g_clear_error (&error);
74
210
config_get_groups (Configuration *config)