chiark / gitweb /
journald: correct spacing near eol code comments
[elogind.git] / src / libsystemd / sd-bus / bus-kernel.c
index 98fd4fd3ec60a72841ab70c17fa3bac948eb1524..2978b0a2844c8dca699b96b2b88c3d877f3f5ac4 100644 (file)
@@ -294,8 +294,8 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
         memzero(m->kdbus, sz);
 
         m->kdbus->flags =
-                ((m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) ? 0 : KDBUS_MSG_FLAGS_EXPECT_REPLY) |
-                ((m->header->flags & BUS_MESSAGE_NO_AUTO_START) ? KDBUS_MSG_FLAGS_NO_AUTO_START : 0);
+                ((m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) ? 0 : KDBUS_MSG_EXPECT_REPLY) |
+                ((m->header->flags & BUS_MESSAGE_NO_AUTO_START) ? KDBUS_MSG_NO_AUTO_START : 0);
 
         if (well_known)
                 /* verify_destination_id will usually be 0, which makes the kernel driver only look
@@ -553,22 +553,17 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
 
                 case KDBUS_ITEM_PIDS:
 
-                        /* The PID starttime/TID might be missing,
-                         * when the data is faked by some data bus
-                         * proxy and it lacks that information about
-                         * the real client since SO_PEERCRED is used
-                         * for that. */
+                        /* The PID/TID might be missing, when the data
+                         * is faked by some data bus proxy and it
+                         * lacks that information about the real
+                         * client since SO_PEERCRED is used for
+                         * that. */
 
                         if (d->pids.pid > 0) {
                                 m->creds.pid = (pid_t) d->pids.pid;
                                 m->creds.mask |= SD_BUS_CREDS_PID & bus->creds_mask;
                         }
 
-                        if (d->pids.starttime > 0) {
-                                m->creds.pid_starttime = d->pids.starttime / NSEC_PER_USEC;
-                                m->creds.mask |= SD_BUS_CREDS_PID_STARTTIME & bus->creds_mask;
-                        }
-
                         if (d->pids.tid > 0) {
                                 m->creds.tid = (pid_t) d->pids.tid;
                                 m->creds.mask |= SD_BUS_CREDS_TID & bus->creds_mask;
@@ -766,7 +761,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         }
 
         /* Refuse messages where the reply flag doesn't match up */
-        if (!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) != !!(k->flags & KDBUS_MSG_FLAGS_EXPECT_REPLY)) {
+        if (!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) != !!(k->flags & KDBUS_MSG_EXPECT_REPLY)) {
                 r = -EBADMSG;
                 goto fail;
         }
@@ -778,7 +773,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         }
 
         /* Refuse messages where the autostart flag doesn't match up */
-        if (!(m->header->flags & BUS_MESSAGE_NO_AUTO_START) != !(k->flags & KDBUS_MSG_FLAGS_NO_AUTO_START)) {
+        if (!(m->header->flags & BUS_MESSAGE_NO_AUTO_START) != !(k->flags & KDBUS_MSG_NO_AUTO_START)) {
                 r = -EBADMSG;
                 goto fail;
         }
@@ -1017,6 +1012,7 @@ static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
 }
 
 int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call) {
+        struct kdbus_cmd_send cmd = { };
         int r;
 
         assert(bus);
@@ -1032,15 +1028,20 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
         if (r < 0)
                 return r;
 
+        cmd.size = sizeof(cmd);
+        cmd.msg_address = (uintptr_t)m->kdbus;
+
         /* If this is a synchronous method call, then let's tell the
          * kernel, so that it can pass CPU time/scheduling to the
          * destination for the time, if it wants to. If we
          * synchronously wait for the result anyway, we won't need CPU
          * anyway. */
-        if (hint_sync_call)
-                m->kdbus->flags |= KDBUS_MSG_FLAGS_EXPECT_REPLY|KDBUS_MSG_FLAGS_SYNC_REPLY;
+        if (hint_sync_call) {
+                m->kdbus->flags |= KDBUS_MSG_EXPECT_REPLY;
+                cmd.flags |= KDBUS_SEND_SYNC_REPLY;
+        }
 
-        r = ioctl(bus->output_fd, KDBUS_CMD_MSG_SEND, m->kdbus);
+        r = ioctl(bus->output_fd, KDBUS_CMD_SEND, &cmd);
         if (r < 0) {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                 sd_bus_message *reply;
@@ -1090,7 +1091,7 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
         } else if (hint_sync_call) {
                 struct kdbus_msg *k;
 
-                k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + m->kdbus->offset_reply);
+                k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + cmd.reply.offset);
                 assert(k);
 
                 if (k->payload_type == KDBUS_PAYLOAD_DBUS) {
@@ -1251,7 +1252,7 @@ static int bus_kernel_translate_message(sd_bus *bus, struct kdbus_msg *k) {
 }
 
 int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority) {
-        struct kdbus_cmd_recv recv = {};
+        struct kdbus_cmd_recv recv = { .size = sizeof(recv) };
         struct kdbus_msg *k;
         int r;
 
@@ -1266,7 +1267,7 @@ int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority) {
                 recv.priority = priority;
         }
 
-        r = ioctl(bus->input_fd, KDBUS_CMD_MSG_RECV, &recv);
+        r = ioctl(bus->input_fd, KDBUS_CMD_RECV, &recv);
         if (r < 0) {
                 if (errno == EAGAIN)
                         return 0;
@@ -1279,7 +1280,7 @@ int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority) {
                 return -errno;
         }
 
-        k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + recv.offset);
+        k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + recv.reply.offset);
         if (k->payload_type == KDBUS_PAYLOAD_DBUS) {
                 r = bus_kernel_make_message(bus, k);
 
@@ -1421,7 +1422,7 @@ uint64_t attach_flags_to_kdbus(uint64_t mask) {
                     SD_BUS_CREDS_GID|SD_BUS_CREDS_EGID|SD_BUS_CREDS_SGID|SD_BUS_CREDS_FSGID))
                 m |= KDBUS_ATTACH_CREDS;
 
-        if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID))
+        if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID))
                 m |= KDBUS_ATTACH_PIDS;
 
         if (mask & SD_BUS_CREDS_COMM)
@@ -1803,12 +1804,13 @@ int bus_kernel_try_close(sd_bus *bus) {
 
 int bus_kernel_drop_one(int fd) {
         struct kdbus_cmd_recv recv = {
-                .flags = KDBUS_RECV_DROP
+                .size = sizeof(recv),
+                .flags = KDBUS_RECV_DROP,
         };
 
         assert(fd >= 0);
 
-        if (ioctl(fd, KDBUS_CMD_MSG_RECV, &recv) < 0)
+        if (ioctl(fd, KDBUS_CMD_RECV, &recv) < 0)
                 return -errno;
 
         return 0;
@@ -1869,7 +1871,7 @@ int bus_kernel_fix_attach_mask(void) {
         r = write_string_file("/sys/module/kdbus/parameters/attach_flags_mask", buf);
         if (r < 0)
                 return log_full_errno(
-                                r == -EROFS ? LOG_DEBUG : LOG_WARNING, r,
+                                IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r,
                                 "Failed to write kdbus attach mask: %m");
 
         return 0;