[PATCH 3/4] Load ipconfig setting at function __connman_service_create_ipconfig()

martin.xu at intel.com martin.xu at intel.com
Sun Apr 11 23:35:05 PDT 2010


From: Martin Xu <martin.xu at intel.com>

ipconfig may not be created when creating service, so the ipconfig setting
has no chance to be loaded. Loading ipconfig setting at function
__connman_service_create_ipcofnig() can resolve the issue. Calling
connman_network_set_index() to create ipconfig, the ipconfig setting can be loaded.
---
 src/service.c |   67 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/src/service.c b/src/service.c
index e0e363e..b9b6b15 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2223,13 +2223,57 @@ static void setup_ipconfig(struct connman_service *service, int index)
 	connman_ipconfig_set_ops(service->ipconfig, &service_ops);
 }
 
+static GKeyFile *create_keyfile(const char *ident)
+{
+	GKeyFile *keyfile;
+	gchar *pathname, *data = NULL;
+	gsize length;
+
+	pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
+	if (pathname == NULL)
+		return NULL;
+
+	keyfile = g_key_file_new();
+
+	if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
+		g_free(pathname);
+		return NULL;
+	}
+
+	g_free(pathname);
+
+	if (g_key_file_load_from_data(keyfile, data, length,
+							0, NULL) == FALSE) {
+		g_free(data);
+		return NULL;
+	}
+
+	g_free(data);
+
+	return keyfile;
+}
+
 void __connman_service_create_ipconfig(struct connman_service *service,
 								int index)
 {
+	const char *ident = service->profile;
+	GKeyFile *keyfile;
+
 	if (service->ipconfig != NULL)
 		return;
 
 	setup_ipconfig(service, index);
+
+	if (ident == NULL)
+		return;
+
+	keyfile = create_keyfile(ident);
+	if (keyfile == NULL)
+		return;
+
+	__connman_ipconfig_load(service->ipconfig, keyfile,
+					service->identifier, "IPv4.");
+	g_key_file_free(keyfile);
 }
 
 /**
@@ -2580,8 +2624,6 @@ static int service_load(struct connman_service *service)
 	const char *ident = service->profile;
 	GKeyFile *keyfile;
 	GError *error = NULL;
-	gchar *pathname, *data = NULL;
-	gsize length;
 	gchar *str;
 	connman_bool_t autoconnect;
 	unsigned int ssid_len;
@@ -2592,26 +2634,9 @@ static int service_load(struct connman_service *service)
 	if (ident == NULL)
 		return -EINVAL;
 
-	pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
-	if (pathname == NULL)
-		return -ENOMEM;
-
-	keyfile = g_key_file_new();
-
-	if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
-		g_free(pathname);
+	keyfile = create_keyfile(ident);
+	if (keyfile == NULL)
 		return -ENOENT;
-	}
-
-	g_free(pathname);
-
-	if (g_key_file_load_from_data(keyfile, data, length,
-							0, NULL) == FALSE) {
-		g_free(data);
-		return -EILSEQ;
-	}
-
-	g_free(data);
 
 	switch (service->type) {
 	case CONNMAN_SERVICE_TYPE_UNKNOWN:
-- 
1.6.1.3




More information about the connman mailing list