We only return a reply to user that is trying to connect to VPN,
after the connection is established. Now all the user initiated
service or provider connect requests work the same way.
---
 src/connman.h  |    2 ++
 src/provider.c |   17 +++++++++++++++++
 src/service.c  |   21 +++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/src/connman.h b/src/connman.h
index ddf2491..12bcaba 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -625,6 +625,8 @@ int __connman_service_disconnect(struct connman_service 
*service);
 int __connman_service_disconnect_all(void);
 void __connman_service_auto_connect(void);
 gboolean __connman_service_remove(struct connman_service *service);
+void __connman_service_set_provider_pending(struct connman_service *service,
+                                                       DBusMessage *msg);
 void __connman_service_set_hidden_data(struct connman_service *service,
                                gpointer user_data);
 void __connman_service_return_error(struct connman_service *service,
diff --git a/src/provider.c b/src/provider.c
index 76e8478..62d8d9b 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -898,6 +898,7 @@ int __connman_provider_create_and_connect(DBusMessage *msg)
        char **networks = NULL;
        char *ident;
        int err, count = 0;
+       connman_bool_t connecting = FALSE;
 
        dbus_message_iter_init(msg, &iter);
        dbus_message_iter_recurse(&iter, &array);
@@ -1008,10 +1009,26 @@ int __connman_provider_create_and_connect(DBusMessage 
*msg)
 
                        if (err < 0 && err != -EINPROGRESS)
                                goto failed;
+
+                       if (err == -EINPROGRESS)
+                               connecting = TRUE;
                }
        }
 
        connman_provider_save(provider);
+
+       if (connecting == TRUE) {
+               /*
+                * Save the dbus message so that we can reply the
+                * caller when VPN connection is established.
+                */
+               dbus_message_ref(msg);
+
+               __connman_service_set_provider_pending(provider->vpn_service,
+                                                                       msg);
+               return 0;
+       }
+
        service_path = __connman_service_get_path(provider->vpn_service);
        g_dbus_send_reply(connection, msg,
                                DBUS_TYPE_OBJECT_PATH, &service_path,
diff --git a/src/service.c b/src/service.c
index 5fb2a5e..aa09329 100644
--- a/src/service.c
+++ b/src/service.c
@@ -105,6 +105,7 @@ struct connman_service {
        char *private_key_passphrase;
        char *phase2;
        DBusMessage *pending;
+       DBusMessage *provider_pending;
        guint timeout;
        struct connman_stats stats;
        struct connman_stats stats_roaming;
@@ -3466,6 +3467,26 @@ static void reply_pending(struct connman_service 
*service, int error)
                                                NULL);
                service->pending = NULL;
        }
+
+       if (service->provider_pending != NULL) {
+               __connman_service_reply_dbus_pending(service->provider_pending,
+                                               error, service->path);
+               service->provider_pending = NULL;
+       }
+}
+
+void __connman_service_set_provider_pending(struct connman_service *service,
+                                                       DBusMessage *msg)
+{
+       if (service->provider_pending != NULL) {
+               DBG("service %p provider pending msg %p already exists",
+                       service, service->provider_pending);
+
+               __connman_service_reply_dbus_pending(service->provider_pending,
+                                               ECONNABORTED, service->path);
+       }
+
+       service->provider_pending = msg;
 }
 
 static void check_pending_msg(struct connman_service *service)
-- 
1.7.9.5

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to