]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - src/lightdm.c
Move config loading into one function; move that function into libcommon; call it...
[sojka/lightdm.git] / src / lightdm.c
index faa4a66b307e1946499bdbcfaee472eef33e81af..15e21bf09dbbbb47b46146eb689e070981c88f1d 100644 (file)
@@ -903,73 +903,6 @@ name_lost_cb (GDBusConnection *connection,
     exit (EXIT_FAILURE);
 }
 
-static gchar *
-path_make_absolute (gchar *path)
-{
-    gchar *cwd, *abs_path;
-
-    if (!path)
-        return NULL;
-
-    if (g_path_is_absolute (path))
-        return path;
-
-    cwd = g_get_current_dir ();
-    abs_path = g_build_filename (cwd, path, NULL);
-    g_free (path);
-
-    return abs_path;
-}
-
-static int
-compare_strings (gconstpointer a, gconstpointer b)
-{
-    return strcmp (a, b);
-}
-
-static void
-load_config_directory (const gchar *path, GList **messages)
-{
-    GDir *dir;
-    GList *files = NULL, *link;
-    GError *error = NULL;
-
-    /* Find configuration files */
-    dir = g_dir_open (path, 0, &error);
-    if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
-        g_printerr ("Failed to open configuration directory %s: %s\n", path, error->message);
-    g_clear_error (&error);
-    if (dir)
-    {
-        const gchar *name;
-        while ((name = g_dir_read_name (dir)))
-            files = g_list_append (files, g_strdup (name));
-        g_dir_close (dir);
-    }
-
-    /* Sort alphabetically and load onto existing configuration */
-    files = g_list_sort (files, compare_strings);
-    for (link = files; link; link = link->next)
-    {
-        gchar *filename = link->data;
-        gchar *conf_path;
-
-        conf_path = g_build_filename (path, filename, NULL);
-        if (g_str_has_suffix (filename, ".conf"))
-        {
-            *messages = g_list_append (*messages, g_strdup_printf ("Loading configuration from %s", conf_path));
-            config_load_from_file (config_get_instance (), conf_path, &error);
-            if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
-                g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
-            g_clear_error (&error);
-        }
-        else
-            g_debug ("Ignoring configuration file %s, it does not have .conf suffix", conf_path);
-        g_free (conf_path);
-    }
-    g_list_free_full (files, g_free);
-}
-
 int
 main (int argc, char **argv)
 {
@@ -978,10 +911,8 @@ main (int argc, char **argv)
     gboolean result;
     gchar **groups, **i, *dir;
     gint n_seats = 0;
-    gboolean explicit_config = FALSE;
     gboolean test_mode = FALSE;
     gchar *pid_path = "/var/run/lightdm.pid";
-    gchar *config_dir, *config_d_dir = NULL;
     gchar *log_dir = NULL;
     gchar *run_dir = NULL;
     gchar *cache_dir = NULL;
@@ -1056,21 +987,6 @@ main (int argc, char **argv)
         return EXIT_SUCCESS;
     }
 
-    if (config_path)
-    {
-        config_dir = g_path_get_basename (config_path);
-        config_dir = path_make_absolute (config_dir);
-        explicit_config = TRUE;
-    }
-    else
-    {
-        config_dir = g_strdup (CONFIG_DIR);
-        config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
-        config_path = g_build_filename (config_dir, "lightdm.conf", NULL);
-    }
-    config_set_string (config_get_instance (), "LightDM", "config-directory", config_dir);
-    g_free (config_dir);
-
     if (!test_mode && getuid () != 0)
     {
         g_printerr ("Only root can run Light Display Manager.  To run as a regular user for testing run with the --test-mode flag.\n");
@@ -1125,25 +1041,8 @@ main (int argc, char **argv)
     }
 
     /* Load config file(s) */
-    load_config_directory (SYSTEM_CONFIG_DIR, &messages);
-    if (config_d_dir)
-        load_config_directory (config_d_dir, &messages);
-    g_free (config_d_dir);
-    messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", config_path));
-    if (!config_load_from_file (config_get_instance (), config_path, &error))
-    {
-        gboolean is_empty;
-
-        is_empty = error && g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
-
-        if (explicit_config || !is_empty)
-        {
-            if (error)
-                g_printerr ("Failed to load configuration from %s: %s\n", config_path, error->message);
-            exit (EXIT_FAILURE);
-        }
-    }
-    g_clear_error (&error);
+    if (!config_load_from_standard_locations (config_get_instance (), config_path, &messages))
+        exit (EXIT_FAILURE);
     g_free (config_path);
 
     /* Set default values */