Added description label to libdbuspolicy kdbus connection 40/85540/1
authorKazimierz Krosman <k.krosman@samsung.com>
Thu, 25 Aug 2016 15:48:16 +0000 (17:48 +0200)
committerKazimierz Krosman <k.krosman@samsung.com>
Thu, 25 Aug 2016 15:48:16 +0000 (17:48 +0200)
Change-Id: I3c17aa33ea71f9eab6cd2bd161500b1363804389

src/libdbuspolicy1.c

index e1e9216..bce1ed5 100644 (file)
@@ -44,6 +44,8 @@
 #define SYSTEM_BUS   0
 #define SESSION_BUS  1
 
+#define CONNECTION_LABEL "libdbuspolicy1-kdbus"
+
 #define ALIGN8(l) (((l) + 7) & ~7)
 #define ALIGNDN8(l) ((l) & ~7)
 #define UID_INVALID ((uid_t) -1)
@@ -78,27 +80,39 @@ static int kdbus_open_bus(const char *path)
 
 static int kdbus_hello(bool bus_type, uint64_t hello_flags, uint64_t attach_flags_send, uint64_t attach_flags_recv)
 {
-       struct kdbus_cmd_hello cmd;
+       struct kdbus_cmd_hello* cmd;
        struct kdbus_cmd_free cmd_free;
+       volatile struct kdbus_item* item;
        int fd = g_conn[bus_type].fd;
-
-       cmd.size = sizeof(cmd);
-       cmd.flags = hello_flags;
-       cmd.attach_flags_send = attach_flags_send;
-       cmd.attach_flags_recv = attach_flags_recv;
-       cmd.pool_size = KDBUS_POOL_SIZE;
-
-       if (ioctl(fd, KDBUS_CMD_HELLO, &cmd) < 0)
-               return -errno;
-
-       g_conn[bus_type].id = cmd.id;
+       int size = ALIGN8(sizeof(struct kdbus_cmd_hello)) + ALIGN8(offsetof(struct kdbus_item, data) + sizeof(CONNECTION_LABEL));
+
+       cmd = calloc(1, size);
+       cmd->size = size;
+       cmd->flags = hello_flags;
+       cmd->attach_flags_send = attach_flags_send;
+       cmd->attach_flags_recv = attach_flags_recv;
+       cmd->pool_size = KDBUS_POOL_SIZE;
+
+       item = cmd->items;
+       item->size = offsetof(struct kdbus_item, data) + sizeof(CONNECTION_LABEL);
+       item->type = KDBUS_ITEM_CONN_DESCRIPTION;
+       memcpy (item->str, CONNECTION_LABEL, sizeof(CONNECTION_LABEL));
+       if (ioctl(fd, KDBUS_CMD_HELLO, cmd) < 0)
+               goto err;
+
+       g_conn[bus_type].id = cmd->id;
        if (MAP_FAILED == (g_conn[bus_type].pool = mmap(NULL, KDBUS_POOL_SIZE, PROT_READ, MAP_SHARED, fd, 0)))
-               return -errno;
+               goto err;
 
-       cmd_free.offset = cmd.offset;
+       cmd_free.offset = cmd->offset;
        cmd_free.size = sizeof(struct kdbus_cmd_free);
        ioctl(g_conn[bus_type].fd, KDBUS_CMD_FREE, &cmd_free);
+       free(cmd);
        return 0;
+
+err:
+       free(cmd);
+       return -errno;
 }
 
 static bool kdbus_is_unique_id(const char* name)