From 10566194f57f8a207c483fed65802cb24ae57a12 Mon Sep 17 00:00:00 2001 From: Lukasz Skalski Date: Wed, 22 Oct 2014 12:23:59 +0000 Subject: [PATCH] [kdbus] Add support for 'ReleaseName' on kdbus --- gio/gkdbus.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gio/gkdbus.h | 4 ++++ 2 files changed, 73 insertions(+) diff --git a/gio/gkdbus.c b/gio/gkdbus.c index b96bc68..03c2d8e 100644 --- a/gio/gkdbus.c +++ b/gio/gkdbus.c @@ -702,6 +702,75 @@ _g_kdbus_RequestName (GDBusConnection *connection, } +/* + * _g_kdbus_ReleaseName: + * + */ +GVariant * +_g_kdbus_ReleaseName (GDBusConnection *connection, + const gchar *name, + GError **error) +{ + GKdbus *kdbus; + GVariant *result; + struct kdbus_cmd_name *kdbus_name; + gssize len, size; + gint status, ret; + + status = G_BUS_RELEASE_NAME_REPLY_RELEASED; + + kdbus = _g_kdbus_connection_get_kdbus (G_KDBUS_CONNECTION (g_dbus_connection_get_stream (connection))); + if (kdbus == NULL) + { + g_set_error_literal (error, + G_DBUS_ERROR, + G_DBUS_ERROR_IO_ERROR, + _("The connection is closed")); + return NULL; + } + + if (!g_dbus_is_name (name)) + { + g_set_error (error, + G_DBUS_ERROR, + G_DBUS_ERROR_INVALID_ARGS, + "Given bus name \"%s\" is not valid", name); + return NULL; + } + + if (*name == ':') + { + g_set_error (error, + G_DBUS_ERROR, + G_DBUS_ERROR_INVALID_ARGS, + "Cannot release a service starting with ':' such as \"%s\"", name); + return NULL; + } + + len = strlen(name) + 1; + size = G_STRUCT_OFFSET (struct kdbus_cmd_name, items) + KDBUS_ITEM_SIZE(len); + kdbus_name = g_alloca0 (size); + kdbus_name->items[0].size = KDBUS_ITEM_HEADER_SIZE + len; + kdbus_name->items[0].type = KDBUS_ITEM_NAME; + memcpy (kdbus_name->items[0].str, name, len); + + ret = ioctl(kdbus->priv->fd, KDBUS_CMD_NAME_RELEASE, kdbus_name); + if (ret < 0) + { + if (errno == ESRCH) + status = G_BUS_RELEASE_NAME_REPLY_NON_EXISTENT; + else if (errno == EADDRINUSE) + status = G_BUS_RELEASE_NAME_REPLY_NOT_OWNER; + else + return FALSE; + } + + result = g_variant_new ("(u)", status); + + return result; +} + + /** * _g_kdbus_GetBusId: * diff --git a/gio/gkdbus.h b/gio/gkdbus.h index 7fac97b..b449cc6 100644 --- a/gio/gkdbus.h +++ b/gio/gkdbus.h @@ -81,6 +81,10 @@ GVariant * _g_kdbus_RequestName (GDB GBusNameOwnerFlags flags, GError **error); +GVariant * _g_kdbus_ReleaseName (GDBusConnection *connection, + const gchar *name, + GError **error); + GVariant * _g_kdbus_GetListNames (GDBusConnection *connection, guint flags, GError **error); -- 2.7.4