chiark / gitweb /
bus: update kdbus monitoring interface
authorKay Sievers <kay@vrfy.org>
Sun, 15 Dec 2013 15:56:28 +0000 (16:56 +0100)
committerKay Sievers <kay@vrfy.org>
Sun, 15 Dec 2013 15:56:28 +0000 (16:56 +0100)
src/libsystemd-bus/bus-kernel.c
src/libsystemd-bus/bus-kernel.h
src/libsystemd-bus/kdbus.h

index 650e6b9659d051348cc68565ab64b9e88921a008..0e473082382c1c3cc6683308dd4c65ff94232cdf 100644 (file)
@@ -1219,18 +1219,37 @@ int bus_kernel_create_namespace(const char *name, char **s) {
         return fd;
 }
 
         return fd;
 }
 
-int bus_kernel_monitor(sd_bus *bus) {
-        struct kdbus_cmd_monitor cmd_monitor;
-        int r;
+int bus_kernel_create_monitor(const char *bus) {
+        struct kdbus_cmd_hello *hello;
+        char *p;
+        int fd;
 
         assert(bus);
 
 
         assert(bus);
 
-        cmd_monitor.id = 0;
-        cmd_monitor.flags = KDBUS_MONITOR_ENABLE;
+        p = alloca(sizeof("/dev/kdbus/") - 1 + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + sizeof("/bus"));
+        sprintf(p, "/dev/kdbus/%lu-%s/bus", (unsigned long) getuid(), bus);
 
 
-        r = ioctl(bus->input_fd, KDBUS_CMD_MONITOR, &cmd_monitor);
-        if (r < 0)
+        fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
+        if (fd < 0)
                 return -errno;
 
                 return -errno;
 
-        return 1;
+        hello = alloca0(sizeof(struct kdbus_cmd_hello));
+        hello->size = sizeof(struct kdbus_cmd_hello);
+        hello->conn_flags = KDBUS_HELLO_ACTIVATOR;
+        hello->pool_size = KDBUS_POOL_SIZE;
+
+        if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0) {
+                close_nointr_nofail(fd);
+                return -errno;
+        }
+
+        /* The higher 32bit of both flags fields are considered
+         * 'incompatible flags'. Refuse them all for now. */
+        if (hello->bus_flags > 0xFFFFFFFFULL ||
+            hello->conn_flags > 0xFFFFFFFFULL) {
+                close_nointr_nofail(fd);
+                return -ENOTSUP;
+        }
+
+        return fd;
 }
 }
index c5d469c98bfd2421c09e69723ea6bdfb1f2ccbab..8c7eacc6d76207e2bfba83643619a834fdd4efd6 100644 (file)
@@ -63,6 +63,7 @@ int bus_kernel_read_message(sd_bus *bus);
 int bus_kernel_create_bus(const char *name, char **s);
 int bus_kernel_create_namespace(const char *name, char **s);
 int bus_kernel_create_starter(const char *bus, const char *name);
 int bus_kernel_create_bus(const char *name, char **s);
 int bus_kernel_create_namespace(const char *name, char **s);
 int bus_kernel_create_starter(const char *bus, const char *name);
+int bus_kernel_create_monitor(const char *bus);
 
 int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *size);
 void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t size);
 
 int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *size);
 void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t size);
@@ -73,5 +74,3 @@ int bus_kernel_parse_unique_name(const char *s, uint64_t *id);
 
 int kdbus_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
 int kdbus_translate_attach_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
 
 int kdbus_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
 int kdbus_translate_attach_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
