From 3879bf3074ad4611027ea8022e1fd53022eda883 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 22 Apr 2009 16:27:11 +0100 Subject: [PATCH] Handle errors with DBusPendingCall and lost connection --- plugins/bluetooth.c | 34 ++++++++++++++++++++++++++++++++-- plugins/modemmgr.c | 9 +++++++-- plugins/supplicant.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index 12519c5..009c6c7 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -117,6 +117,13 @@ static void get_properties(DBusConnection *connection, 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; @@ -240,6 +247,12 @@ static int pan_connect(struct connman_network *network) 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); @@ -307,6 +320,12 @@ static int pan_disconnect(struct connman_network *network) 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); @@ -393,6 +412,12 @@ static int change_powered(DBusConnection *connection, const char *path, 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); @@ -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"); - 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); +done: dbus_message_unref(message); } diff --git a/plugins/modemmgr.c b/plugins/modemmgr.c index cbb5ebd..0950848 100644 --- a/plugins/modemmgr.c +++ b/plugins/modemmgr.c @@ -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"); - 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); +done: dbus_message_unref(message); } diff --git a/plugins/supplicant.c b/plugins/supplicant.c index 69ef372..fc57d35 100644 --- a/plugins/supplicant.c +++ b/plugins/supplicant.c @@ -279,6 +279,12 @@ static int add_interface(struct supplicant_task *task) 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); @@ -349,6 +355,12 @@ static int create_interface(struct supplicant_task *task) 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); @@ -401,6 +413,12 @@ static int remove_interface(struct supplicant_task *task) 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); @@ -1129,6 +1147,12 @@ static void get_properties(struct supplicant_task *task) 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); @@ -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 (call == NULL) { + connman_error("D-Bus connection not available"); + goto done; + } + dbus_pending_call_set_notify(call, scan_results_reply, task, NULL); done: -- 1.7.9.5