Fix bug to remove vpn services when turning offline mode on
authorMohamed Abbas <mohamed.abbas@intel.com>
Wed, 22 Sep 2010 11:35:35 +0000 (04:35 -0700)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 22 Sep 2010 15:23:30 +0000 (17:23 +0200)
This patch will remove all vpn services on offline mode. It also
make sure it exits after releasing all resources.

Fixes BMC #6591

plugins/openconnect.c
src/provider.c

index 11377c3..2ddb904 100644 (file)
@@ -121,8 +121,6 @@ static void openconnect_died(struct connman_task *task, void *user_data)
        kill_tun(data->if_name);
        connman_provider_set_data(provider, NULL);
        connman_rtnl_remove_watch(data->watch);
-       connman_provider_unref(data->provider);
-       g_free(data);
 
  oc_exit:
        if (state != OC_STATE_READY && state != OC_STATE_DISCONNECT)
@@ -133,6 +131,9 @@ static void openconnect_died(struct connman_task *task, void *user_data)
                                                CONNMAN_PROVIDER_STATE_IDLE);
 
        connman_provider_set_index(provider, -1);
+       connman_provider_unref(data->provider);
+       g_free(data);
+
        connman_task_destroy(task);
 }
 
index b011778..b7dc9e9 100644 (file)
@@ -165,7 +165,8 @@ int __connman_provider_disconnect(struct connman_provider *provider)
        else
                return -EOPNOTSUPP;
 
-       __connman_service_indicate_state(provider->vpn_service,
+       if (provider->vpn_service != NULL)
+               __connman_service_indicate_state(provider->vpn_service,
                                        CONNMAN_SERVICE_STATE_DISCONNECT);
        if (err < 0) {
                if (err != -EINPROGRESS)
@@ -333,10 +334,12 @@ int connman_provider_set_state(struct connman_provider *provider,
 static void unregister_provider(gpointer data)
 {
        struct connman_provider *provider = data;
+       struct connman_service *service = provider->vpn_service;
 
        DBG("provider %p", provider);
 
-       __connman_service_put(provider->vpn_service);
+       provider->vpn_service = NULL;
+       __connman_service_put(service);
 
        connman_element_unregister(&provider->element);
        connman_provider_unref(provider);
@@ -537,7 +540,8 @@ int __connman_provider_create_and_connect(DBusMessage *msg)
        if (created == TRUE)
                provider_probe(provider);
 
-       provider->vpn_service =
+       if (provider->vpn_service == NULL)
+               provider->vpn_service =
                        __connman_service_create_from_provider(provider);
        if (provider->vpn_service == NULL) {
                err = -EOPNOTSUPP;
@@ -559,8 +563,10 @@ failed:
                DBG("can not connect delete provider");
                connman_provider_unref(provider);
 
-               if (provider->vpn_service != NULL)
+               if (provider->vpn_service != NULL) {
                        __connman_service_put(provider->vpn_service);
+                       provider->vpn_service = NULL;
+               }
        }
 
        return err;
@@ -640,6 +646,9 @@ void connman_provider_set_index(struct connman_provider *provider, int index)
 
        DBG("");
 
+       if (service == NULL)
+               return;
+
        ipconfig = __connman_service_get_ipconfig(service);
 
        if (ipconfig == NULL) {
@@ -694,12 +703,12 @@ void connman_provider_driver_unregister(struct connman_provider_driver *driver)
        driver_list = g_slist_remove(driver_list, driver);
 }
 
-static void provider_disconnect(gpointer key, gpointer value,
+static void provider_remove(gpointer key, gpointer value,
                                                gpointer user_data)
 {
        struct connman_provider *provider = value;
 
-       __connman_provider_disconnect(provider);
+       g_hash_table_remove(provider_hash, provider->identifier);
 }
 
 static void provider_offline_mode(connman_bool_t enabled)
@@ -707,7 +716,7 @@ static void provider_offline_mode(connman_bool_t enabled)
        DBG("enabled %d", enabled);
 
        if (enabled == TRUE)
-               g_hash_table_foreach(provider_hash, provider_disconnect, NULL);
+               g_hash_table_foreach(provider_hash, provider_remove, NULL);
 
 }