[PATCH 3/6] Use readvars_parse_file() in loader/modules.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 loader/modules.c |   65 +++++++++++++++++++----------------------------------
 1 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/loader/modules.c b/loader/modules.c
index cf69969..8fc07df 100644
--- a/loader/modules.c
+++ b/loader/modules.c
@@ -44,6 +44,7 @@
 #include "../pyanaconda/isys/log.h"
 
 #include "modules.h"
+#include "readvars.h"
 
 /* boot flags */
 extern uint64_t flags;
@@ -244,60 +245,40 @@ static gboolean _doLoadModule(const gchar *module, gchar **args) {
 }
 
 gboolean mlInitModuleConfig(void) {
-    gint i = 0;
-    gchar *cmdline = NULL;
-    gchar **options = NULL;
-    GError *readErr = NULL;
-
-    /* read module options out of /proc/cmdline and into a structure */
-    if (!g_file_get_contents("/proc/cmdline", &cmdline, NULL, &readErr)) {
-        logMessage(ERROR, "unable to read /proc/cmdline: %s", readErr->message);
-        g_error_free(readErr);
-        return _writeModulesConf(MODULES_CONF);
-    }
-
-    cmdline = g_strchomp(cmdline);
-    options = g_strsplit(cmdline, " ", 0);
-    g_free(cmdline);
+    GHashTableIter iter;
+    gpointer key = NULL, value = NULL;
+    GHashTable *cmdline = readvars_parse_file("/proc/cmdline");
 
-    if (options == NULL) {
+    if (cmdline == NULL) {
         return _writeModulesConf(MODULES_CONF);
     }
 
-    while (options[i] != NULL) {
-        gchar *tmpmod = NULL;
-        gchar **fields = NULL;
+    g_hash_table_iter_init(&iter, cmdline);
 
-        if (g_strstr_len(options[i], -1, "=") == NULL) {
-            i++;
-            continue;
-        }
+    while (g_hash_table_iter_next(&iter, &key, &value)) {
+        gchar *k = (gchar *) key;
+        gchar *v = (gchar *) value;
 
-        if (!strncmp(options[i], "blacklist=", 10)) {
-            if ((fields = g_strsplit(options[i], "=", 0)) != NULL) {
-                if (g_strv_length(fields) == 2) {
-                    tmpmod = g_strdup(fields[1]);
-                    blacklist = g_slist_append(blacklist, tmpmod);
-                }
-            }
-        } else if ((fields = g_strsplit(options[i], ".", 0)) != NULL) {
-            if (g_strv_length(fields) == 2) {
-                if (_isValidModule(fields[0])) {
-                    _addOption(fields[0], fields[1]);
-                }
+        if (v == NULL) {
+            continue;
+        } else if (!strcasecmp(k, "blacklist")) {
+            gchar *tmpmod = g_strdup(v);
+            blacklist = g_slist_append(blacklist, tmpmod);
+        } else if (!strstr(k, ".")) {
+            gchar **fields = g_strsplit(k, ".", 0);
+
+            if (g_strv_length(fields) == 2 && _isValidModule(fields[0])) {
+                GString *tmp = g_string_new(fields[1]);
+                g_string_append_printf(tmp, "=%s", v);
+                _addOption(fields[0], tmp->str);
+                g_string_free(tmp, TRUE);
             }
-        }
 
-        if (fields != NULL) {
             g_strfreev(fields);
         }
-
-        i++;
     }
 
-    if (options != NULL) {
-        g_strfreev(options);
-    }
+    g_hash_table_destroy(cmdline);
 
     return _writeModulesConf(MODULES_CONF);
 }
-- 
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux