summaryrefslogtreecommitdiff
path: root/src/service.c
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2012-06-05 11:24:09 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-06-11 13:03:06 +0300
commita43818bdc307dbc80f306562ba43df17d38a98e3 (patch)
treeb3840c658b3178a5a27667e21d5c318879f29d25 /src/service.c
parent309230b1cc7b01332f7a5f8aab3f330d09ee42a1 (diff)
downloadconnman-a43818bdc307dbc80f306562ba43df17d38a98e3.tar.gz
connman-a43818bdc307dbc80f306562ba43df17d38a98e3.tar.bz2
connman-a43818bdc307dbc80f306562ba43df17d38a98e3.zip
service: Remove unprovisioned services when starting connman
Diffstat (limited to 'src/service.c')
-rw-r--r--src/service.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/service.c b/src/service.c
index 8f9db427..99d441a5 100644
--- a/src/service.c
+++ b/src/service.c
@@ -6214,6 +6214,66 @@ __connman_service_create_from_provider(struct connman_provider *provider)
return service;
}
+static void remove_unprovisioned_services()
+{
+ gchar **services;
+ GKeyFile *keyfile, *configkeyfile;
+ char *file, *section;
+ int i = 0;
+
+ services = connman_storage_get_services();
+ if (services == NULL)
+ return;
+
+ for (;services[i] != NULL; i++) {
+ file = section = NULL;
+ keyfile = configkeyfile = NULL;
+
+ keyfile = connman_storage_load_service(services[i]);
+ if (keyfile == NULL)
+ continue;
+
+ file = g_key_file_get_string(keyfile, services[i],
+ "Config.file", NULL);
+ if (file == NULL)
+ goto next;
+
+ section = g_key_file_get_string(keyfile, services[i],
+ "Config.ident", NULL);
+ if (section == NULL)
+ goto next;
+
+ configkeyfile = __connman_storage_load_config(file);
+ if (configkeyfile == NULL) {
+ /*
+ * Config file is missing, remove the provisioned
+ * service.
+ */
+ __connman_storage_remove_service(services[i]);
+ goto next;
+ }
+
+ if (g_key_file_has_group(configkeyfile, section) == FALSE)
+ /*
+ * Config section is missing, remove the provisioned
+ * service.
+ */
+ __connman_storage_remove_service(services[i]);
+
+ next:
+ if (keyfile != NULL)
+ g_key_file_free(keyfile);
+
+ if (configkeyfile != NULL)
+ g_key_file_free(configkeyfile);
+
+ g_free(section);
+ g_free(file);
+ }
+
+ g_strfreev(services);
+}
+
int __connman_service_init(void)
{
DBG("");
@@ -6230,6 +6290,8 @@ int __connman_service_init(void)
g_str_equal, g_free, NULL);
services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
+ remove_unprovisioned_services();
+
return 0;
}