From: Alok Barsode <[email protected]>

Add __connman_storage_load_mainconf to load
values from main.conf.
---
 src/connman.h |    1 +
 src/main.c    |   41 ++++++++---------------------------------
 src/storage.c |   17 +++++++++++++++++
 3 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index a13927a..68aa26e 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -164,6 +164,7 @@ GKeyFile *__connman_storage_open_global();
 GKeyFile *__connman_storage_load_global();
 void __connman_storage_save_global(GKeyFile *keyfile);
 void __connman_storage_delete_global();
+GKeyFile *__connman_storage_load_mainconf();
 
 GKeyFile *__connman_storage_load_config(const char *ident);
 void __connman_storage_save_config(GKeyFile *keyfile, const char *ident);
diff --git a/src/main.c b/src/main.c
index ded3bb1..6c69523 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,45 +48,26 @@ static struct {
        .bg_scan = TRUE,
 };
 
-static GKeyFile *load_config(const char *file)
+static void parse_config()
 {
-       GError *err = NULL;
        GKeyFile *keyfile;
-
-       keyfile = g_key_file_new();
-
-       g_key_file_set_list_separator(keyfile, ',');
-
-       if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
-               if (err->code != G_FILE_ERROR_NOENT) {
-                       connman_error("Parsing %s failed: %s", file,
-                                                               err->message);
-               }
-
-               g_error_free(err);
-               g_key_file_free(keyfile);
-               return NULL;
-       }
-
-       return keyfile;
-}
-
-static void parse_config(GKeyFile *config)
-{
        GError *error = NULL;
        gboolean boolean;
 
-       if (config == NULL)
+       keyfile = __connman_storage_load_mainconf();
+       if (keyfile == NULL)
                return;
 
        DBG("parsing main.conf");
 
-       boolean = g_key_file_get_boolean(config, "General",
+       boolean = g_key_file_get_boolean(keyfile, "General",
                                                "BackgroundScanning", &error);
        if (error == NULL)
                connman_settings.bg_scan = boolean;
+       else
+               g_clear_error(&error);
 
-       g_clear_error(&error);
+       g_key_file_free(keyfile);
 }
 
 static GMainLoop *main_loop = NULL;
@@ -243,7 +224,6 @@ int main(int argc, char *argv[])
        GError *error = NULL;
        DBusConnection *conn;
        DBusError err;
-       GKeyFile *config;
        guint signal;
 
 #ifdef HAVE_CAPNG
@@ -324,9 +304,7 @@ int main(int argc, char *argv[])
 
        __connman_dbus_init(conn);
 
-       config = load_config(CONFIGDIR "/main.conf");
-
-       parse_config(config);
+       parse_config();
 
        __connman_storage_migrate();
        __connman_technology_init();
@@ -416,9 +394,6 @@ int main(int argc, char *argv[])
 
        g_main_loop_unref(main_loop);
 
-       if (config)
-               g_key_file_free(config);
-
        g_free(option_debug);
 
        return 0;
diff --git a/src/storage.c b/src/storage.c
index 75a1b0b..e3278fb 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -33,6 +33,7 @@
 #include "connman.h"
 
 #define SETTINGS       "settings"
+#define MAINCONF       "main.conf"
 #define DEFAULT                "default.profile"
 
 #define MODE           (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
@@ -82,6 +83,22 @@ static void storage_delete(const char *pathname)
                connman_error("Failed to remove %s", pathname);
 }
 
+GKeyFile *__connman_storage_load_mainconf()
+{
+       gchar *pathname;
+       GKeyFile *keyfile = NULL;
+
+       pathname = g_strdup_printf("%s/%s", CONFIGDIR, MAINCONF);
+       if (pathname == NULL)
+               return NULL;
+
+       keyfile = storage_load(pathname);
+
+       g_free(pathname);
+
+       return keyfile;
+}
+
 GKeyFile *__connman_storage_load_global()
 {
        gchar *pathname;
-- 
1.7.5.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to