storage: Return any errors when saving services and global config
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 18 May 2012 08:44:05 +0000 (11:44 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 24 May 2012 13:33:15 +0000 (16:33 +0300)
src/connman.h
src/storage.c

index 7f998eb..b501296 100644 (file)
@@ -204,7 +204,7 @@ int __connman_resolver_redo_servers(const char *interface);
 void __connman_storage_migrate(void);
 GKeyFile *__connman_storage_open_global();
 GKeyFile *__connman_storage_load_global();
-void __connman_storage_save_global(GKeyFile *keyfile);
+int __connman_storage_save_global(GKeyFile *keyfile);
 void __connman_storage_delete_global();
 
 GKeyFile *__connman_storage_load_config(const char *ident);
@@ -212,7 +212,7 @@ void __connman_storage_save_config(GKeyFile *keyfile, const char *ident);
 void __connman_storage_delete_config(const char *ident);
 
 GKeyFile *__connman_storage_open_service(const char *ident);
-void __connman_storage_save_service(GKeyFile *keyfile, const char *ident);
+int __connman_storage_save_service(GKeyFile *keyfile, const char *ident);
 GKeyFile *__connman_storage_load_provider(const char *identifier);
 void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier);
 char **__connman_storage_get_providers(void);
index 2faab75..e35a893 100644 (file)
@@ -58,20 +58,24 @@ static GKeyFile *storage_load(const char *pathname)
        return keyfile;
 }
 
-static void storage_save(GKeyFile *keyfile, char *pathname)
+static int storage_save(GKeyFile *keyfile, char *pathname)
 {
        gchar *data = NULL;
        gsize length = 0;
        GError *error = NULL;
+       int ret = 0;
 
        data = g_key_file_to_data(keyfile, &length, NULL);
 
        if (!g_file_set_contents(pathname, data, length, &error)) {
                DBG("Failed to store information: %s", error->message);
                g_error_free(error);
+               ret = -EIO;
        }
 
        g_free(data);
+
+       return ret;
 }
 
 static void storage_delete(const char *pathname)
@@ -98,17 +102,20 @@ GKeyFile *__connman_storage_load_global()
        return keyfile;
 }
 
-void __connman_storage_save_global(GKeyFile *keyfile)
+int __connman_storage_save_global(GKeyFile *keyfile)
 {
        gchar *pathname;
+       int ret;
 
        pathname = g_strdup_printf("%s/%s", STORAGEDIR, SETTINGS);
        if(pathname == NULL)
-               return;
+               return -ENOMEM;
 
-       storage_save(keyfile, pathname);
+       ret = storage_save(keyfile, pathname);
 
        g_free(pathname);
+
+       return ret;
 }
 
 void __connman_storage_delete_global()
@@ -263,20 +270,21 @@ GKeyFile *connman_storage_load_service(const char *service_id)
        return keyfile;
 }
 
-void __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
+int __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
 {
+       int ret = 0;
        gchar *pathname, *dirname;
 
        dirname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
        if(dirname == NULL)
-               return;
+               return -ENOMEM;
 
        /* If the dir doesn't exist, create it */
        if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
                if(mkdir(dirname, MODE) < 0) {
                        if (errno != EEXIST) {
                                g_free(dirname);
-                               return;
+                               return -errno;
                        }
                }
        }
@@ -285,9 +293,11 @@ void __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
 
        g_free(dirname);
 
-       storage_save(keyfile, pathname);
+       ret = storage_save(keyfile, pathname);
 
        g_free(pathname);
+
+       return ret;
 }
 
 GKeyFile *__connman_storage_load_provider(const char *identifier)