Handle errors with DBusPendingCall and lost connection
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 22 Apr 2009 15:27:11 +0000 (16:27 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 22 Apr 2009 15:27:11 +0000 (16:27 +0100)
plugins/bluetooth.c
plugins/modemmgr.c
plugins/supplicant.c

index 12519c5..009c6c7 100644 (file)
@@ -117,6 +117,13 @@ static void get_properties(DBusConnection *connection,
                return;
        }
 
                return;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               g_free(data);
+               return;
+       }
+
        data->connection = connection;
        data->message    = message;
        data->callback   = callback;
        data->connection = connection;
        data->message    = message;
        data->callback   = callback;
@@ -240,6 +247,12 @@ static int pan_connect(struct connman_network *network)
                return -EINVAL;
        }
 
                return -EINVAL;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EINVAL;
+       }
+
        dbus_pending_call_set_notify(call, connect_reply, network, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, connect_reply, network, NULL);
 
        dbus_message_unref(message);
@@ -307,6 +320,12 @@ static int pan_disconnect(struct connman_network *network)
                return -EINVAL;
        }
 
                return -EINVAL;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EINVAL;
+       }
+
        dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
 
        dbus_message_unref(message);
@@ -393,6 +412,12 @@ static int change_powered(DBusConnection *connection, const char *path,
                return -EINVAL;
        }
 
                return -EINVAL;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EINVAL;
+       }
+
        dbus_pending_call_set_notify(call, powered_reply, NULL, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, powered_reply, NULL, NULL);
 
        dbus_message_unref(message);
@@ -718,13 +743,18 @@ static void bluetooth_connect(DBusConnection *connection, void *user_data)
        if (dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT) == FALSE) {
                connman_error("Failed to get Bluetooth adapters");
        if (dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT) == FALSE) {
                connman_error("Failed to get Bluetooth adapters");
-               dbus_message_unref(message);
-               return;
+               goto done;
+       }
+
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               goto done;
        }
 
        dbus_pending_call_set_notify(call, list_adapters_reply,
                                                        connection, NULL);
 
        }
 
        dbus_pending_call_set_notify(call, list_adapters_reply,
                                                        connection, NULL);
 
+done:
        dbus_message_unref(message);
 }
 
        dbus_message_unref(message);
 }
 
index cbb5ebd..0950848 100644 (file)
@@ -65,13 +65,18 @@ static void modemmgr_connect(DBusConnection *connection, void *user_data)
        if (dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT) == FALSE) {
                connman_error("Failed to get modem devices");
        if (dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT) == FALSE) {
                connman_error("Failed to get modem devices");
-               dbus_message_unref(message);
-               return;
+               goto done;
+       }
+
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               goto done;
        }
 
        dbus_pending_call_set_notify(call, enumerate_devices_reply,
                                                        NULL, NULL);
 
        }
 
        dbus_pending_call_set_notify(call, enumerate_devices_reply,
                                                        NULL, NULL);
 
+done:
        dbus_message_unref(message);
 }
 
        dbus_message_unref(message);
 }
 
index 69ef372..fc57d35 100644 (file)
@@ -279,6 +279,12 @@ static int add_interface(struct supplicant_task *task)
                return -EIO;
        }
 
                return -EIO;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EIO;
+       }
+
        dbus_pending_call_set_notify(call, add_interface_reply, task, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, add_interface_reply, task, NULL);
 
        dbus_message_unref(message);
@@ -349,6 +355,12 @@ static int create_interface(struct supplicant_task *task)
                return -EIO;
        }
 
                return -EIO;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EIO;
+       }
+
        dbus_pending_call_set_notify(call, get_interface_reply, task, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, get_interface_reply, task, NULL);
 
        dbus_message_unref(message);
@@ -401,6 +413,12 @@ static int remove_interface(struct supplicant_task *task)
                return -EIO;
        }
 
                return -EIO;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EIO;
+       }
+
        dbus_pending_call_set_notify(call, remove_interface_reply, task, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, remove_interface_reply, task, NULL);
 
        dbus_message_unref(message);
@@ -1129,6 +1147,12 @@ static void get_properties(struct supplicant_task *task)
                goto noscan;
        }
 
                goto noscan;
        }
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               goto noscan;
+       }
+
        dbus_pending_call_set_notify(call, properties_reply, task, NULL);
 
        dbus_message_unref(message);
        dbus_pending_call_set_notify(call, properties_reply, task, NULL);
 
        dbus_message_unref(message);
@@ -1220,6 +1244,11 @@ static void scan_results_available(struct supplicant_task *task)
        if (task->noscan == FALSE)
                connman_device_set_scanning(task->device, TRUE);
 
        if (task->noscan == FALSE)
                connman_device_set_scanning(task->device, TRUE);
 
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               goto done;
+       }
+
        dbus_pending_call_set_notify(call, scan_results_reply, task, NULL);
 
 done:
        dbus_pending_call_set_notify(call, scan_results_reply, task, NULL);
 
 done: