From 413eb0b8f7185e736d228736274e940d8f578c3d Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Mon, 28 Feb 2011 10:43:53 -0300 Subject: [PATCH] location-reporting: don't add client-exit watch too early Wait until driver gives us a file descriptor to start watching for client exit. This fixes a race when client exits before the driver calls location_reporting_enable_cb(). --- src/location-reporting.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/location-reporting.c b/src/location-reporting.c index 6ab09147..f19ccf5d 100644 --- a/src/location-reporting.c +++ b/src/location-reporting.c @@ -170,13 +170,12 @@ static void location_reporting_enable_cb(const struct ofono_error *error, int fd, void *data) { struct ofono_location_reporting *lr = data; + DBusConnection *conn = ofono_dbus_get_connection(); DBusMessage *reply; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { ofono_error("Enabling location-reporting failed"); - client_remove(lr); - reply = __ofono_error_failed(lr->pending); __ofono_dbus_pending_reply(&lr->pending, reply); @@ -184,6 +183,9 @@ static void location_reporting_enable_cb(const struct ofono_error *error, } lr->enabled = TRUE; + lr->client_owner = g_strdup(dbus_message_get_sender(lr->pending)); + lr->disconnect_watch = g_dbus_add_disconnect_watch(conn, + lr->client_owner, client_exited, lr, NULL); reply = dbus_message_new_method_return(lr->pending); dbus_message_append_args(reply, DBUS_TYPE_UNIX_FD, &fd, @@ -198,7 +200,6 @@ static DBusMessage *location_reporting_request(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_location_reporting *lr = data; - const char *caller = dbus_message_get_sender(msg); if (lr->pending != NULL) return __ofono_error_busy(msg); @@ -206,9 +207,6 @@ static DBusMessage *location_reporting_request(DBusConnection *conn, if (lr->enabled) return __ofono_error_in_use(msg); - lr->client_owner = g_strdup(caller); - lr->disconnect_watch = g_dbus_add_disconnect_watch(conn, - lr->client_owner, client_exited, lr, NULL); lr->pending = dbus_message_ref(msg); lr->driver->enable(lr, location_reporting_enable_cb, lr);