chiark / gitweb /
ptyfwd: Set the size of the PTY base on the size of stdout, not stdin.
[elogind.git] / src / libsystemd-bus / bus-kernel.c
index 495d7e57dc596b97ac5cf77b2ed9384ea8329f93..f66cf04e1640c759705fa942741ccdc0ff830b82 100644 (file)
@@ -254,7 +254,7 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
         m->kdbus->dst_id =
                 well_known ? 0 :
                 m->destination ? unique : KDBUS_DST_ID_BROADCAST;
-        m->kdbus->payload_type = KDBUS_PAYLOAD_DBUS1;
+        m->kdbus->payload_type = KDBUS_PAYLOAD_DBUS;
         m->kdbus->cookie = m->header->serial;
 
         m->kdbus->timeout_ns = m->timeout * NSEC_PER_USEC;
@@ -362,6 +362,7 @@ int bus_kernel_take_fd(sd_bus *b) {
         b->is_kernel = true;
         b->bus_client = true;
         b->can_fds = !!(hello.conn_flags & KDBUS_HELLO_ACCEPT_FD);
+        b->message_version = 2;
 
         /* the kernel told us the UUID of the underlying bus */
         memcpy(b->server_id.bytes, hello.id128, sizeof(b->server_id.bytes));
@@ -417,8 +418,10 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m) {
 
                         if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
                                 sd_bus_error_setf(&error, SD_BUS_ERROR_SERVICE_UNKNOWN, "Destination %s not known", m->destination);
-                        else
+                        else {
+                                log_debug("Could not deliver message to %s as destination is not known. Ignoring.", m->destination);
                                 return 0;
+                        }
 
                 } else if (errno == EADDRNOTAVAIL) {
 
@@ -426,8 +429,10 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m) {
 
                         if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
                                 sd_bus_error_setf(&error, SD_BUS_ERROR_SERVICE_UNKNOWN, "Activation of %s not requested", m->destination);
-                        else
+                        else {
+                                log_debug("Could not deliver message to %s as destination is not activated. Ignoring.", m->destination);
                                 return 0;
+                        }
                 } else
                         return -errno;
 
@@ -618,7 +623,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
 
         assert(bus);
         assert(k);
-        assert(k->payload_type == KDBUS_PAYLOAD_DBUS1);
+        assert(k->payload_type == KDBUS_PAYLOAD_DBUS);
 
         KDBUS_ITEM_FOREACH(d, k, items) {
                 size_t l;
@@ -676,6 +681,12 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         if (n_bytes != total)
                 return -EBADMSG;
 
+        /* on kdbus we only speak native endian gvariant, never dbus1
+         * marshalling or reverse endian */
+        if (h->version != 2 ||
+            h->endian != BUS_NATIVE_ENDIAN)
+                return -EPROTOTYPE;
+
         r = bus_message_from_header(bus, h, sizeof(struct bus_header), fds, n_fds, NULL, seclabel, 0, &m);
         if (r < 0)
                 return r;
@@ -885,9 +896,16 @@ int bus_kernel_read_message(sd_bus *bus) {
         }
         k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + off);
 
-        if (k->payload_type == KDBUS_PAYLOAD_DBUS1)
+        if (k->payload_type == KDBUS_PAYLOAD_DBUS) {
                 r = bus_kernel_make_message(bus, k);
-        else if (k->payload_type == KDBUS_PAYLOAD_KERNEL)
+
+                /* Anybody can send us invalid messages, let's just drop them. */
+                if (r == -EBADMSG || r == -EPROTOTYPE) {
+                        log_debug("Ignoring invalid message: %s", strerror(-r));
+                        r = 0;
+                }
+
+        } else if (k->payload_type == KDBUS_PAYLOAD_KERNEL)
                 r = bus_kernel_translate_message(bus, k);
         else
                 r = 0;
@@ -1197,3 +1215,19 @@ int bus_kernel_create_namespace(const char *name, char **s) {
 
         return fd;
 }
+
+int bus_kernel_monitor(sd_bus *bus) {
+        struct kdbus_cmd_monitor cmd_monitor;
+        int r;
+
+        assert(bus);
+
+        cmd_monitor.id = 0;
+        cmd_monitor.flags = KDBUS_MONITOR_ENABLE;
+
+        r = ioctl(bus->input_fd, KDBUS_CMD_MONITOR, &cmd_monitor);
+        if (r < 0)
+                return -errno;
+
+        return 1;
+}