diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-05-18 11:44:05 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-05-24 16:33:15 +0300 |
commit | 39c1cfe1013d5731f64407881ddf3dc16942063a (patch) | |
tree | a9f417efc2246bbea31cf6150357d292b37ed962 | |
parent | 52889168f73566d75d470e6dd8ca28d42ea90961 (diff) | |
download | connman-39c1cfe1013d5731f64407881ddf3dc16942063a.tar.gz connman-39c1cfe1013d5731f64407881ddf3dc16942063a.tar.bz2 connman-39c1cfe1013d5731f64407881ddf3dc16942063a.zip |
storage: Return any errors when saving services and global config
-rw-r--r-- | src/connman.h | 4 | ||||
-rw-r--r-- | src/storage.c | 26 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/connman.h b/src/connman.h index 7f998ebc..b501296e 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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); diff --git a/src/storage.c b/src/storage.c index 2faab757..e35a893e 100644 --- a/src/storage.c +++ b/src/storage.c @@ -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) |