vpn-plugin: Check completion of configure and connect
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 10 Dec 2012 10:42:05 +0000 (12:42 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 10 Dec 2012 11:01:10 +0000 (13:01 +0200)
When creating a configuration, wait until both configuration and
connection has been done. Otherwise NULL user data is passed to the
callback which then cannot relay an error to the caller and the caller will
get a timeout waiting for a reply from D-Bus.

plugins/vpn.c

index 65a4853da2ce89d16ad995ad4bf2dbae1dba6bf1..2f3d86074a5894cd45b831f1aeb68b4bc702be7a 100644 (file)
@@ -1243,8 +1243,8 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
 
        data = g_hash_table_lookup(vpn_connections, ident);
        if (data != NULL) {
-               if (data->call != NULL) {
-                       connman_error("Dbus call already pending");
+               if (data->call != NULL || data->cb_data != NULL) {
+                       DBG("create configuration call already pending");
                        err = -EINPROGRESS;
                        goto done;
                }
@@ -1274,6 +1274,18 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
        dbus_message_set_sender(new_msg, me);
        dbus_message_set_member(new_msg, "Create");
 
+       user_data = g_try_new0(struct config_create_data, 1);
+       if (user_data == NULL) {
+               err = -ENOMEM;
+               goto done;
+       }
+
+       user_data->callback = callback;
+       user_data->message = dbus_message_ref(msg);
+       user_data->path = NULL;
+
+       DBG("cb %p msg %p", user_data, msg);
+
        result = dbus_connection_send_with_reply(connection, new_msg,
                                                &call, DBUS_TIMEOUT);
        if (result == FALSE || call == NULL) {
@@ -1281,20 +1293,6 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
                goto done;
        }
 
-       if (data->cb_data == NULL) {
-               user_data = g_try_new(struct config_create_data, 1);
-               if (user_data != NULL) {
-                       user_data->callback = callback;
-                       user_data->message = dbus_message_ref(msg);
-                       user_data->path = NULL;
-
-                       DBG("cb %p msg %p", user_data, msg);
-               }
-       } else {
-               DBG("Configuration callback data already pending, "
-                       "discarding new data.");
-       }
-
        dbus_pending_call_set_notify(call, configuration_create_reply,
                                                        user_data, NULL);
        data->call = call;