}
if (item->size > KDBUS_ITEM_HEADER_SIZE +
- KDBUS_MAKE_MAX_LEN + 1) {
+ KDBUS_SYSNAME_MAX_LEN + 1) {
ret = -ENAMETOOLONG;
goto exit;
}
goto exit;
}
- ret = kdbus_devname_valid(item->str);
+ ret = kdbus_sysname_is_valid(item->str);
if (ret < 0)
goto exit;
bsize = item->data64[0];
break;
-
- default:
- ret = -ENOTSUPP;
- goto exit;
}
}
#include "namespace.h"
#include "notify.h"
#include "policy.h"
+#include "util.h"
/**
* struct kdbus_conn_queue - messages waiting to be read
kdbus_match_db_free(conn->match_db);
kdbus_pool_free(conn->pool);
kdbus_ep_unref(conn->ep);
+ kfree(conn->name);
kfree(conn);
}
struct kdbus_bus *bus = ep->bus;
const struct kdbus_item *item;
const char *activator_name = NULL;
+ const char *conn_name = NULL;
const struct kdbus_creds *creds = NULL;
const char *seclabel = NULL;
size_t seclabel_len = 0;
if (activator_name)
return -EINVAL;
+
+ if (!kdbus_validate_nul(item->str,
+ item->size - KDBUS_ITEM_HEADER_SIZE))
+ return -EINVAL;
+
+ if (!kdbus_name_is_valid(item->str))
+ return -EINVAL;
+
activator_name = item->str;
break;
if (!kdbus_bus_uid_is_privileged(bus))
return -EPERM;
+ if (!kdbus_validate_nul(item->str,
+ item->size - KDBUS_ITEM_HEADER_SIZE))
+ return -EINVAL;
+
+ if (!kdbus_name_is_valid(item->str))
+ return -EINVAL;
+
seclabel = item->str;
seclabel_len = item->size - KDBUS_ITEM_HEADER_SIZE;
break;
+
+ case KDBUS_ITEM_CONN_NAME:
+ /* human-readable connection name (debugging) */
+ if (conn_name)
+ return -EINVAL;
+
+ if (item->size > KDBUS_SYSNAME_MAX_LEN +
+ KDBUS_ITEM_HEADER_SIZE + 1)
+ return -ENAMETOOLONG;
+
+ if (!kdbus_validate_nul(item->str,
+ item->size - KDBUS_ITEM_HEADER_SIZE))
+ return -EINVAL;
+
+ ret = kdbus_sysname_is_valid(item->str);
+ if (ret < 0)
+ return ret;
+
+ conn_name = item->str;
+ break;
}
}
if (!conn)
return -ENOMEM;
+ if (conn_name) {
+ conn->name = kstrdup(conn_name, GFP_KERNEL);
+ if (!conn->name) {
+ kfree(conn);
+ return -ENOMEM;
+ }
+ }
+
kref_init(&conn->kref);
mutex_init(&conn->lock);
INIT_LIST_HEAD(&conn->msg_list);
/* init entry, so we can unconditionally remove it */
INIT_LIST_HEAD(&conn->monitor_entry);
- ret = kdbus_pool_new(&conn->pool, hello->pool_size);
+ ret = kdbus_pool_new(conn->name, hello->pool_size, &conn->pool);
if (ret < 0)
goto exit_unref;
* struct kdbus_conn - connection to a bus
* @kref: Reference count
* @disconnected: Invalidated data
+ * @name: Human-readable connection name, used for debugging
* @ep: The endpoint this connection belongs to
* @id: Connection ID
* @flags: KDBUS_HELLO_* flags
struct kdbus_conn {
struct kref kref;
bool disconnected;
+ const char *name;
struct kdbus_ep *ep;
u64 id;
u64 flags;
#define KDBUS_NAME_MAX_LEN 255
/* maximum length of bus, ns, ep name */
-#define KDBUS_MAKE_MAX_LEN 63
+#define KDBUS_SYSNAME_MAX_LEN 63
/* maximum size of make data */
#define KDBUS_MAKE_MAX_SIZE SZ_32K
}
if (item->size > KDBUS_ITEM_HEADER_SIZE +
- KDBUS_MAKE_MAX_LEN + 1) {
+ KDBUS_SYSNAME_MAX_LEN + 1) {
ret = -ENAMETOOLONG;
goto exit;
}
goto exit;
}
- ret = kdbus_devname_valid(item->str);
+ ret = kdbus_sysname_is_valid(item->str);
if (ret < 0)
goto exit;
n = item->str;
continue;
-
- default:
- ret = -ENOTSUPP;
- goto exit;
}
}
#include <linux/sizes.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
+#include <linux/syscalls.h>
#include "bus.h"
#include "connection.h"
* The higher 32bit are considered 'incompatible
* flags'. Refuse them all for now.
*/
- return kernel_flags <= 0xFFFFFFFFULL;
+ return kernel_flags <= 0xffffffffULL;
+}
+
+static int kdbus_handle_memfd(void __user *buf)
+{
+ u64 size;
+ struct kdbus_cmd_memfd_make *m = NULL;
+ const struct kdbus_item *item;
+ const char *n = NULL;
+ int fd;
+ int __user *addr;
+ int ret;
+
+ if (!KDBUS_IS_ALIGNED8((uintptr_t)buf))
+ return -EFAULT;
+
+ if (kdbus_size_get_user(&size, buf, struct kdbus_cmd_conn_info))
+ return -EFAULT;
+
+ if (size < sizeof(struct kdbus_cmd_memfd_make))
+ return -EINVAL;
+
+ if (size > sizeof(struct kdbus_cmd_memfd_make) + KDBUS_MAKE_MAX_SIZE)
+ return -EMSGSIZE;
+
+ m = memdup_user(buf, size);
+ if (IS_ERR(m))
+ return PTR_ERR(m);
+
+ KDBUS_ITEM_FOREACH(item, m, items) {
+ if (!KDBUS_ITEM_VALID(item, m)) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ switch (item->type) {
+ case KDBUS_ITEM_MEMFD_NAME:
+ if (n) {
+ ret = -EEXIST;
+ goto exit;
+ }
+
+ if (item->size < KDBUS_ITEM_HEADER_SIZE + 2) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ if (item->size > KDBUS_ITEM_HEADER_SIZE +
+ KDBUS_SYSNAME_MAX_LEN + 1) {
+ ret = -ENAMETOOLONG;
+ goto exit;
+ }
+
+ if (!kdbus_validate_nul(item->str,
+ item->size - KDBUS_ITEM_HEADER_SIZE)) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ ret = kdbus_sysname_is_valid(item->str);
+ if (ret < 0)
+ goto exit;
+
+ n = item->str;
+ break;
+ }
+ }
+
+ if (!KDBUS_ITEM_END(item, m)) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ ret = kdbus_memfd_new(n, m->file_size, &fd);
+ if (ret < 0)
+ goto exit;
+
+ /* return fd number to caller */
+ addr = buf + offsetof(struct kdbus_cmd_memfd_make, fd);
+ if (put_user(fd, addr)) {
+ sys_close(fd);
+ ret = -EFAULT;
+ goto exit;
+ }
+
+exit:
+ kfree(m);
+ return ret;
}
/* kdbus control device commands */
break;
}
- case KDBUS_CMD_MEMFD_NEW: {
- int fd;
- int __user *addr = buf;
-
- ret = kdbus_memfd_new(&fd);
- if (ret < 0)
- break;
-
- if (put_user(fd, addr))
- ret = -EFAULT;
+ case KDBUS_CMD_MEMFD_NEW:
+ ret = kdbus_handle_memfd(buf);
break;
- }
default:
ret = -ENOTTY;
break;
}
- kfree(make);
return ret;
}
ret = kdbus_conn_src_msg(conn, buf);
break;
- case KDBUS_CMD_MEMFD_NEW: {
- int fd;
- int __user *addr = buf;
-
- ret = kdbus_memfd_new(&fd);
- if (ret < 0)
- break;
-
- if (put_user(fd, addr))
- ret = -EFAULT;
+ case KDBUS_CMD_MEMFD_NEW:
+ ret = kdbus_handle_memfd(buf);
break;
- }
default:
ret = -ENOTTY;
* struct kdbus_memfd - a kdbus memfd
* @size: The memfd's size
* @fd: The file descriptor number
- * @__pad: Padding to make the struct aligned
+ * @__pad: Padding to ensure proper alignement and size
*
* Attached to:
* KDBUS_ITEM_PAYLOAD_MEMFD
* @KDBUS_ITEM_BLOOM_SIZE: Desired bloom size, used by KDBUS_CMD_BUS_MAKE
* @KDBUS_ITEM_DST_NAME: Destination's well-known name
* @KDBUS_ITEM_MAKE_NAME: Name of namespace, bus, endpoint
+ * @KDBUS_ITEM_MEMFD_NAME: The human readable name of a memfd (debugging)
* @_KDBUS_ITEM_POLICY_BASE: Start of policy items
* @KDBUS_ITEM_POLICY_NAME: Policy in struct kdbus_policy
* @KDBUS_ITEM_POLICY_ACCESS: Policy in struct kdbus_policy
* @KDBUS_ITEM_CAPS: The process capabilities
* @KDBUS_ITEM_SECLABEL: The security label
* @KDBUS_ITEM_AUDIT: The audit IDs
+ * @KDBUS_ITEM_CONN_NAME: The connection's human-readable name (debugging)
* @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items
* @KDBUS_ITEM_NAME_ADD: Notify in struct kdbus_notify_name_change
* @KDBUS_ITEM_NAME_REMOVE: Notify in struct kdbus_notify_name_change
KDBUS_ITEM_BLOOM_SIZE,
KDBUS_ITEM_DST_NAME,
KDBUS_ITEM_MAKE_NAME,
+ KDBUS_ITEM_MEMFD_NAME,
- _KDBUS_ITEM_POLICY_BASE = 0x400,
+ _KDBUS_ITEM_POLICY_BASE = 0x1000,
KDBUS_ITEM_POLICY_NAME = _KDBUS_ITEM_POLICY_BASE,
KDBUS_ITEM_POLICY_ACCESS,
- _KDBUS_ITEM_ATTACH_BASE = 0x600,
+ _KDBUS_ITEM_ATTACH_BASE = 0x2000,
KDBUS_ITEM_NAME = _KDBUS_ITEM_ATTACH_BASE,
KDBUS_ITEM_ID,
KDBUS_ITEM_TIMESTAMP,
KDBUS_ITEM_CAPS,
KDBUS_ITEM_SECLABEL,
KDBUS_ITEM_AUDIT,
+ KDBUS_ITEM_CONN_NAME,
- _KDBUS_ITEM_KERNEL_BASE = 0x800,
+ _KDBUS_ITEM_KERNEL_BASE = 0x3000,
KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE,
KDBUS_ITEM_NAME_REMOVE,
KDBUS_ITEM_NAME_CHANGE,
* @payload_type: Payload type (KDBUS_PAYLOAD_*)
* @cookie: Userspace-supplied cookie, for the connection
* to identify its messages
- * @cookie_reply: A reply to the requesting message with the same
- * cookie. The requesting connection can match its
- * request and the reply with this value
* @timeout_ns: The time to wait for a message reply from the peer.
* If there is no reply, a kernel-generated message
* with an attached KDBUS_ITEM_REPLY_TIMEOUT item
* is sent to @src_id.
+ * @cookie_reply: A reply to the requesting message with the same
+ * cookie. The requesting connection can match its
+ * request and the reply with this value
* @items: A list of kdbus_items containing the message payload
*/
struct kdbus_msg {
__u64 payload_type;
__u64 cookie;
union {
- __u64 cookie_reply;
__u64 timeout_ns;
+ __u64 cookie_reply;
};
struct kdbus_item items[0];
} __attribute__((aligned(8)));
* @KDBUS_ATTACH_CAPS: The process capabilities
* @KDBUS_ATTACH_SECLABEL: The security label
* @KDBUS_ATTACH_AUDIT: The audit IDs
+ * @KDBUS_ATTACH_CONN_NAME: The human-readable connection name
*/
enum kdbus_attach_flags {
KDBUS_ATTACH_TIMESTAMP = 1 << 0,
KDBUS_ATTACH_CAPS = 1 << 7,
KDBUS_ATTACH_SECLABEL = 1 << 8,
KDBUS_ATTACH_AUDIT = 1 << 9,
+ KDBUS_ATTACH_CONN_NAME = 1 << 10,
};
/**
struct kdbus_item items[0];
} __attribute__((aligned(8)));
+/**
+ * struct kdbus_cmd_memfd_make - create a kdbus memfd
+ * @size: The total size of the struct
+ * @file_size: The initial file size
+ * @fd: The returned file descriptor number
+ * @__pad: Padding to ensure proper alignement
+ * @items: A list of items for additional information
+ *
+ * This structure is used with the KDBUS_CMD_MEMFD_NEW ioctl.
+ */
+struct kdbus_cmd_memfd_make {
+ __u64 size;
+ __u64 file_size;
+ int fd;
+ __u32 __pad;
+ struct kdbus_item items[0];
+} __attribute__((aligned(8)));
+
/**
* enum kdbus_ioctl_type - Ioctl API
* @KDBUS_CMD_BUS_MAKE: After opening the "control" device node, this
* pool.
* @KDBUS_CMD_DROP: Drop and free the next queued message and all
* its ressources without actually receiveing it.
- * @KDBUS_CMD_SRC: Return the sender's connection ID of the next
- * queued message.
+ * @KDBUS_CMD_SRC: Query the sender's connection ID of the next
+ * queued message, used to determine the activating
+ * connection of a bus name.
* @KDBUS_CMD_NAME_ACQUIRE: Request a well-known bus name to associate with
* the connection. Well-known names are used to
* address a peer on the bus.
KDBUS_CMD_EP_POLICY_SET = _IOW (KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
- KDBUS_CMD_MEMFD_NEW = _IOR (KDBUS_IOC_MAGIC, 0x90, int *),
- KDBUS_CMD_MEMFD_SIZE_GET = _IOR (KDBUS_IOC_MAGIC, 0x91, __u64 *),
- KDBUS_CMD_MEMFD_SIZE_SET = _IOW (KDBUS_IOC_MAGIC, 0x92, __u64 *),
- KDBUS_CMD_MEMFD_SEAL_GET = _IOR (KDBUS_IOC_MAGIC, 0x93, int *),
- KDBUS_CMD_MEMFD_SEAL_SET = _IO (KDBUS_IOC_MAGIC, 0x94),
+ KDBUS_CMD_MEMFD_NEW = _IOWR(KDBUS_IOC_MAGIC, 0xc0, struct kdbus_cmd_memfd_make),
+ KDBUS_CMD_MEMFD_SIZE_GET = _IOR (KDBUS_IOC_MAGIC, 0xc1, __u64 *),
+ KDBUS_CMD_MEMFD_SIZE_SET = _IOW (KDBUS_IOC_MAGIC, 0xc2, __u64 *),
+ KDBUS_CMD_MEMFD_SEAL_GET = _IOR (KDBUS_IOC_MAGIC, 0xc3, int *),
+ KDBUS_CMD_MEMFD_SEAL_SET = _IO (KDBUS_IOC_MAGIC, 0xc4),
};
/*
/**
* struct kdbus_memfile - protectable shared memory file
- * @sealed: Flag if the content is writable
+ * @name: Name of the (deleted) file which shows up in
+ * /proc, used for debugging
* @lock: Locking
* @fp: Shared memory backing file
+ * @sealed: Flag if the content is writable
*/
struct kdbus_memfile {
- bool sealed;
+ const char *name;
struct mutex lock;
struct file *fp;
+ bool sealed;
};
/**
/**
* kdbus_memfd_new() - create and install a memfd and file descriptor
- * @fd: installed file descriptor
+ * @name: Name of the (deleted) file which shows up in
+ * /proc, used for debugging
+ * @size: Initial size of the file
+ * @fd: Installed file descriptor
*
* Returns: 0 on success, negative errno on failure.
*/
-int kdbus_memfd_new(int *fd)
+int kdbus_memfd_new(const char *name, size_t size, int *fd)
{
struct kdbus_memfile *mf;
+ const char *shmem_name = NULL;
+ const char *anon_name = NULL;
struct file *shmemfp;
struct file *fp;
int f;
mutex_init(&mf->lock);
+ if (name) {
+ mf->name = kstrdup(name, GFP_KERNEL);
+ shmem_name = kasprintf(GFP_KERNEL, KBUILD_MODNAME "-memfd:%s", name);
+ anon_name = kasprintf(GFP_KERNEL, "[" KBUILD_MODNAME "-memfd:%s]", name);
+ if (!mf->name || !shmem_name || !anon_name) {
+ ret = -ENOMEM;
+ goto exit;
+ }
+ }
+
/* allocate a new unlinked shmem file */
- shmemfp = shmem_file_setup(KBUILD_MODNAME "-memfd", 0, 0);
+ shmemfp = shmem_file_setup(name ? shmem_name : KBUILD_MODNAME "-memfd",
+ size, 0);
if (IS_ERR(shmemfp)) {
ret = PTR_ERR(shmemfp);
goto exit;
* invisible shmem inode. We rely on the fact that nothing else
* can create a new file for the shmem inode, like by opening the
* fd in /proc/$PID/fd/ */
- fp = anon_inode_getfile("[" KBUILD_MODNAME "-memfd]",
+ fp = anon_inode_getfile(name ? anon_name : "[" KBUILD_MODNAME "-memfd]",
&kdbus_memfd_fops, mf, O_RDWR);
if (IS_ERR(fp)) {
ret = PTR_ERR(fp);
fp->f_mapping = shmemfp->f_mapping;
fd_install(f, fp);
+ kfree(anon_name);
+ kfree(shmem_name);
*fd = f;
return 0;
exit_shmem:
fput(shmemfp);
exit:
+ kfree(anon_name);
+ kfree(shmem_name);
+ kfree(mf->name);
kfree(mf);
return ret;
}
struct kdbus_memfile *mf = file->private_data;
fput(mf->fp);
+ kfree(mf->name);
kfree(mf);
return 0;
}
bool kdbus_is_memfd(const struct file *fp);
bool kdbus_is_memfd_sealed(const struct file *fp);
u64 kdbus_memfd_size(const struct file *fp);
-int kdbus_memfd_new(int *fd);
+int kdbus_memfd_new(const char *name, size_t size, int *fd);
#endif
kmsg->dst_name = item->str;
break;
-
- default:
- return -ENOTSUPP;
}
}
#define __KDBUS_MESSAGE_H
#include "util.h"
-#include "namespace.h"
#include "metadata.h"
/**
goto exit;
}
#endif
+
+ if (which & KDBUS_ATTACH_CONN_NAME &&
+ !(meta->attached & KDBUS_ATTACH_CONN_NAME)) {
+ ret = kdbus_meta_append_str(meta, KDBUS_ITEM_CONN_NAME,
+ conn->name);
+ if (ret < 0)
+ goto exit;
+ }
+
/*
* We tried to add everything we got asked for; do not get
* here again for the same question.
#ifndef __KDBUS_METADATA_H
#define __KDBUS_METADATA_H
-#include "message.h"
-
/**
* struct kdbus_meta - metadata buffer
* @attached: Flags for already attached data
goto exit;
}
- if (payload_size > KDBUS_MAKE_MAX_LEN + 1) {
+ if (payload_size > KDBUS_SYSNAME_MAX_LEN + 1) {
ret = -ENAMETOOLONG;
goto exit;
}
goto exit;
}
- ret = kdbus_devname_valid(item->str);
+ ret = kdbus_sysname_is_valid(item->str);
if (ret < 0)
goto exit;
n = item->str;
continue;
-
- default:
- ret = -ENOTSUPP;
- goto exit;
}
}
/**
* kdbus_pool_new() - create a new pool
- * @pool: Newly allocated pool
+ * @name: Name of the (deleted) file which shows up in
+ * /proc, used for debugging
* @size: Maximum size of the pool
+ * @pool: Newly allocated pool
*
* Returns: 0 on success, negative errno on failure.
*/
-int kdbus_pool_new(struct kdbus_pool **pool, size_t size)
+int kdbus_pool_new(const char *name, size_t size, struct kdbus_pool **pool)
{
struct kdbus_pool *p;
struct file *f;
if (!p)
return -ENOMEM;
- f = shmem_file_setup(KBUILD_MODNAME "-pool", size, 0);
+ if (name) {
+ char *n;
+
+ n = kasprintf(GFP_KERNEL, KBUILD_MODNAME "-conn:%s", name);
+ if (!n) {
+ ret = -ENOMEM;
+ goto exit_free;
+ }
+ f = shmem_file_setup(n, size, 0);
+ kfree(n);
+ } else {
+ f = shmem_file_setup(KBUILD_MODNAME "-conn", size, 0);
+ }
if (IS_ERR(f)) {
ret = PTR_ERR(f);
- goto exit_free_p;
+ goto exit_free;
}
/* allocate first slice spanning the entire pool */
exit_put_shmem:
fput(f);
-exit_free_p:
+exit_free:
kfree(p);
return ret;
}
struct kdbus_pool;
-int kdbus_pool_new(struct kdbus_pool **pool, size_t size);
+int kdbus_pool_new(const char *name, size_t size, struct kdbus_pool **pool);
void kdbus_pool_free(struct kdbus_pool *pool);
int kdbus_pool_alloc_range(struct kdbus_pool *pool, size_t size, size_t *off);
ENUM(KDBUS_ITEM_CAPS),
ENUM(KDBUS_ITEM_SECLABEL),
ENUM(KDBUS_ITEM_AUDIT),
+ ENUM(KDBUS_ITEM_CONN_NAME),
ENUM(KDBUS_ITEM_NAME),
ENUM(KDBUS_ITEM_TIMESTAMP),
ENUM(KDBUS_ITEM_NAME_ADD),
struct conn *connect_to_bus(const char *path, uint64_t hello_flags)
{
int fd, ret;
- struct kdbus_cmd_hello hello;
+ struct {
+ struct kdbus_cmd_hello hello;
+ uint64_t size;
+ uint64_t type;
+ char comm[16];
+ } h;
struct conn *conn;
- memset(&hello, 0, sizeof(hello));
+ memset(&h, 0, sizeof(h));
printf("-- opening bus connection %s\n", path);
fd = open(path, O_RDWR|O_CLOEXEC);
return NULL;
}
- hello.conn_flags = hello_flags | KDBUS_HELLO_ACCEPT_FD;
+ h.hello.conn_flags = hello_flags | KDBUS_HELLO_ACCEPT_FD;
- hello.attach_flags = KDBUS_ATTACH_TIMESTAMP |
+ h.hello.attach_flags = KDBUS_ATTACH_TIMESTAMP |
KDBUS_ATTACH_CREDS |
KDBUS_ATTACH_NAMES |
KDBUS_ATTACH_COMM |
KDBUS_ATTACH_CAPS |
KDBUS_ATTACH_CGROUP |
KDBUS_ATTACH_SECLABEL |
- KDBUS_ATTACH_AUDIT;
+ KDBUS_ATTACH_AUDIT |
+ KDBUS_ATTACH_CONN_NAME;
+
+ h.type = KDBUS_ITEM_CONN_NAME;
+ h.size = KDBUS_ITEM_HEADER_SIZE + sizeof(h.comm);
+ strcpy(h.comm, "this-is-my-name");
- hello.size = sizeof(struct kdbus_cmd_hello);
- hello.pool_size = POOL_SIZE;
+ h.hello.size = sizeof(h);
+ h.hello.pool_size = POOL_SIZE;
- ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
+ ret = ioctl(fd, KDBUS_CMD_HELLO, &h.hello);
if (ret < 0) {
fprintf(stderr, "--- error when saying hello: %d (%m)\n", ret);
return NULL;
}
printf("-- Our peer ID for %s: %llu -- bus uuid: '%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'\n",
- path, (unsigned long long)hello.id,
- hello.id128[0], hello.id128[1], hello.id128[2], hello.id128[3],
- hello.id128[4], hello.id128[5], hello.id128[6], hello.id128[7],
- hello.id128[8], hello.id128[9], hello.id128[10], hello.id128[11],
- hello.id128[12], hello.id128[13], hello.id128[14], hello.id128[15]);
+ path, (unsigned long long)h.hello.id,
+ h.hello.id128[0], h.hello.id128[1], h.hello.id128[2], h.hello.id128[3],
+ h.hello.id128[4], h.hello.id128[5], h.hello.id128[6], h.hello.id128[7],
+ h.hello.id128[8], h.hello.id128[9], h.hello.id128[10], h.hello.id128[11],
+ h.hello.id128[12], h.hello.id128[13], h.hello.id128[14], h.hello.id128[15]);
conn = malloc(sizeof(*conn));
if (!conn) {
}
conn->fd = fd;
- conn->id = hello.id;
+ conn->id = h.hello.id;
return conn;
}
if (dst_id == KDBUS_DST_ID_BROADCAST)
size += KDBUS_ITEM_HEADER_SIZE + 64;
else {
- ret = ioctl(conn->fd, KDBUS_CMD_MEMFD_NEW, &memfd);
+ struct {
+ struct kdbus_cmd_memfd_make cmd;
+ uint64_t size;
+ uint64_t type;
+ char name[16];
+ } m = {};
+
+ m.cmd.size = sizeof(m);
+ m.cmd.file_size = 1024 * 1024;
+ m.cmd.items[0].type = KDBUS_ITEM_MEMFD_NAME;
+ m.cmd.items[0].size = KDBUS_ITEM_HEADER_SIZE + sizeof(m.name);
+ strcpy(m.name, "my-name-is-nice");
+ ret = ioctl(conn->fd, KDBUS_CMD_MEMFD_NEW, &m);
if (ret < 0) {
fprintf(stderr, "KDBUS_CMD_MEMFD_NEW failed: %m\n");
return EXIT_FAILURE;
}
+ memfd = m.cmd.fd;
if (write(memfd, "kdbus memfd 1234567", 19) != 19) {
fprintf(stderr, "writing to memfd failed: %m\n");
case KDBUS_ITEM_CGROUP:
case KDBUS_ITEM_SECLABEL:
case KDBUS_ITEM_DST_NAME:
+ case KDBUS_ITEM_CONN_NAME:
printf(" +%s (%llu bytes) '%s' (%zu)\n",
enum_MSG(item->type), item->size, item->str, strlen(item->str));
break;
send_echo_request(struct conn *conn, uint64_t dst_id)
{
struct kdbus_msg *msg;
+ struct kdbus_cmd_memfd_make mfd = {};
struct kdbus_item *item;
uint64_t size;
int memfd = -1;
size = sizeof(struct kdbus_msg);
size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
- ret = ioctl(conn->fd, KDBUS_CMD_MEMFD_NEW, &memfd);
+ mfd.size = sizeof(struct kdbus_cmd_memfd_make);
+ ret = ioctl(conn->fd, KDBUS_CMD_MEMFD_NEW, &mfd);
if (ret < 0) {
fprintf(stderr, "KDBUS_CMD_MEMFD_NEW failed: %m\n");
return EXIT_FAILURE;
}
+ memfd = mfd.fd;
if (write(memfd, &now, sizeof(now)) != sizeof(now)) {
fprintf(stderr, "writing to memfd failed: %m\n");
if (dst_id == KDBUS_DST_ID_BROADCAST)
size += KDBUS_ITEM_HEADER_SIZE + 64;
else {
- ret = ioctl(conn->fd, KDBUS_CMD_MEMFD_NEW, &memfd);
+ struct kdbus_cmd_memfd_make mfd;
+
+ mfd.size = sizeof(struct kdbus_cmd_memfd_make);
+ ret = ioctl(conn->fd, KDBUS_CMD_MEMFD_NEW, &mfd);
ASSERT_RETURN(ret == 0);
+ memfd = mfd.fd;
ASSERT_RETURN(write(memfd, "kdbus memfd 1234567", 19) == 19);
#include "util.h"
/**
- * kdbus_devname_valid - validate names showing up in /dev
+ * kdbus_sysname_valid - validate names showing up in /proc, /sys and /dev
* @name: Name of namespace, bus, endpoint
*
* Returns: 0 if the given name is valid, otherwise negative errno
*/
-int kdbus_devname_valid(const char *name)
+int kdbus_sysname_is_valid(const char *name)
{
unsigned int i;
size_t len;
return full_name_hash(str, strlen(str));
}
-int kdbus_devname_valid(const char *name);
+int kdbus_sysname_is_valid(const char *name);
#endif