diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-01-19 20:21:51 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-01-19 20:21:51 +0000 |
commit | 2a01a5f6eb1b238b74f0ac9d3adfd2952f6f0ea1 (patch) | |
tree | cf3c82405484fd191311747bc80ad98f7ee5600f /hcid | |
parent | 8e0a966c57f17e914ebf614e0fb11526496a03c8 (diff) |
Fix ActivateService to return the right response if a service is already running
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-manager.c | 31 | ||||
-rw-r--r-- | hcid/dbus-service.c | 4 | ||||
-rw-r--r-- | hcid/dbus-service.h | 2 |
3 files changed, 24 insertions, 13 deletions
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 21587575..94609cc5 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -199,22 +199,23 @@ static DBusHandlerResult find_service(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - const char *pattern, *path; + const char *pattern; + struct service *service; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - path = search_service(conn, pattern); - if (!path) + service = search_service(conn, pattern); + if (!service) return error_no_such_service(conn, msg); reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_STRING, &path, + dbus_message_append_args(reply, DBUS_TYPE_STRING, &service->object_path, DBUS_TYPE_INVALID); return send_message_and_unref(conn, reply); @@ -248,7 +249,7 @@ static DBusHandlerResult list_services(DBusConnection *conn, static DBusHandlerResult activate_service(DBusConnection *conn, DBusMessage *msg, void *data) { - const char *pattern, *path; + const char *pattern; struct service *service; if (!dbus_message_get_args(msg, NULL, @@ -256,13 +257,23 @@ static DBusHandlerResult activate_service(DBusConnection *conn, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - path = search_service(conn, pattern); - if (!path) + service = search_service(conn, pattern); + if (!service) return error_no_such_service(conn, msg); - if (!dbus_connection_get_object_path_data(conn, path, - (void *) &service)) - return error_no_such_service(conn, msg); + if (service->bus_name) { + DBusMessage *reply; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &service->object_path, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); + } if (service_start(service, conn) < 0) return error_failed(conn, msg, ENOEXEC); diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 08b39d87..db643edf 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -858,7 +858,7 @@ void release_services(DBusConnection *conn) services = NULL; } -const char *search_service(DBusConnection *conn, const char *pattern) +struct service *search_service(DBusConnection *conn, const char *pattern) { GSList *l; @@ -866,7 +866,7 @@ const char *search_service(DBusConnection *conn, const char *pattern) struct service *service = l->data; if (service->ident && !strcmp(service->ident, pattern)) - return service->object_path; + return service; } return NULL; diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h index d01278fa..f4e3d313 100644 --- a/hcid/dbus-service.h +++ b/hcid/dbus-service.h @@ -70,7 +70,7 @@ void release_services(DBusConnection *conn); void append_available_services(DBusMessageIter *iter); -const char *search_service(DBusConnection *conn, const char *pattern); +struct service *search_service(DBusConnection *conn, const char *pattern); int register_service_records(GSList *lrecords); |