Merge changes I795ea4d7,I4871ee62
[platform/upstream/dbus.git] / dbus / dbus-transport-kdbus.c
index 6eabd17..902116d 100644 (file)
@@ -136,6 +136,17 @@ __u64 dbus_transport_get_bloom_size(DBusTransport* transport)
 }
 
 /**
+ *  Gets pointer to the memory pool, wher received messages are
+ *  placed and some ioctls return their info
+ *  @param transport transport
+ *  @returns pointer to the pool
+ */
+void* dbus_transport_get_pool_pointer(DBusTransport* transport)
+{
+  return ((DBusTransportKdbus*)transport)->kdbus_mmap_ptr;
+}
+
+/**
  * Puts locally generated message into received messages queue
  * @param message message that will be added
  * @param connection connection to which message will be added
@@ -274,24 +285,24 @@ static struct kdbus_msg* kdbus_init_msg(const char* name, __u64 dst_id, uint64_t
     msg_size = sizeof(struct kdbus_msg);
 
     if(use_memfd == TRUE)  // bulk data - memfd
-        msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_memfd));
+        msg_size += KDBUS_PART_SIZE(sizeof(struct kdbus_memfd));
     else
       {
-        msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));  //header is a must
+        msg_size += KDBUS_PART_SIZE(sizeof(struct kdbus_vec));  //header is a must
         while(body_size > KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE)
           {
-            msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
+            msg_size += KDBUS_PART_SIZE(sizeof(struct kdbus_vec));
             body_size -= KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE;
           }
         if(body_size)
-          msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
+          msg_size += KDBUS_PART_SIZE(sizeof(struct kdbus_vec));
       }
 
     if(fds_count)
-       msg_size += KDBUS_ITEM_SIZE(sizeof(int)*fds_count);
+       msg_size += KDBUS_PART_SIZE(sizeof(int)*fds_count);
 
     if (name)
-       msg_size += KDBUS_ITEM_SIZE(strlen(name) + 1);
+       msg_size += KDBUS_PART_SIZE(strlen(name) + 1);
     else if (dst_id == KDBUS_DST_ID_BROADCAST)
        msg_size += KDBUS_PART_HEADER_SIZE + transport->bloom_size;
 
@@ -304,7 +315,7 @@ static struct kdbus_msg* kdbus_init_msg(const char* name, __u64 dst_id, uint64_t
 
     memset(msg, 0, msg_size);
     msg->size = msg_size;
-    msg->payload_type = KDBUS_PAYLOAD_DBUS1;
+    msg->payload_type = KDBUS_PAYLOAD_DBUS;
     msg->dst_id = name ? 0 : dst_id;
     msg->src_id = strtoull(dbus_bus_get_unique_name(transport->base.connection), NULL , 10);
 
@@ -507,6 +518,7 @@ static int kdbus_write_msg(DBusTransportKdbus *transport, DBusMessage *message,
 static dbus_bool_t bus_register_kdbus(char* name, DBusTransportKdbus* transportS)
 {
        struct kdbus_cmd_hello __attribute__ ((__aligned__(8))) hello;
+       memset(&hello, 0, sizeof(hello));
 
        hello.conn_flags = KDBUS_HELLO_ACCEPT_FD/* |
                           KDBUS_HELLO_ATTACH_COMM |
@@ -567,9 +579,10 @@ static int capture_hello_message(DBusTransport *transport, const char* destinati
               strcpy(name, ":1.");
               if(!bus_register_kdbus(&name[3], (DBusTransportKdbus*)transport))
                 goto out;
+#ifdef POLICY_TO_KDBUS
               if(!register_kdbus_policy(&name[3], transport, geteuid()))
                 goto out;
-
+#endif
               ((DBusTransportKdbus*)transport)->sender = name;
 
               if(!reply_1_data(message, DBUS_TYPE_STRING, &name, transport->connection))
@@ -645,8 +658,7 @@ LOOKUP(MSG);
 const char *enum_PAYLOAD(long long id);
 TABLE(PAYLOAD) = {
        ENUM(KDBUS_PAYLOAD_KERNEL),
-       ENUM(KDBUS_PAYLOAD_DBUS1),
-       ENUM(KDBUS_PAYLOAD_GVARIANT),
+       ENUM(KDBUS_PAYLOAD_DBUS),
 };
 LOOKUP(PAYLOAD);
 
@@ -920,10 +932,11 @@ static int kdbus_decode_msg(const struct kdbus_msg* msg, char *data, DBusTranspo
                        break;
 
                        case KDBUS_ITEM_NAME_ADD:
-                               _dbus_verbose("  +%s (%llu bytes) '%s', old id=%lld, new id=%lld, flags=0x%llx\n",
+                               _dbus_verbose("  +%s (%llu bytes) '%s', old id=%lld, new id=%lld, old flags=0x%llx, new flags=0x%llx\n",
                                        enum_MSG(item->type), (unsigned long long) item->size,
                                        item->name_change.name, item->name_change.old_id,
-                                       item->name_change.new_id, item->name_change.flags);
+                                       item->name_change.new_id, item->name_change.old_flags,
+                                       item->name_change.new_flags);
 
                                message = dbus_message_new_signal(DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameOwnerChanged");
                                if(message == NULL)
@@ -945,10 +958,11 @@ static int kdbus_decode_msg(const struct kdbus_msg* msg, char *data, DBusTranspo
                        break;
 
                        case KDBUS_ITEM_NAME_REMOVE:
-                               _dbus_verbose("  +%s (%llu bytes) '%s', old id=%lld, new id=%lld, flags=0x%llx\n",
+                               _dbus_verbose("  +%s (%llu bytes) '%s', old id=%lld, new id=%lld, old flags=0x%llx, new flags=0x%llx\n",
                                        enum_MSG(item->type), (unsigned long long) item->size,
                                        item->name_change.name, item->name_change.old_id,
-                                       item->name_change.new_id, item->name_change.flags);
+                                       item->name_change.new_id, item->name_change.old_flags,
+                                       item->name_change.new_flags);
 
                                message = dbus_message_new_signal(DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameOwnerChanged"); // name of the signal
                                if(message == NULL)
@@ -970,10 +984,11 @@ static int kdbus_decode_msg(const struct kdbus_msg* msg, char *data, DBusTranspo
                        break;
 
                        case KDBUS_ITEM_NAME_CHANGE:
-                               _dbus_verbose("  +%s (%llu bytes) '%s', old id=%lld, new id=%lld, flags=0x%llx\n",
+                               _dbus_verbose("  +%s (%llu bytes) '%s', old id=%lld, new id=%lld, old flags=0x%llx, new flags=0x%llx\n",
                                        enum_MSG(item->type), (unsigned long long) item->size,
                                        item->name_change.name, item->name_change.old_id,
-                                       item->name_change.new_id, item->name_change.flags);
+                                       item->name_change.new_id, item->name_change.old_flags,
+                                       item->name_change.new_flags);
 
                                message = dbus_message_new_signal(DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameOwnerChanged");
                                if(message == NULL)