]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
main: refactor theme loading code to reduce duplication
authorRay Strode <rstrode@redhat.com>
Fri, 10 Jan 2014 16:10:16 +0000 (11:10 -0500)
committerRay Strode <rstrode@redhat.com>
Fri, 10 Jan 2014 19:17:57 +0000 (14:17 -0500)
Right now we read /usr/share/plymouthd/plymouthd.defaults
and /etc/plymouth/plymouthd.conf to find the configured splash
screen.  The two functions that do this are basically copy-and-paste
of each other.

This commits splits some of the duplicated code out into a common
function for clarity.  Doing this also helps to facilitate adding
more configuration options, which we'll need to do in the future
to support a global start up delay.

src/main.c

index 50ccbf064784a9770fda5877a58e08c8eff3ac29..4c0f84364bf30de019ae4de839bd12a4020f8ce5 100644 (file)
@@ -256,6 +256,37 @@ show_messages (state_t *state)
     }
 }
 
+static bool
+load_settings (state_t     *state,
+               const char  *path,
+               char       **theme_path)
+{
+  ply_key_file_t *key_file = NULL;
+  bool settings_loaded = false;
+  const char *splash_string;
+
+  ply_trace ("Trying to load %s", path);
+  key_file = ply_key_file_new (path);
+
+  if (!ply_key_file_load (key_file))
+    goto out;
+
+  splash_string = ply_key_file_get_value (key_file, "Daemon", "Theme");
+
+  if (splash_string == NULL)
+    goto out;
+
+  asprintf (theme_path,
+            PLYMOUTH_THEME_PATH "%s/%s.plymouth",
+            splash_string, splash_string);
+
+  settings_loaded = true;
+out:
+  ply_key_file_free (key_file);
+
+  return settings_loaded;
+}
+
 static void
 show_detailed_splash (state_t *state)
 {
@@ -341,60 +372,31 @@ find_override_splash (state_t *state)
 static void
 find_system_default_splash (state_t *state)
 {
-  ply_key_file_t *key_file;
-  char *splash_string;
-
   if (state->system_default_splash_path != NULL)
       return;
 
-  ply_trace ("Trying to load " PLYMOUTH_CONF_DIR "plymouthd.conf");
-  key_file = ply_key_file_new (PLYMOUTH_CONF_DIR "plymouthd.conf");
-
-  if (!ply_key_file_load (key_file))
+  if (!load_settings (state, PLYMOUTH_CONF_DIR "plymouthd.conf", &state->system_default_splash_path))
     {
       ply_trace ("failed to load " PLYMOUTH_CONF_DIR "plymouthd.conf");
-      ply_key_file_free (key_file);
       return;
     }
 
-  splash_string = ply_key_file_get_value (key_file, "Daemon", "Theme");
-
-  ply_trace ("System default splash is configured to be '%s'", splash_string);
-
-  asprintf (&state->system_default_splash_path,
-            PLYMOUTH_THEME_PATH "%s/%s.plymouth",
-            splash_string, splash_string);
-  free (splash_string);
-  ply_key_file_free (key_file);
+  ply_trace ("System configured theme file is '%s'", state->system_default_splash_path);
 }
 
 static void
 find_distribution_default_splash (state_t *state)
 {
-  ply_key_file_t *key_file;
-  char *splash_string;
-
   if (state->distribution_default_splash_path != NULL)
       return;
 
-  ply_trace ("Trying to load " PLYMOUTH_POLICY_DIR "plymouthd.defaults");
-  key_file = ply_key_file_new (PLYMOUTH_POLICY_DIR "plymouthd.defaults");
-
-  if (!ply_key_file_load (key_file))
+  if (!load_settings (state, PLYMOUTH_POLICY_DIR "plymouthd.conf", &state->distribution_default_splash_path))
     {
-      ply_trace ("failed to load " PLYMOUTH_POLICY_DIR "plymouthd.defaults");
-      ply_key_file_free (key_file);
+      ply_trace ("failed to load " PLYMOUTH_POLICY_DIR "plymouthd.conf");
       return;
     }
 
-  splash_string = ply_key_file_get_value (key_file, "Daemon", "Theme");
-
-  ply_trace ("Distribution default splash is configured to be '%s'", splash_string);
-
-  asprintf (&state->distribution_default_splash_path,
-            PLYMOUTH_THEME_PATH "%s/%s.plymouth",
-            splash_string, splash_string);
-  free (splash_string);
+  ply_trace ("Distribution default theme file is '%s'", state->distribution_default_splash_path);
 }
 
 static void