-
-int bus_kernel_monitor(sd_bus *bus);
index dcd29359f5c11b0338a259e7973d7b1e32671dad..1ab72518a98cea02c02094554ee9468336a975fe 100644 (file)
@@ -414,14 +414,18 @@ struct kdbus_cmd_policy {
 
 /**
  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
 
 /**
  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
- * @KDBUS_HELLO_ACTIVATOR:             The connection registers a name for activation
- *                             by well-know name
  * @KDBUS_HELLO_ACCEPT_FD:     The connection allows the receiving of
  *                             any passed file descriptors
  * @KDBUS_HELLO_ACCEPT_FD:     The connection allows the receiving of
  *                             any passed file descriptors
+ * @KDBUS_HELLO_ACTIVATOR:     Special-purpose connection which registers
+ *                             a well-know name for a process to be started
+ *                             when traffic arrives
+ * @KDBUS_HELLO_MONITOR:       Special-purpose connection to monitor
+ *                             bus traffic
  */
 enum kdbus_hello_flags {
  */
 enum kdbus_hello_flags {
-       KDBUS_HELLO_ACTIVATOR           =  1 <<  0,
-       KDBUS_HELLO_ACCEPT_FD           =  1 <<  1,
+       KDBUS_HELLO_ACCEPT_FD           =  1 <<  0,
+       KDBUS_HELLO_ACTIVATOR           =  1 <<  1,
+       KDBUS_HELLO_MONITOR             =  1 <<  2,
 };
 
 /**
 };
 
 /**
@@ -698,27 +702,6 @@ struct kdbus_cmd_match {
        struct kdbus_item items[0];
 };
 
        struct kdbus_item items[0];
 };
 
-/**
- * enum kdbus_monitor_flags - flags for monitoring
- * @KDBUS_MONITOR_ENABLE:      Enable monitoring
- */
-enum kdbus_monitor_flags {
-       KDBUS_MONITOR_ENABLE            = 1 <<  0,
-};
-
-/**
- * struct kdbus_cmd_monitor - struct to enable or disable eavesdropping
- * @id:                        Privileged users may enable or disable the monitor feature
- *                     on behalf of other peers
- * @flags:             Use KDBUS_MONITOR_ENABLE to enable eavesdropping
- *
- * This structure is used with the KDBUS_CMD_MONITOR ioctl.
- */
-struct kdbus_cmd_monitor {
-       __u64 id;
-       __u64 flags;
-};
-
 /**
  * enum kdbus_ioctl_type - Ioctl API
  * @KDBUS_CMD_BUS_MAKE:                After opening the "control" device node, this
 /**
  * enum kdbus_ioctl_type - Ioctl API
  * @KDBUS_CMD_BUS_MAKE:                After opening the "control" device node, this
@@ -756,9 +739,6 @@ struct kdbus_cmd_monitor {
  * @KDBUS_CMD_MATCH_ADD:       Install a match which broadcast messages should
  *                             be delivered to the connection.
  * @KDBUS_CMD_MATCH_REMOVE:    Remove a current match for broadcast messages.
  * @KDBUS_CMD_MATCH_ADD:       Install a match which broadcast messages should
  *                             be delivered to the connection.
  * @KDBUS_CMD_MATCH_REMOVE:    Remove a current match for broadcast messages.
- * @KDBUS_CMD_MONITOR:         Monitor the bus and receive all transmitted
- *                             messages. Privileges are required for this
- *                             operation.
  * @KDBUS_CMD_EP_POLICY_SET:   Set the policy of an endpoint. It is used to
  *                             restrict the access for endpoints created with
  *                             KDBUS_CMD_EP_MAKE.
  * @KDBUS_CMD_EP_POLICY_SET:   Set the policy of an endpoint. It is used to
  *                             restrict the access for endpoints created with
  *                             KDBUS_CMD_EP_MAKE.
@@ -808,7 +788,6 @@ enum kdbus_ioctl_type {
 
        KDBUS_CMD_MATCH_ADD =           _IOW (KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
        KDBUS_CMD_MATCH_REMOVE =        _IOW (KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
 
        KDBUS_CMD_MATCH_ADD =           _IOW (KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
        KDBUS_CMD_MATCH_REMOVE =        _IOW (KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
-       KDBUS_CMD_MONITOR =             _IOW (KDBUS_IOC_MAGIC, 0x72, struct kdbus_cmd_monitor),
 
        KDBUS_CMD_EP_POLICY_SET =       _IOW (KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
 
 
        KDBUS_CMD_EP_POLICY_SET =       _IOW (KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),