Drop kdbus bits

Some kdbus_flag and memfd related parts are left behind, because they
are entangled with the "legacy" dbus support.

test-bus-benchmark is switched to "manual". It was already broken before
(in the non-kdbus mode) but apparently nobody noticed. Hopefully it can
be fixed later.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-07-23 11:45:57 -04:00
parent a6c97fc460
commit a132bef023
26 changed files with 149 additions and 4859 deletions

7
TODO
View File

@ -435,25 +435,18 @@ Features:
* sd-bus:
- EBADSLT handling
- GetAllProperties() on a non-existing object does not result in a failure currently
- kdbus: process fd=-1 for incoming msgs
- port to sd-resolve for connecting to TCP dbus servers
- kdbus: maybe add controlling tty metadata fields
- see if we can introduce a new sd_bus_get_owner_machine_id() call to retrieve the machine ID of the machine of the bus itself
- when kdbus does not take our message without memfds, try again with memfds
- see if we can drop more message validation on the sending side
- add API to clone sd_bus_message objects
- make AddMatch calls on dbus1 transports async?
- kdbus: matches against source or destination pids for an "strace -p"-like feel. Problem: The PID info needs to be available in userspace too...
- longer term: priority inheritance
- dbus spec updates:
- kdbus mapping
- NameLost/NameAcquired obsolete
- GVariant
- path escaping
- update systemd.special(7) to mention that dbus.socket is only about the compatibility socket now
- test bloom filter generation indexes
- kdbus: introduce a concept of "send-only" connections
- kdbus: add counter for refused unicast messages that is passed out via the RECV ioctl. SImilar to the counter for dropped multicast messages we already have.
* sd-event
- allow multiple signal handlers per signal?

View File

@ -57,10 +57,8 @@
#endif
#define UNIX_SYSTEM_BUS_ADDRESS "unix:path=/var/run/dbus/system_bus_socket"
#define KERNEL_SYSTEM_BUS_ADDRESS "kernel:path=/sys/fs/kdbus/0-system/bus"
#define DEFAULT_SYSTEM_BUS_ADDRESS KERNEL_SYSTEM_BUS_ADDRESS ";" UNIX_SYSTEM_BUS_ADDRESS
#define DEFAULT_SYSTEM_BUS_ADDRESS UNIX_SYSTEM_BUS_ADDRESS
#define UNIX_USER_BUS_ADDRESS_FMT "unix:path=%s/bus"
#define KERNEL_USER_BUS_ADDRESS_FMT "kernel:path=/sys/fs/kdbus/"UID_FMT"-user/bus"
#define PLYMOUTH_SOCKET { \
.un.sun_family = AF_UNIX, \

View File

@ -931,8 +931,6 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) {
whitelist_device(path, x, y);
whitelist_major(path, "pts", 'c', "rw");
whitelist_major(path, "kdbus", 'c', "rw");
whitelist_major(path, "kdbus/*", 'c', "rw");
}
LIST_FOREACH(device_allow, a, c->device_allow) {

View File

@ -1582,7 +1582,7 @@ int main(int argc, char *argv[]) {
* /proc/$PID/fd is available. */
if (getpid_cached() == 1) {
/* Load the kernel modules early, so that we kdbus.ko is loaded before kdbusfs shall be mounted */
/* Load the kernel modules early. */
if (!skip_setup)
kmod_setup();

View File

@ -614,7 +614,7 @@ static int service_setup_bus_name(Service *s) {
if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to add dependency on " SPECIAL_DBUS_SOCKET ": %m");
/* Regardless if kdbus is used or not, we always want to be ordered against dbus.socket if both are in the transaction. */
/* We always want to be ordered against dbus.socket if both are in the transaction. */
r = unit_add_dependency_by_name(UNIT(s), UNIT_AFTER, SPECIAL_DBUS_SOCKET, NULL, true);
if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to add dependency on " SPECIAL_DBUS_SOCKET ": %m");

View File

@ -41,7 +41,6 @@ libsystemd_internal_sources = files('''
sd-bus/bus-track.h
sd-bus/bus-type.c
sd-bus/bus-type.h
sd-bus/kdbus.h
sd-bus/sd-bus.c
sd-daemon/sd-daemon.c
sd-device/device-enumerator-private.h

View File

@ -140,138 +140,3 @@ int bus_container_connect_socket(sd_bus *b) {
return bus_socket_start_auth(b);
}
int bus_container_connect_kernel(sd_bus *b) {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int))];
} control = {};
int error_buf = 0;
struct iovec iov = {
.iov_base = &error_buf,
.iov_len = sizeof(error_buf),
};
struct msghdr mh = {
.msg_control = &control,
.msg_controllen = sizeof(control),
.msg_iov = &iov,
.msg_iovlen = 1,
};
struct cmsghdr *cmsg;
pid_t child;
siginfo_t si;
int r, fd = -1;
ssize_t n;
assert(b);
assert(b->input_fd < 0);
assert(b->output_fd < 0);
assert(b->nspid > 0 || b->machine);
if (b->nspid <= 0) {
r = container_get_leader(b->machine, &b->nspid);
if (r < 0)
return r;
}
r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &usernsfd, &rootfd);
if (r < 0)
return r;
if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, pair) < 0)
return -errno;
child = fork();
if (child < 0)
return -errno;
if (child == 0) {
pid_t grandchild;
pair[0] = safe_close(pair[0]);
r = namespace_enter(pidnsfd, mntnsfd, -1, usernsfd, rootfd);
if (r < 0)
_exit(EXIT_FAILURE);
/* We just changed PID namespace, however it will only
* take effect on the children we now fork. Hence,
* let's fork another time, and connect from this
* grandchild, so that kdbus only sees the credentials
* of this process which comes from within the
* container, and not outside of it */
grandchild = fork();
if (grandchild < 0)
_exit(EXIT_FAILURE);
if (grandchild == 0) {
fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0) {
/* Try to send error up */
error_buf = errno;
(void) write(pair[1], &error_buf, sizeof(error_buf));
_exit(EXIT_FAILURE);
}
r = send_one_fd(pair[1], fd, 0);
if (r < 0)
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);
}
r = wait_for_terminate(grandchild, &si);
if (r < 0)
_exit(EXIT_FAILURE);
if (si.si_code != CLD_EXITED)
_exit(EXIT_FAILURE);
_exit(si.si_status);
}
pair[1] = safe_close(pair[1]);
r = wait_for_terminate(child, &si);
if (r < 0)
return r;
n = recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC);
if (n < 0)
return -errno;
CMSG_FOREACH(cmsg, &mh) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
int *fds;
unsigned n_fds;
assert(fd < 0);
fds = (int*) CMSG_DATA(cmsg);
n_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
if (n_fds != 1) {
close_many(fds, n_fds);
return -EIO;
}
fd = fds[0];
}
}
/* If there's an fd passed, we are good. */
if (fd >= 0) {
b->input_fd = b->output_fd = fd;
return bus_kernel_take_fd(b);
}
/* If there's an error passed, use it */
if (n == sizeof(error_buf) && error_buf > 0)
return -error_buf;
/* Otherwise, we have no clue */
return -EIO;
}

View File

@ -22,4 +22,3 @@
#include "sd-bus.h"
int bus_container_connect_socket(sd_bus *b);
int bus_container_connect_kernel(sd_bus *b);

File diff suppressed because it is too large Load Diff

View File

@ -28,5 +28,3 @@ int bus_remove_match_internal(sd_bus *bus, const char *match, uint64_t cookie);
int bus_add_match_internal_kernel(sd_bus *bus, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
int bus_remove_match_internal_kernel(sd_bus *bus, uint64_t cookie);
int bus_get_name_creds_kdbus(sd_bus *bus, const char *name, uint64_t mask, bool allow_activator, sd_bus_creds **creds);

View File

@ -533,19 +533,12 @@ _public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_b
* to get it from the sender or peer. */
if (call->sender)
/* There's a sender, but the creds are
* missing. This means we are talking via
* dbus1, or are getting a message that was
* sent to us via kdbus, but was converted
* from a dbus1 message by the bus-proxy and
* thus also lacks the creds. */
/* There's a sender, but the creds are missing. */
return sd_bus_get_name_creds(call->bus, call->sender, mask, creds);
else
/* There's no sender, hence we are on a dbus1
* direct connection. For direct connections
/* There's no sender. For direct connections
* the credentials of the AF_UNIX peer matter,
* which may be queried via
* sd_bus_get_owner_creds(). */
* which may be queried via sd_bus_get_owner_creds(). */
return sd_bus_get_owner_creds(call->bus, mask, creds);
}
@ -579,9 +572,6 @@ _public_ int sd_bus_query_sender_privilege(sd_bus_message *call, int capability)
* here. */
assert_return((sd_bus_creds_get_augmented_mask(creds) & SD_BUS_CREDS_EFFECTIVE_CAPS) == 0, -EPERM);
/* Note that not even on kdbus we might have the caps
* field, due to faked identities, or namespace
* translation issues. */
r = sd_bus_creds_has_effective_cap(creds, capability);
if (r > 0)
return 1;

View File

@ -28,7 +28,6 @@
#include "bus-kernel.h"
#include "bus-match.h"
#include "hashmap.h"
#include "kdbus.h"
#include "list.h"
#include "prioq.h"
#include "refcnt.h"
@ -191,7 +190,6 @@ struct sd_bus {
int message_version;
int message_endian;
bool is_kernel:1;
bool can_fds:1;
bool bus_client:1;
bool ucred_valid:1;
@ -203,8 +201,6 @@ struct sd_bus {
bool filter_callbacks_modified:1;
bool nodes_modified:1;
bool trusted:1;
bool fake_creds_valid:1;
bool fake_pids_valid:1;
bool manual_peer_interface:1;
bool is_system:1;
bool is_user:1;
@ -245,7 +241,6 @@ struct sd_bus {
union sockaddr_union sockaddr;
socklen_t sockaddr_size;
char *kernel;
char *machine;
pid_t nspid;
@ -276,8 +271,6 @@ struct sd_bus {
unsigned iteration_counter;
void *kdbus_buffer;
/* We do locking around the memfd cache, since we want to
* allow people to process a sd_bus_message in a different
* thread then it was generated on and free it there. Since
@ -310,10 +303,6 @@ struct sd_bus {
sd_bus **default_bus_ptr;
pid_t tid;
struct kdbus_creds fake_creds;
struct kdbus_pids fake_pids;
char *fake_label;
char *cgroup_root;
char *description;
@ -402,3 +391,65 @@ int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
if (!assert_log(expr, #expr)) \
return sd_bus_error_set_errno(error, r); \
} while (false)
/**
* enum kdbus_attach_flags - flags for metadata attachments
* @KDBUS_ATTACH_TIMESTAMP: Timestamp
* @KDBUS_ATTACH_CREDS: Credentials
* @KDBUS_ATTACH_PIDS: PIDs
* @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups
* @KDBUS_ATTACH_NAMES: Well-known names
* @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID
* @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID
* @KDBUS_ATTACH_EXE: The path of the executable
* @KDBUS_ATTACH_CMDLINE: The process command line
* @KDBUS_ATTACH_CGROUP: The croup membership
* @KDBUS_ATTACH_CAPS: The process capabilities
* @KDBUS_ATTACH_SECLABEL: The security label
* @KDBUS_ATTACH_AUDIT: The audit IDs
* @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name
* @_KDBUS_ATTACH_ALL: All of the above
* @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of
* metatdata.
*/
enum kdbus_attach_flags {
KDBUS_ATTACH_TIMESTAMP = 1ULL << 0,
KDBUS_ATTACH_CREDS = 1ULL << 1,
KDBUS_ATTACH_PIDS = 1ULL << 2,
KDBUS_ATTACH_AUXGROUPS = 1ULL << 3,
KDBUS_ATTACH_NAMES = 1ULL << 4,
KDBUS_ATTACH_TID_COMM = 1ULL << 5,
KDBUS_ATTACH_PID_COMM = 1ULL << 6,
KDBUS_ATTACH_EXE = 1ULL << 7,
KDBUS_ATTACH_CMDLINE = 1ULL << 8,
KDBUS_ATTACH_CGROUP = 1ULL << 9,
KDBUS_ATTACH_CAPS = 1ULL << 10,
KDBUS_ATTACH_SECLABEL = 1ULL << 11,
KDBUS_ATTACH_AUDIT = 1ULL << 12,
KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13,
_KDBUS_ATTACH_ALL = (1ULL << 14) - 1,
_KDBUS_ATTACH_ANY = ~0ULL
};
/**
* enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
* @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception 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_POLICY_HOLDER: Special-purpose connection which registers
* policy entries for a name. The provided name
* is not activated and not registered with the
* name database, it only allows unprivileged
* connections to acquire a name, talk or discover
* a service
* @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
* bus traffic
*/
enum kdbus_hello_flags {
KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
KDBUS_HELLO_MONITOR = 1ULL << 3,
};

File diff suppressed because it is too large Load Diff

View File

@ -19,27 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include "sd-bus.h"
#define KDBUS_ITEM_NEXT(item) \
(typeof(item))(((uint8_t *)item) + ALIGN8((item)->size))
#define KDBUS_ITEM_FOREACH(part, head, first) \
for (part = (head)->first; \
((uint8_t *)(part) < (uint8_t *)(head) + (head)->size) && \
((uint8_t *) part >= (uint8_t *) head); \
part = KDBUS_ITEM_NEXT(part))
#define KDBUS_FOREACH(iter, first, _size) \
for (iter = (first); \
((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) && \
((uint8_t *)(iter) >= (uint8_t *)(first)); \
iter = (void*)(((uint8_t *)iter) + ALIGN8((iter)->size)))
#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
#define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
#define MEMFD_CACHE_MAX 32
/* When we cache a memfd block for reuse, we will truncate blocks
@ -50,10 +31,6 @@
* sending vectors */
#define MEMFD_MIN_SIZE (512*1024)
/* The size of the per-connection memory pool that we set up and where
* the kernel places our incoming messages */
#define KDBUS_POOL_SIZE (16*1024*1024)
struct memfd_cache {
int fd;
void *address;
@ -61,33 +38,7 @@ struct memfd_cache {
size_t allocated;
};
int bus_kernel_connect(sd_bus *b);
int bus_kernel_take_fd(sd_bus *b);
void close_and_munmap(int fd, void *address, size_t size);
void bus_flush_memfd(sd_bus *bus);
int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call);
int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority);
int bus_kernel_open_bus_fd(const char *bus, char **path);
int bus_kernel_create_bus(const char *name, bool world, char **s);
int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char **path);
int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *allocated);
void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, size_t allocated);
void bus_kernel_flush_memfd(sd_bus *bus);
int bus_kernel_parse_unique_name(const char *s, uint64_t *id);
uint64_t request_name_flags_to_kdbus(uint64_t sd_bus_flags);
uint64_t attach_flags_to_kdbus(uint64_t sd_bus_flags);
int bus_kernel_try_close(sd_bus *bus);
int bus_kernel_drop_one(int fd);
int bus_kernel_realize_attach_flags(sd_bus *bus);
int bus_kernel_get_bus_name(sd_bus *bus, char **name);
int bus_kernel_cmd_free(sd_bus *bus, uint64_t offset);

View File

@ -62,22 +62,9 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
assert(m);
assert(part);
if (part->memfd >= 0) {
/* If we can reuse the memfd, try that. For that it
* can't be sealed yet. */
if (!part->sealed) {
assert(part->memfd_offset == 0);
assert(part->data == part->mmap_begin);
bus_kernel_push_memfd(m->bus, part->memfd, part->data, part->mapped, part->allocated);
} else {
if (part->mapped > 0)
assert_se(munmap(part->mmap_begin, part->mapped) == 0);
safe_close(part->memfd);
}
} else if (part->munmap_this)
if (part->memfd >= 0)
close_and_munmap(part->memfd, part->mmap_begin, part->mapped);
else if (part->munmap_this)
munmap(part->mmap_begin, part->mapped);
else if (part->free_this)
free(part->data);
@ -129,12 +116,6 @@ static void message_free(sd_bus_message *m) {
message_reset_parts(m);
if (m->release_kdbus)
bus_kernel_cmd_free(m->bus, (uint8_t *) m->kdbus - (uint8_t *) m->bus->kdbus_buffer);
if (m->free_kdbus)
free(m->kdbus);
sd_bus_unref(m->bus);
if (m->free_fds) {
@ -1215,7 +1196,6 @@ static int part_make_space(
void **q) {
void *n;
int r;
assert(m);
assert(part);
@ -1224,61 +1204,19 @@ static int part_make_space(
if (m->poisoned)
return -ENOMEM;
if (!part->data && part->memfd < 0) {
part->memfd = bus_kernel_pop_memfd(m->bus, &part->data, &part->mapped, &part->allocated);
part->mmap_begin = part->data;
}
if (part->allocated == 0 || sz > part->allocated) {
size_t new_allocated;
if (part->memfd >= 0) {
if (part->allocated == 0 || sz > part->allocated) {
uint64_t new_allocated;
new_allocated = PAGE_ALIGN(sz > 0 ? 2 * sz : 1);
r = memfd_set_size(part->memfd, new_allocated);
if (r < 0) {
m->poisoned = true;
return r;
}
part->allocated = new_allocated;
new_allocated = sz > 0 ? 2 * sz : 64;
n = realloc(part->data, new_allocated);
if (!n) {
m->poisoned = true;
return -ENOMEM;
}
if (!part->data || sz > part->mapped) {
size_t psz;
psz = PAGE_ALIGN(sz > 0 ? sz : 1);
if (part->mapped <= 0)
n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, 0);
else
n = mremap(part->mmap_begin, part->mapped, psz, MREMAP_MAYMOVE);
if (n == MAP_FAILED) {
m->poisoned = true;
return -errno;
}
part->mmap_begin = part->data = n;
part->mapped = psz;
part->memfd_offset = 0;
}
part->munmap_this = true;
} else {
if (part->allocated == 0 || sz > part->allocated) {
size_t new_allocated;
new_allocated = sz > 0 ? 2 * sz : 64;
n = realloc(part->data, new_allocated);
if (!n) {
m->poisoned = true;
return -ENOMEM;
}
part->data = n;
part->allocated = new_allocated;
part->free_this = true;
}
part->data = n;
part->allocated = new_allocated;
part->free_this = true;
}
if (q)
@ -5368,7 +5306,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
r = message_peek_field_string(m, service_name_is_valid, &ri, item_size, &m->sender);
if (r >= 0 && m->sender[0] == ':' && m->bus->bus_client && !m->bus->is_kernel) {
if (r >= 0 && m->sender[0] == ':' && m->bus->bus_client) {
m->creds.unique_name = (char*) m->sender;
m->creds.mask |= SD_BUS_CREDS_UNIQUE_NAME & m->bus->creds_mask;
}

View File

@ -92,9 +92,7 @@ struct sd_bus_message {
bool dont_send:1;
bool allow_fds:1;
bool free_header:1;
bool free_kdbus:1;
bool free_fds:1;
bool release_kdbus:1;
bool poisoned:1;
/* The first and last bytes of the message */
@ -128,8 +126,6 @@ struct sd_bus_message {
struct iovec iovec_fixed[2];
unsigned n_iovec;
struct kdbus_msg *kdbus;
char *peeked_signature;
/* If set replies to this message must carry the signature

View File

@ -593,7 +593,6 @@ void bus_socket_setup(sd_bus *b) {
fd_inc_rcvbuf(b->input_fd, SNDBUF_SIZE);
fd_inc_sndbuf(b->output_fd, SNDBUF_SIZE);
b->is_kernel = false;
b->message_version = 1;
b->message_endian = 0;
}

View File

@ -1,980 +0,0 @@
/*
* kdbus is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*/
#ifndef _UAPI_KDBUS_H_
#define _UAPI_KDBUS_H_
#include <linux/ioctl.h>
#include <linux/types.h>
#define KDBUS_IOCTL_MAGIC 0x95
#define KDBUS_SRC_ID_KERNEL (0)
#define KDBUS_DST_ID_NAME (0)
#define KDBUS_MATCH_ID_ANY (~0ULL)
#define KDBUS_DST_ID_BROADCAST (~0ULL)
#define KDBUS_FLAG_NEGOTIATE (1ULL << 63)
/**
* struct kdbus_notify_id_change - name registry change message
* @id: New or former owner of the name
* @flags: flags field from KDBUS_HELLO_*
*
* Sent from kernel to userspace when the owner or activator of
* a well-known name changes.
*
* Attached to:
* KDBUS_ITEM_ID_ADD
* KDBUS_ITEM_ID_REMOVE
*/
struct kdbus_notify_id_change {
__u64 id;
__u64 flags;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_notify_name_change - name registry change message
* @old_id: ID and flags of former owner of a name
* @new_id: ID and flags of new owner of a name
* @name: Well-known name
*
* Sent from kernel to userspace when the owner or activator of
* a well-known name changes.
*
* Attached to:
* KDBUS_ITEM_NAME_ADD
* KDBUS_ITEM_NAME_REMOVE
* KDBUS_ITEM_NAME_CHANGE
*/
struct kdbus_notify_name_change {
struct kdbus_notify_id_change old_id;
struct kdbus_notify_id_change new_id;
char name[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_creds - process credentials
* @uid: User ID
* @euid: Effective UID
* @suid: Saved UID
* @fsuid: Filesystem UID
* @gid: Group ID
* @egid: Effective GID
* @sgid: Saved GID
* @fsgid: Filesystem GID
*
* Attached to:
* KDBUS_ITEM_CREDS
*/
struct kdbus_creds {
__u64 uid;
__u64 euid;
__u64 suid;
__u64 fsuid;
__u64 gid;
__u64 egid;
__u64 sgid;
__u64 fsgid;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_pids - process identifiers
* @pid: Process ID
* @tid: Thread ID
* @ppid: Parent process ID
*
* The PID and TID of a process.
*
* Attached to:
* KDBUS_ITEM_PIDS
*/
struct kdbus_pids {
__u64 pid;
__u64 tid;
__u64 ppid;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_caps - process capabilities
* @last_cap: Highest currently known capability bit
* @caps: Variable number of 32-bit capabilities flags
*
* Contains a variable number of 32-bit capabilities flags.
*
* Attached to:
* KDBUS_ITEM_CAPS
*/
struct kdbus_caps {
__u32 last_cap;
__u32 caps[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_audit - audit information
* @sessionid: The audit session ID
* @loginuid: The audit login uid
*
* Attached to:
* KDBUS_ITEM_AUDIT
*/
struct kdbus_audit {
__u32 sessionid;
__u32 loginuid;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_timestamp
* @seqnum: Global per-domain message sequence number
* @monotonic_ns: Monotonic timestamp, in nanoseconds
* @realtime_ns: Realtime timestamp, in nanoseconds
*
* Attached to:
* KDBUS_ITEM_TIMESTAMP
*/
struct kdbus_timestamp {
__u64 seqnum;
__u64 monotonic_ns;
__u64 realtime_ns;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_vec - I/O vector for kdbus payload items
* @size: The size of the vector
* @address: Memory address of data buffer
* @offset: Offset in the in-message payload memory,
* relative to the message head
*
* Attached to:
* KDBUS_ITEM_PAYLOAD_VEC, KDBUS_ITEM_PAYLOAD_OFF
*/
struct kdbus_vec {
__u64 size;
union {
__u64 address;
__u64 offset;
};
} __attribute__((__aligned__(8)));
/**
* struct kdbus_bloom_parameter - bus-wide bloom parameters
* @size: Size of the bit field in bytes (m / 8)
* @n_hash: Number of hash functions used (k)
*/
struct kdbus_bloom_parameter {
__u64 size;
__u64 n_hash;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_bloom_filter - bloom filter containing n elements
* @generation: Generation of the element set in the filter
* @data: Bit field, multiple of 8 bytes
*/
struct kdbus_bloom_filter {
__u64 generation;
__u64 data[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_memfd - a kdbus memfd
* @start: The offset into the memfd where the segment starts
* @size: The size of the memfd segment
* @fd: The file descriptor number
* @__pad: Padding to ensure proper alignment and size
*
* Attached to:
* KDBUS_ITEM_PAYLOAD_MEMFD
*/
struct kdbus_memfd {
__u64 start;
__u64 size;
int fd;
__u32 __pad;
} __attribute__((__aligned__(8)));
/**
* struct kdbus_name - a registered well-known name with its flags
* @flags: Flags from KDBUS_NAME_*
* @name: Well-known name
*
* Attached to:
* KDBUS_ITEM_OWNED_NAME
*/
struct kdbus_name {
__u64 flags;
char name[0];
} __attribute__((__aligned__(8)));
/**
* enum kdbus_policy_access_type - permissions of a policy record
* @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid
* @KDBUS_POLICY_ACCESS_USER: Grant access to a uid
* @KDBUS_POLICY_ACCESS_GROUP: Grant access to gid
* @KDBUS_POLICY_ACCESS_WORLD: World-accessible
*/
enum kdbus_policy_access_type {
_KDBUS_POLICY_ACCESS_NULL,
KDBUS_POLICY_ACCESS_USER,
KDBUS_POLICY_ACCESS_GROUP,
KDBUS_POLICY_ACCESS_WORLD,
};
/**
* enum kdbus_policy_access_flags - mode flags
* @KDBUS_POLICY_OWN: Allow to own a well-known name
* Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
* @KDBUS_POLICY_TALK: Allow communication to a well-known name
* Implies KDBUS_POLICY_SEE
* @KDBUS_POLICY_SEE: Allow to see a well-known name
*/
enum kdbus_policy_type {
KDBUS_POLICY_SEE = 0,
KDBUS_POLICY_TALK,
KDBUS_POLICY_OWN,
};
/**
* struct kdbus_policy_access - policy access item
* @type: One of KDBUS_POLICY_ACCESS_* types
* @access: Access to grant
* @id: For KDBUS_POLICY_ACCESS_USER, the uid
* For KDBUS_POLICY_ACCESS_GROUP, the gid
*/
struct kdbus_policy_access {
__u64 type; /* USER, GROUP, WORLD */
__u64 access; /* OWN, TALK, SEE */
__u64 id; /* uid, gid, 0 */
} __attribute__((__aligned__(8)));
/**
* enum kdbus_attach_flags - flags for metadata attachments
* @KDBUS_ATTACH_TIMESTAMP: Timestamp
* @KDBUS_ATTACH_CREDS: Credentials
* @KDBUS_ATTACH_PIDS: PIDs
* @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups
* @KDBUS_ATTACH_NAMES: Well-known names
* @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID
* @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID
* @KDBUS_ATTACH_EXE: The path of the executable
* @KDBUS_ATTACH_CMDLINE: The process command line
* @KDBUS_ATTACH_CGROUP: The croup membership
* @KDBUS_ATTACH_CAPS: The process capabilities
* @KDBUS_ATTACH_SECLABEL: The security label
* @KDBUS_ATTACH_AUDIT: The audit IDs
* @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name
* @_KDBUS_ATTACH_ALL: All of the above
* @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of
* metatdata.
*/
enum kdbus_attach_flags {
KDBUS_ATTACH_TIMESTAMP = 1ULL << 0,
KDBUS_ATTACH_CREDS = 1ULL << 1,
KDBUS_ATTACH_PIDS = 1ULL << 2,
KDBUS_ATTACH_AUXGROUPS = 1ULL << 3,
KDBUS_ATTACH_NAMES = 1ULL << 4,
KDBUS_ATTACH_TID_COMM = 1ULL << 5,
KDBUS_ATTACH_PID_COMM = 1ULL << 6,
KDBUS_ATTACH_EXE = 1ULL << 7,
KDBUS_ATTACH_CMDLINE = 1ULL << 8,
KDBUS_ATTACH_CGROUP = 1ULL << 9,
KDBUS_ATTACH_CAPS = 1ULL << 10,
KDBUS_ATTACH_SECLABEL = 1ULL << 11,
KDBUS_ATTACH_AUDIT = 1ULL << 12,
KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13,
_KDBUS_ATTACH_ALL = (1ULL << 14) - 1,
_KDBUS_ATTACH_ANY = ~0ULL
};
/**
* enum kdbus_item_type - item types to chain data in a list
* @_KDBUS_ITEM_NULL: Uninitialized/invalid
* @_KDBUS_ITEM_USER_BASE: Start of user items
* @KDBUS_ITEM_NEGOTIATE: Negotiate supported items
* @KDBUS_ITEM_PAYLOAD_VEC: Vector to data
* @KDBUS_ITEM_PAYLOAD_OFF: Data at returned offset to message head
* @KDBUS_ITEM_PAYLOAD_MEMFD: Data as sealed memfd
* @KDBUS_ITEM_FDS: Attached file descriptors
* @KDBUS_ITEM_CANCEL_FD: FD used to cancel a synchronous
* operation by writing to it from
* userspace
* @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with
* KDBUS_CMD_BUS_MAKE, carries a
* struct kdbus_bloom_parameter
* @KDBUS_ITEM_BLOOM_FILTER: Bloom filter carried with a message,
* used to match against a bloom mask of a
* connection, carries a struct
* kdbus_bloom_filter
* @KDBUS_ITEM_BLOOM_MASK: Bloom mask used to match against a
* message'sbloom filter
* @KDBUS_ITEM_DST_NAME: Destination's well-known name
* @KDBUS_ITEM_MAKE_NAME: Name of domain, bus, endpoint
* @KDBUS_ITEM_ATTACH_FLAGS_SEND: Attach-flags, used for updating which
* metadata a connection opts in to send
* @KDBUS_ITEM_ATTACH_FLAGS_RECV: Attach-flags, used for updating which
* metadata a connection requests to
* receive for each reeceived message
* @KDBUS_ITEM_ID: Connection ID
* @KDBUS_ITEM_NAME: Well-know name with flags
* @_KDBUS_ITEM_ATTACH_BASE: Start of metadata attach items
* @KDBUS_ITEM_TIMESTAMP: Timestamp
* @KDBUS_ITEM_CREDS: Process credentials
* @KDBUS_ITEM_PIDS: Process identifiers
* @KDBUS_ITEM_AUXGROUPS: Auxiliary process groups
* @KDBUS_ITEM_OWNED_NAME: A name owned by the associated
* connection
* @KDBUS_ITEM_TID_COMM: Thread ID "comm" identifier
* (Don't trust this, see below.)
* @KDBUS_ITEM_PID_COMM: Process ID "comm" identifier
* (Don't trust this, see below.)
* @KDBUS_ITEM_EXE: The path of the executable
* (Don't trust this, see below.)
* @KDBUS_ITEM_CMDLINE: The process command line
* (Don't trust this, see below.)
* @KDBUS_ITEM_CGROUP: The croup membership
* @KDBUS_ITEM_CAPS: The process capabilities
* @KDBUS_ITEM_SECLABEL: The security label
* @KDBUS_ITEM_AUDIT: The audit IDs
* @KDBUS_ITEM_CONN_DESCRIPTION: The connection's human-readable name
* (debugging)
* @_KDBUS_ITEM_POLICY_BASE: Start of policy items
* @KDBUS_ITEM_POLICY_ACCESS: Policy access block
* @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items
* @KDBUS_ITEM_NAME_ADD: Notification in kdbus_notify_name_change
* @KDBUS_ITEM_NAME_REMOVE: Notification in kdbus_notify_name_change
* @KDBUS_ITEM_NAME_CHANGE: Notification in kdbus_notify_name_change
* @KDBUS_ITEM_ID_ADD: Notification in kdbus_notify_id_change
* @KDBUS_ITEM_ID_REMOVE: Notification in kdbus_notify_id_change
* @KDBUS_ITEM_REPLY_TIMEOUT: Timeout has been reached
* @KDBUS_ITEM_REPLY_DEAD: Destination died
*
* N.B: The process and thread COMM fields, as well as the CMDLINE and
* EXE fields may be altered by unprivileged processes und should
* hence *not* used for security decisions. Peers should make use of
* these items only for informational purposes, such as generating log
* records.
*/
enum kdbus_item_type {
_KDBUS_ITEM_NULL,
_KDBUS_ITEM_USER_BASE,
KDBUS_ITEM_NEGOTIATE = _KDBUS_ITEM_USER_BASE,
KDBUS_ITEM_PAYLOAD_VEC,
KDBUS_ITEM_PAYLOAD_OFF,
KDBUS_ITEM_PAYLOAD_MEMFD,
KDBUS_ITEM_FDS,
KDBUS_ITEM_CANCEL_FD,
KDBUS_ITEM_BLOOM_PARAMETER,
KDBUS_ITEM_BLOOM_FILTER,
KDBUS_ITEM_BLOOM_MASK,
KDBUS_ITEM_DST_NAME,
KDBUS_ITEM_MAKE_NAME,
KDBUS_ITEM_ATTACH_FLAGS_SEND,
KDBUS_ITEM_ATTACH_FLAGS_RECV,
KDBUS_ITEM_ID,
KDBUS_ITEM_NAME,
KDBUS_ITEM_DST_ID,
/* keep these item types in sync with KDBUS_ATTACH_* flags */
_KDBUS_ITEM_ATTACH_BASE = 0x1000,
KDBUS_ITEM_TIMESTAMP = _KDBUS_ITEM_ATTACH_BASE,
KDBUS_ITEM_CREDS,
KDBUS_ITEM_PIDS,
KDBUS_ITEM_AUXGROUPS,
KDBUS_ITEM_OWNED_NAME,
KDBUS_ITEM_TID_COMM,
KDBUS_ITEM_PID_COMM,
KDBUS_ITEM_EXE,
KDBUS_ITEM_CMDLINE,
KDBUS_ITEM_CGROUP,
KDBUS_ITEM_CAPS,
KDBUS_ITEM_SECLABEL,
KDBUS_ITEM_AUDIT,
KDBUS_ITEM_CONN_DESCRIPTION,
_KDBUS_ITEM_POLICY_BASE = 0x2000,
KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
_KDBUS_ITEM_KERNEL_BASE = 0x8000,
KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE,
KDBUS_ITEM_NAME_REMOVE,
KDBUS_ITEM_NAME_CHANGE,
KDBUS_ITEM_ID_ADD,
KDBUS_ITEM_ID_REMOVE,
KDBUS_ITEM_REPLY_TIMEOUT,
KDBUS_ITEM_REPLY_DEAD,
};
/**
* struct kdbus_item - chain of data blocks
* @size: Overall data record size
* @type: Kdbus_item type of data
* @data: Generic bytes
* @data32: Generic 32 bit array
* @data64: Generic 64 bit array
* @str: Generic string
* @id: Connection ID
* @vec: KDBUS_ITEM_PAYLOAD_VEC
* @creds: KDBUS_ITEM_CREDS
* @audit: KDBUS_ITEM_AUDIT
* @timestamp: KDBUS_ITEM_TIMESTAMP
* @name: KDBUS_ITEM_NAME
* @bloom_parameter: KDBUS_ITEM_BLOOM_PARAMETER
* @bloom_filter: KDBUS_ITEM_BLOOM_FILTER
* @memfd: KDBUS_ITEM_PAYLOAD_MEMFD
* @name_change: KDBUS_ITEM_NAME_ADD
* KDBUS_ITEM_NAME_REMOVE
* KDBUS_ITEM_NAME_CHANGE
* @id_change: KDBUS_ITEM_ID_ADD
* KDBUS_ITEM_ID_REMOVE
* @policy: KDBUS_ITEM_POLICY_ACCESS
*/
struct kdbus_item {
__u64 size;
__u64 type;
union {
__u8 data[0];
__u32 data32[0];
__u64 data64[0];
char str[0];
__u64 id;
struct kdbus_vec vec;
struct kdbus_creds creds;
struct kdbus_pids pids;
struct kdbus_audit audit;
struct kdbus_caps caps;
struct kdbus_timestamp timestamp;
struct kdbus_name name;
struct kdbus_bloom_parameter bloom_parameter;
struct kdbus_bloom_filter bloom_filter;
struct kdbus_memfd memfd;
int fds[0];
struct kdbus_notify_name_change name_change;
struct kdbus_notify_id_change id_change;
struct kdbus_policy_access policy_access;
};
} __attribute__((__aligned__(8)));
/**
* enum kdbus_msg_flags - type of message
* @KDBUS_MSG_EXPECT_REPLY: Expect a reply message, used for
* method calls. The userspace-supplied
* cookie identifies the message and the
* respective reply carries the cookie
* in cookie_reply
* @KDBUS_MSG_NO_AUTO_START: Do not start a service if the addressed
* name is not currently active. This flag is
* not looked at by the kernel but only
* serves as hint for userspace implementations.
* @KDBUS_MSG_SIGNAL: Treat this message as signal
*/
enum kdbus_msg_flags {
KDBUS_MSG_EXPECT_REPLY = 1ULL << 0,
KDBUS_MSG_NO_AUTO_START = 1ULL << 1,
KDBUS_MSG_SIGNAL = 1ULL << 2,
};
/**
* enum kdbus_payload_type - type of payload carried by message
* @KDBUS_PAYLOAD_KERNEL: Kernel-generated simple message
* @KDBUS_PAYLOAD_DBUS: D-Bus marshalling "DBusDBus"
*
* Any payload-type is accepted. Common types will get added here once
* established.
*/
enum kdbus_payload_type {
KDBUS_PAYLOAD_KERNEL,
KDBUS_PAYLOAD_DBUS = 0x4442757344427573ULL,
};
/**
* struct kdbus_msg - the representation of a kdbus message
* @size: Total size of the message
* @flags: Message flags (KDBUS_MSG_*), userspace kernel
* @priority: Message queue priority value
* @dst_id: 64-bit ID of the destination connection
* @src_id: 64-bit ID of the source connection
* @payload_type: Payload type (KDBUS_PAYLOAD_*)
* @cookie: Userspace-supplied cookie, for the connection
* to identify its messages
* @timeout_ns: The time to wait for a message reply from the peer.
* If there is no reply, and the send command is
* executed asynchronously, a kernel-generated message
* with an attached KDBUS_ITEM_REPLY_TIMEOUT item
* is sent to @src_id. For synchronously executed send
* command, the value denotes the maximum time the call
* blocks to wait for a reply. The timeout is expected in
* nanoseconds and as absolute CLOCK_MONOTONIC value.
* @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 size;
__u64 flags;
__s64 priority;
__u64 dst_id;
__u64 src_id;
__u64 payload_type;
__u64 cookie;
union {
__u64 timeout_ns;
__u64 cookie_reply;
};
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_msg_info - returned message container
* @offset: Offset of kdbus_msg slice in pool
* @msg_size: Copy of the kdbus_msg.size field
* @return_flags: Command return flags, kernel userspace
*/
struct kdbus_msg_info {
__u64 offset;
__u64 msg_size;
__u64 return_flags;
} __attribute__((__aligned__(8)));
/**
* enum kdbus_send_flags - flags for sending messages
* @KDBUS_SEND_SYNC_REPLY: Wait for destination connection to
* reply to this message. The
* KDBUS_CMD_SEND ioctl() will block
* until the reply is received, and
* reply in struct kdbus_cmd_send will
* yield the offset in the sender's pool
* where the reply can be found.
* This flag is only valid if
* @KDBUS_MSG_EXPECT_REPLY is set as well.
*/
enum kdbus_send_flags {
KDBUS_SEND_SYNC_REPLY = 1ULL << 0,
};
/**
* struct kdbus_cmd_send - send message
* @size: Overall size of this structure
* @flags: Flags to change send behavior (KDBUS_SEND_*)
* @return_flags: Command return flags, kernel userspace
* @msg_address: Storage address of the kdbus_msg to send
* @reply: Storage for message reply if KDBUS_SEND_SYNC_REPLY
* was given
* @items: Additional items for this command
*/
struct kdbus_cmd_send {
__u64 size;
__u64 flags;
__u64 return_flags;
__u64 msg_address;
struct kdbus_msg_info reply;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* enum kdbus_recv_flags - flags for de-queuing messages
* @KDBUS_RECV_PEEK: Return the next queued message without
* actually de-queuing it, and without installing
* any file descriptors or other resources. It is
* usually used to determine the activating
* connection of a bus name.
* @KDBUS_RECV_DROP: Drop and free the next queued message and all
* its resources without actually receiving it.
* @KDBUS_RECV_USE_PRIORITY: Only de-queue messages with the specified or
* higher priority (lowest values); if not set,
* the priority value is ignored.
*/
enum kdbus_recv_flags {
KDBUS_RECV_PEEK = 1ULL << 0,
KDBUS_RECV_DROP = 1ULL << 1,
KDBUS_RECV_USE_PRIORITY = 1ULL << 2,
};
/**
* enum kdbus_recv_return_flags - return flags for message receive commands
* @KDBUS_RECV_RETURN_INCOMPLETE_FDS: One or more file descriptors could not
* be installed. These descriptors in
* KDBUS_ITEM_FDS will carry the value -1.
* @KDBUS_RECV_RETURN_DROPPED_MSGS: There have been dropped messages since
* the last time a message was received.
* The 'dropped_msgs' counter contains the
* number of messages dropped pool
* overflows or other missed broadcasts.
*/
enum kdbus_recv_return_flags {
KDBUS_RECV_RETURN_INCOMPLETE_FDS = 1ULL << 0,
KDBUS_RECV_RETURN_DROPPED_MSGS = 1ULL << 1,
};
/**
* struct kdbus_cmd_recv - struct to de-queue a buffered message
* @size: Overall size of this object
* @flags: KDBUS_RECV_* flags, userspace kernel
* @return_flags: Command return flags, kernel userspace
* @priority: Minimum priority of the messages to de-queue. Lowest
* values have the highest priority.
* @dropped_msgs: In case there were any dropped messages since the last
* time a message was received, this will be set to the
* number of lost messages and
* KDBUS_RECV_RETURN_DROPPED_MSGS will be set in
* 'return_flags'. This can only happen if the ioctl
* returns 0 or EAGAIN.
* @msg: Return storage for received message.
* @items: Additional items for this command.
*
* This struct is used with the KDBUS_CMD_RECV ioctl.
*/
struct kdbus_cmd_recv {
__u64 size;
__u64 flags;
__u64 return_flags;
__s64 priority;
__u64 dropped_msgs;
struct kdbus_msg_info msg;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_cmd_free - struct to free a slice of memory in the pool
* @size: Overall size of this structure
* @flags: Flags for the free command, userspace kernel
* @return_flags: Command return flags, kernel userspace
* @offset: The offset of the memory slice, as returned by other
* ioctls
* @items: Additional items to modify the behavior
*
* This struct is used with the KDBUS_CMD_FREE ioctl.
*/
struct kdbus_cmd_free {
__u64 size;
__u64 flags;
__u64 return_flags;
__u64 offset;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
* @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception 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_POLICY_HOLDER: Special-purpose connection which registers
* policy entries for a name. The provided name
* is not activated and not registered with the
* name database, it only allows unprivileged
* connections to acquire a name, talk or discover
* a service
* @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
* bus traffic
*/
enum kdbus_hello_flags {
KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
KDBUS_HELLO_MONITOR = 1ULL << 3,
};
/**
* struct kdbus_cmd_hello - struct to say hello to kdbus
* @size: The total size of the structure
* @flags: Connection flags (KDBUS_HELLO_*), userspace kernel
* @return_flags: Command return flags, kernel userspace
* @attach_flags_send: Mask of metadata to attach to each message sent
* off by this connection (KDBUS_ATTACH_*)
* @attach_flags_recv: Mask of metadata to attach to each message receieved
* by the new connection (KDBUS_ATTACH_*)
* @bus_flags: The flags field copied verbatim from the original
* KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
* to do negotiation of features of the payload that is
* transferred (kernel userspace)
* @id: The ID of this connection (kernel userspace)
* @pool_size: Size of the connection's buffer where the received
* messages are placed
* @offset: Pool offset where items are returned to report
* additional information about the bus and the newly
* created connection.
* @items_size: Size of buffer returned in the pool slice at @offset.
* @id128: Unique 128-bit ID of the bus (kernel userspace)
* @items: A list of items
*
* This struct is used with the KDBUS_CMD_HELLO ioctl.
*/
struct kdbus_cmd_hello {
__u64 size;
__u64 flags;
__u64 return_flags;
__u64 attach_flags_send;
__u64 attach_flags_recv;
__u64 bus_flags;
__u64 id;
__u64 pool_size;
__u64 offset;
__u64 items_size;
__u8 id128[16];
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_info - connection information
* @size: total size of the struct
* @id: 64bit object ID
* @flags: object creation flags
* @items: list of items
*
* Note that the user is responsible for freeing the allocated memory with
* the KDBUS_CMD_FREE ioctl.
*/
struct kdbus_info {
__u64 size;
__u64 id;
__u64 flags;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* enum kdbus_list_flags - what to include into the returned list
* @KDBUS_LIST_UNIQUE: active connections
* @KDBUS_LIST_ACTIVATORS: activator connections
* @KDBUS_LIST_NAMES: known well-known names
* @KDBUS_LIST_QUEUED: queued-up names
*/
enum kdbus_list_flags {
KDBUS_LIST_UNIQUE = 1ULL << 0,
KDBUS_LIST_NAMES = 1ULL << 1,
KDBUS_LIST_ACTIVATORS = 1ULL << 2,
KDBUS_LIST_QUEUED = 1ULL << 3,
};
/**
* struct kdbus_cmd_list - list connections
* @size: overall size of this object
* @flags: flags for the query (KDBUS_LIST_*), userspace kernel
* @return_flags: command return flags, kernel userspace
* @offset: Offset in the caller's pool buffer where an array of
* kdbus_info objects is stored.
* The user must use KDBUS_CMD_FREE to free the
* allocated memory.
* @list_size: size of returned list in bytes
* @items: Items for the command. Reserved for future use.
*
* This structure is used with the KDBUS_CMD_LIST ioctl.
*/
struct kdbus_cmd_list {
__u64 size;
__u64 flags;
__u64 return_flags;
__u64 offset;
__u64 list_size;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* struct kdbus_cmd_info - struct used for KDBUS_CMD_CONN_INFO ioctl
* @size: The total size of the struct
* @flags: Flags for this ioctl, userspace kernel
* @return_flags: Command return flags, kernel userspace
* @id: The 64-bit ID of the connection. If set to zero, passing
* @name is required. kdbus will look up the name to
* determine the ID in this case.
* @attach_flags: Set of attach flags to specify the set of information
* to receive, userspace kernel
* @offset: Returned offset in the caller's pool buffer where the
* kdbus_info struct result is stored. The user must
* use KDBUS_CMD_FREE to free the allocated memory.
* @info_size: Output buffer to report size of data at @offset.
* @items: The optional item list, containing the
* well-known name to look up as a KDBUS_ITEM_NAME.
* Only needed in case @id is zero.
*
* On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
* tell the user the offset in the connection pool buffer at which to find the
* result in a struct kdbus_info.
*/
struct kdbus_cmd_info {
__u64 size;
__u64 flags;
__u64 return_flags;
__u64 id;
__u64 attach_flags;
__u64 offset;
__u64 info_size;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* enum kdbus_cmd_match_flags - flags to control the KDBUS_CMD_MATCH_ADD ioctl
* @KDBUS_MATCH_REPLACE: If entries with the supplied cookie already
* exists, remove them before installing the new
* matches.
*/
enum kdbus_cmd_match_flags {
KDBUS_MATCH_REPLACE = 1ULL << 0,
};
/**
* struct kdbus_cmd_match - struct to add or remove matches
* @size: The total size of the struct
* @flags: Flags for match command (KDBUS_MATCH_*),
* userspace kernel
* @return_flags: Command return flags, kernel userspace
* @cookie: Userspace supplied cookie. When removing, the cookie
* identifies the match to remove
* @items: A list of items for additional information
*
* This structure is used with the KDBUS_CMD_MATCH_ADD and
* KDBUS_CMD_MATCH_REMOVE ioctl.
*/
struct kdbus_cmd_match {
__u64 size;
__u64 flags;
__u64 return_flags;
__u64 cookie;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,ENDPOINT}_MAKE
* @KDBUS_MAKE_ACCESS_GROUP: Make the bus or endpoint node group-accessible
* @KDBUS_MAKE_ACCESS_WORLD: Make the bus or endpoint node world-accessible
*/
enum kdbus_make_flags {
KDBUS_MAKE_ACCESS_GROUP = 1ULL << 0,
KDBUS_MAKE_ACCESS_WORLD = 1ULL << 1,
};
/**
* enum kdbus_name_flags - flags for KDBUS_CMD_NAME_ACQUIRE
* @KDBUS_NAME_REPLACE_EXISTING: Try to replace name of other connections
* @KDBUS_NAME_ALLOW_REPLACEMENT: Allow the replacement of the name
* @KDBUS_NAME_QUEUE: Name should be queued if busy
* @KDBUS_NAME_IN_QUEUE: Name is queued
* @KDBUS_NAME_ACTIVATOR: Name is owned by a activator connection
*/
enum kdbus_name_flags {
KDBUS_NAME_REPLACE_EXISTING = 1ULL << 0,
KDBUS_NAME_ALLOW_REPLACEMENT = 1ULL << 1,
KDBUS_NAME_QUEUE = 1ULL << 2,
KDBUS_NAME_IN_QUEUE = 1ULL << 3,
KDBUS_NAME_ACTIVATOR = 1ULL << 4,
};
/**
* struct kdbus_cmd - generic ioctl payload
* @size: Overall size of this structure
* @flags: Flags for this ioctl, userspace kernel
* @return_flags: Ioctl return flags, kernel userspace
* @items: Additional items to modify the behavior
*
* This is a generic ioctl payload object. It's used by all ioctls that only
* take flags and items as input.
*/
struct kdbus_cmd {
__u64 size;
__u64 flags;
__u64 return_flags;
struct kdbus_item items[0];
} __attribute__((__aligned__(8)));
/**
* Ioctl API
*
* KDBUS_CMD_BUS_MAKE: After opening the "control" node, this command
* creates a new bus with the specified
* name. The bus is immediately shut down and
* cleaned up when the opened file descriptor is
* closed.
*
* KDBUS_CMD_ENDPOINT_MAKE: Creates a new named special endpoint to talk to
* the bus. Such endpoints usually carry a more
* restrictive policy and grant restricted access
* to specific applications.
* KDBUS_CMD_ENDPOINT_UPDATE: Update the properties of a custom enpoint. Used
* to update the policy.
*
* KDBUS_CMD_HELLO: By opening the bus node, a connection is
* created. After a HELLO the opened connection
* becomes an active peer on the bus.
* KDBUS_CMD_UPDATE: Update the properties of a connection. Used to
* update the metadata subscription mask and
* policy.
* KDBUS_CMD_BYEBYE: Disconnect a connection. If there are no
* messages queued up in the connection's pool,
* the call succeeds, and the handle is rendered
* unusable. Otherwise, -EBUSY is returned without
* any further side-effects.
* KDBUS_CMD_FREE: Release the allocated memory in the receiver's
* pool.
* KDBUS_CMD_CONN_INFO: Retrieve credentials and properties of the
* initial creator of the connection. The data was
* stored at registration time and does not
* necessarily represent the connected process or
* the actual state of the process.
* KDBUS_CMD_BUS_CREATOR_INFO: Retrieve information of the creator of the bus
* a connection is attached to.
*
* KDBUS_CMD_SEND: Send a message and pass data from userspace to
* the kernel.
* KDBUS_CMD_RECV: Receive a message from the kernel which is
* placed in the receiver's pool.
*
* 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_NAME_RELEASE: Release a well-known name the connection
* currently owns.
* KDBUS_CMD_LIST: Retrieve the list of all currently registered
* well-known and unique names.
*
* 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.
*/
enum kdbus_ioctl_type {
/* bus owner (00-0f) */
KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x00,
struct kdbus_cmd),
/* endpoint owner (10-1f) */
KDBUS_CMD_ENDPOINT_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x10,
struct kdbus_cmd),
KDBUS_CMD_ENDPOINT_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x11,
struct kdbus_cmd),
/* connection owner (80-ff) */
KDBUS_CMD_HELLO = _IOWR(KDBUS_IOCTL_MAGIC, 0x80,
struct kdbus_cmd_hello),
KDBUS_CMD_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x81,
struct kdbus_cmd),
KDBUS_CMD_BYEBYE = _IOW(KDBUS_IOCTL_MAGIC, 0x82,
struct kdbus_cmd),
KDBUS_CMD_FREE = _IOW(KDBUS_IOCTL_MAGIC, 0x83,
struct kdbus_cmd_free),
KDBUS_CMD_CONN_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x84,
struct kdbus_cmd_info),
KDBUS_CMD_BUS_CREATOR_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x85,
struct kdbus_cmd_info),
KDBUS_CMD_LIST = _IOR(KDBUS_IOCTL_MAGIC, 0x86,
struct kdbus_cmd_list),
KDBUS_CMD_SEND = _IOW(KDBUS_IOCTL_MAGIC, 0x90,
struct kdbus_cmd_send),
KDBUS_CMD_RECV = _IOR(KDBUS_IOCTL_MAGIC, 0x91,
struct kdbus_cmd_recv),
KDBUS_CMD_NAME_ACQUIRE = _IOW(KDBUS_IOCTL_MAGIC, 0xa0,
struct kdbus_cmd),
KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOCTL_MAGIC, 0xa1,
struct kdbus_cmd),
KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOCTL_MAGIC, 0xb0,
struct kdbus_cmd_match),
KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOCTL_MAGIC, 0xb1,
struct kdbus_cmd_match),
};
#endif /* _UAPI_KDBUS_H_ */

View File

@ -131,17 +131,12 @@ static void bus_free(sd_bus *b) {
bus_close_fds(b);
if (b->kdbus_buffer)
munmap(b->kdbus_buffer, KDBUS_POOL_SIZE);
free(b->label);
free(b->rbuffer);
free(b->unique_name);
free(b->auth_buffer);
free(b->address);
free(b->kernel);
free(b->machine);
free(b->fake_label);
free(b->cgroup_root);
free(b->description);
@ -165,7 +160,7 @@ static void bus_free(sd_bus *b) {
assert(hashmap_isempty(b->nodes));
hashmap_free(b->nodes);
bus_kernel_flush_memfd(b);
bus_flush_memfd(b);
assert_se(pthread_mutex_destroy(&b->memfd_cache_mutex) == 0);
@ -300,8 +295,6 @@ _public_ int sd_bus_negotiate_timestamp(sd_bus *bus, int b) {
return 0;
bus->attach_flags = new_flags;
if (bus->state != BUS_UNSET && bus->is_kernel)
bus_kernel_realize_attach_flags(bus);
return 0;
}
@ -325,8 +318,6 @@ _public_ int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t mask) {
return 0;
bus->attach_flags = new_flags;
if (bus->state != BUS_UNSET && bus->is_kernel)
bus_kernel_realize_attach_flags(bus);
return 0;
}
@ -420,7 +411,7 @@ static int bus_send_hello(sd_bus *bus) {
assert(bus);
if (!bus->bus_client || bus->is_kernel)
if (!bus->bus_client)
return 0;
r = sd_bus_message_new_method_call(
@ -439,7 +430,7 @@ static int bus_send_hello(sd_bus *bus) {
int bus_start_running(sd_bus *bus) {
assert(bus);
if (bus->bus_client && !bus->is_kernel) {
if (bus->bus_client) {
bus->state = BUS_HELLO;
return 1;
}
@ -755,43 +746,6 @@ fail:
return r;
}
static int parse_kernel_address(sd_bus *b, const char **p, char **guid) {
_cleanup_free_ char *path = NULL;
int r;
assert(b);
assert(p);
assert(*p);
assert(guid);
while (**p != 0 && **p != ';') {
r = parse_address_key(p, "guid", guid);
if (r < 0)
return r;
else if (r > 0)
continue;
r = parse_address_key(p, "path", &path);
if (r < 0)
return r;
else if (r > 0)
continue;
skip_address_key(p);
}
if (!path)
return -EINVAL;
free(b->kernel);
b->kernel = path;
path = NULL;
b->is_local = true;
return 0;
}
static int parse_container_unix_address(sd_bus *b, const char **p, char **guid) {
_cleanup_free_ char *machine = NULL, *pid = NULL;
int r;
@ -852,67 +806,6 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
return 0;
}
static int parse_container_kernel_address(sd_bus *b, const char **p, char **guid) {
_cleanup_free_ char *machine = NULL, *pid = NULL;
int r;
assert(b);
assert(p);
assert(*p);
assert(guid);
while (**p != 0 && **p != ';') {
r = parse_address_key(p, "guid", guid);
if (r < 0)
return r;
else if (r > 0)
continue;
r = parse_address_key(p, "machine", &machine);
if (r < 0)
return r;
else if (r > 0)
continue;
r = parse_address_key(p, "pid", &pid);
if (r < 0)
return r;
else if (r > 0)
continue;
skip_address_key(p);
}
if (!machine == !pid)
return -EINVAL;
if (machine) {
if (!machine_name_is_valid(machine))
return -EINVAL;
free(b->machine);
b->machine = machine;
machine = NULL;
} else {
b->machine = mfree(b->machine);
}
if (pid) {
r = parse_pid(pid, &b->nspid);
if (r < 0)
return r;
} else
b->nspid = 0;
r = free_and_strdup(&b->kernel, "/sys/fs/kdbus/0-system/bus");
if (r < 0)
return r;
b->is_local = false;
return 0;
}
static void bus_reset_parsed_address(sd_bus *b) {
assert(b);
@ -921,7 +814,6 @@ static void bus_reset_parsed_address(sd_bus *b) {
b->exec_argv = strv_free(b->exec_argv);
b->exec_path = mfree(b->exec_path);
b->server_id = SD_ID128_NULL;
b->kernel = mfree(b->kernel);
b->machine = mfree(b->machine);
b->nspid = 0;
}
@ -975,14 +867,6 @@ static int bus_parse_next_address(sd_bus *b) {
break;
} else if (startswith(a, "kernel:")) {
a += 7;
r = parse_kernel_address(b, &a, &guid);
if (r < 0)
return r;
break;
} else if (startswith(a, "x-machine-unix:")) {
a += 15;
@ -990,14 +874,6 @@ static int bus_parse_next_address(sd_bus *b) {
if (r < 0)
return r;
break;
} else if (startswith(a, "x-machine-kernel:")) {
a += 17;
r = parse_container_kernel_address(b, &a, &guid);
if (r < 0)
return r;
break;
}
@ -1017,68 +893,43 @@ static int bus_parse_next_address(sd_bus *b) {
}
static int bus_start_address(sd_bus *b) {
bool container_kdbus_available = false;
bool kdbus_available = false;
int r;
assert(b);
for (;;) {
bool skipped = false;
bus_close_fds(b);
/*
* Usually, if you provide multiple different bus-addresses, we
* try all of them in order. We use the first one that
* succeeds. However, if you mix kernel and unix addresses, we
* never try unix-addresses if a previous kernel address was
* tried and kdbus was available. This is required to prevent
* clients to fallback to the bus-proxy if kdbus is available
* but failed (eg., too many connections).
*/
/* If you provide multiple different bus-addresses, we
* try all of them in order and use the first one that
* succeeds. */
if (b->exec_path)
r = bus_socket_exec(b);
else if ((b->nspid > 0 || b->machine) && b->kernel) {
r = bus_container_connect_kernel(b);
if (r < 0 && !IN_SET(r, -ENOENT, -ESOCKTNOSUPPORT))
container_kdbus_available = true;
} else if ((b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC) {
if (!container_kdbus_available)
r = bus_container_connect_socket(b);
else
skipped = true;
else if ((b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC)
r = bus_container_connect_socket(b);
} else if (b->kernel) {
r = bus_kernel_connect(b);
if (r < 0 && !IN_SET(r, -ENOENT, -ESOCKTNOSUPPORT))
kdbus_available = true;
else if (b->sockaddr.sa.sa_family != AF_UNSPEC)
r = bus_socket_connect(b);
} else if (b->sockaddr.sa.sa_family != AF_UNSPEC) {
if (!kdbus_available)
r = bus_socket_connect(b);
else
skipped = true;
} else
skipped = true;
else
goto next;
if (!skipped) {
if (r >= 0) {
r = attach_io_events(b);
if (r >= 0)
return r;
}
b->last_connect_error = -r;
if (r >= 0) {
r = attach_io_events(b);
if (r >= 0)
return r;
}
b->last_connect_error = -r;
next:
r = bus_parse_next_address(b);
if (r < 0)
return r;
if (r == 0)
return b->last_connect_error ? -b->last_connect_error : -ECONNREFUSED;
return b->last_connect_error > 0 ? -b->last_connect_error : -ECONNREFUSED;
}
}
@ -1118,10 +969,7 @@ static int bus_start_fd(sd_bus *b) {
if (fstat(b->input_fd, &st) < 0)
return -errno;
if (S_ISCHR(b->input_fd))
return bus_kernel_take_fd(b);
else
return bus_socket_take_fd(b);
return bus_socket_take_fd(b);
}
_public_ int sd_bus_start(sd_bus *bus) {
@ -1138,7 +986,7 @@ _public_ int sd_bus_start(sd_bus *bus) {
if (bus->input_fd >= 0)
r = bus_start_fd(bus);
else if (bus->address || bus->sockaddr.sa.sa_family != AF_UNSPEC || bus->exec_path || bus->kernel || bus->machine)
else if (bus->address || bus->sockaddr.sa.sa_family != AF_UNSPEC || bus->exec_path || bus->machine)
r = bus_start_address(bus);
else
return -EINVAL;
@ -1256,8 +1104,7 @@ fail:
int bus_set_address_user(sd_bus *b) {
const char *e;
uid_t uid;
int r;
_cleanup_free_ char *ee = NULL, *s = NULL;
assert(b);
@ -1265,25 +1112,20 @@ int bus_set_address_user(sd_bus *b) {
if (e)
return sd_bus_set_address(b, e);
r = cg_pid_get_owner_uid(0, &uid);
if (r < 0)
uid = getuid();
e = secure_getenv("XDG_RUNTIME_DIR");
if (e) {
_cleanup_free_ char *ee = NULL;
if (!e)
return -ENOENT;
ee = bus_address_escape(e);
if (!ee)
return -ENOMEM;
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, uid, ee);
} else
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT, uid);
if (!b->address)
ee = bus_address_escape(e);
if (!ee)
return -ENOMEM;
if (asprintf(&s, UNIX_USER_BUS_ADDRESS_FMT, ee) < 0)
return -ENOMEM;
b->address = s;
s = NULL;
return 0;
}
@ -1403,7 +1245,7 @@ int bus_set_address_system_machine(sd_bus *b, const char *machine) {
if (!e)
return -ENOMEM;
b->address = strjoin("x-machine-kernel:machine=", e, ";x-machine-unix:machine=", e);
b->address = strjoin("x-machine-unix:machine=", e);
if (!b->address)
return -ENOMEM;
@ -1460,13 +1302,7 @@ _public_ void sd_bus_close(sd_bus *bus) {
* the bus object and the bus may be freed */
bus_reset_queues(bus);
if (!bus->is_kernel)
bus_close_fds(bus);
/* We'll leave the fd open in case this is a kernel bus, since
* there might still be memblocks around that reference this
* bus, and they might need to invoke the KDBUS_CMD_FREE
* ioctl on the fd when they are freed. */
bus_close_fds(bus);
}
_public_ sd_bus* sd_bus_flush_close_unref(sd_bus *bus) {
@ -1594,14 +1430,6 @@ static int bus_remarshal_message(sd_bus *b, sd_bus_message **m) {
if (b->message_endian != 0 && b->message_endian != (*m)->header->endian)
remarshal = true;
/* TODO: kdbus-messages received from the kernel contain data which is
* not allowed to be passed to KDBUS_CMD_SEND. Therefore, we have to
* force remarshaling of the message. Technically, we could just
* recreate the kdbus message, but that is non-trivial as other parts of
* the message refer to m->kdbus already. This should be fixed! */
if ((*m)->kdbus && (*m)->release_kdbus)
remarshal = true;
return remarshal ? bus_message_remarshal(b, m) : 0;
}
@ -1635,15 +1463,11 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
assert(bus);
assert(m);
if (bus->is_kernel)
r = bus_kernel_write_message(bus, m, hint_sync_call);
else
r = bus_socket_write_message(bus, m, idx);
r = bus_socket_write_message(bus, m, idx);
if (r <= 0)
return r;
if (bus->is_kernel || *idx >= BUS_MESSAGE_SIZE(m))
if (*idx >= BUS_MESSAGE_SIZE(m))
log_debug("Sent message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s",
bus_message_type_to_string(m->header->type),
strna(sd_bus_message_get_sender(m)),
@ -1672,7 +1496,7 @@ static int dispatch_wqueue(sd_bus *bus) {
else if (r == 0)
/* Didn't do anything this time */
return ret;
else if (bus->is_kernel || bus->windex >= BUS_MESSAGE_SIZE(bus->wqueue[0])) {
else if (bus->windex >= BUS_MESSAGE_SIZE(bus->wqueue[0])) {
/* Fully written. Let's drop the entry from
* the queue.
*
@ -1698,10 +1522,7 @@ static int dispatch_wqueue(sd_bus *bus) {
static int bus_read_message(sd_bus *bus, bool hint_priority, int64_t priority) {
assert(bus);
if (bus->is_kernel)
return bus_kernel_read_message(bus, hint_priority, priority);
else
return bus_socket_read_message(bus);
return bus_socket_read_message(bus);
}
int bus_rqueue_make_room(sd_bus *bus) {
@ -1758,7 +1579,6 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
bus = m->bus;
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS);
if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;
@ -1804,7 +1624,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
return r;
}
if (!bus->is_kernel && idx < BUS_MESSAGE_SIZE(m)) {
if (idx < BUS_MESSAGE_SIZE(m)) {
/* Wasn't fully written. So let's remember how
* much was written. Note that the first entry
* of the wqueue array is always allocated so
@ -1910,7 +1730,6 @@ _public_ int sd_bus_call_async(
bus = m->bus;
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS);
if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;
@ -2011,7 +1830,6 @@ _public_ int sd_bus_call(
bus = m->bus;
bus_assert_return(!bus_pid_changed(bus), -ECHILD, error);
bus_assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS, error);
if (!BUS_IS_OPEN(bus->state)) {
r = -ENOTCONN;
@ -2330,9 +2148,6 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
m->header->type != SD_BUS_MESSAGE_METHOD_ERROR)
return 0;
if (bus->is_kernel && (bus->hello_flags & KDBUS_HELLO_MONITOR))
return 0;
if (m->destination && bus->unique_name && !streq_ptr(m->destination, bus->unique_name))
return 0;
@ -3054,20 +2869,16 @@ _public_ int sd_bus_add_match(
scope = bus_match_get_scope(components, n_components);
/* Do not install server-side matches for matches
* against the local service, interface or bus
* path. */
* against the local service, interface or bus path. */
if (scope != BUS_MATCH_LOCAL) {
if (!bus->is_kernel) {
/* When this is not a kernel transport, we
* store the original match string, so that we
* can use it to remove the match again */
/* We store the original match string, so that
* we can use it to remove the match again. */
s->match_callback.match_string = strdup(match);
if (!s->match_callback.match_string) {
r = -ENOMEM;
goto finish;
}
s->match_callback.match_string = strdup(match);
if (!s->match_callback.match_string) {
r = -ENOMEM;
goto finish;
}
r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components, s->match_callback.cookie);
@ -3683,29 +3494,10 @@ _public_ int sd_bus_path_decode_many(const char *path, const char *path_template
}
_public_ int sd_bus_try_close(sd_bus *bus) {
int r;
assert_return(bus, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
if (!bus->is_kernel)
return -EOPNOTSUPP;
if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;
if (bus->rqueue_size > 0)
return -EBUSY;
if (bus->wqueue_size > 0)
return -EBUSY;
r = bus_kernel_try_close(bus);
if (r < 0)
return r;
sd_bus_close(bus);
return 0;
return -EOPNOTSUPP;
}
_public_ int sd_bus_get_description(sd_bus *bus, const char **description) {
@ -3737,32 +3529,10 @@ int bus_get_root_path(sd_bus *bus) {
}
_public_ int sd_bus_get_scope(sd_bus *bus, const char **scope) {
int r;
assert_return(bus, -EINVAL);
assert_return(scope, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
if (bus->is_kernel) {
_cleanup_free_ char *n = NULL;
const char *dash;
r = bus_kernel_get_bus_name(bus, &n);
if (r < 0)
return r;
if (streq(n, "0-system")) {
*scope = "system";
return 0;
}
dash = strchr(n, '-');
if (streq_ptr(dash, "-user")) {
*scope = "user";
return 0;
}
}
if (bus->is_user) {
*scope = "user";
return 0;

View File

@ -35,7 +35,6 @@
static usec_t arg_loop_usec = 100 * USEC_PER_MSEC;
typedef enum Type {
TYPE_KDBUS,
TYPE_LEGACY,
TYPE_DIRECT,
} Type;
@ -190,9 +189,6 @@ static void client_chart(Type type, const char *address, const char *server_name
assert_se(r >= 0);
switch (type) {
case TYPE_KDBUS:
printf("SIZE\tCOPY\tMEMFD\n");
break;
case TYPE_LEGACY:
printf("SIZE\tLEGACY\n");
break;
@ -203,25 +199,10 @@ static void client_chart(Type type, const char *address, const char *server_name
for (csize = 1; csize <= MAX_SIZE; csize *= 2) {
usec_t t;
unsigned n_copying, n_memfd;
unsigned n_memfd;
printf("%zu\t", csize);
if (type == TYPE_KDBUS) {
b->use_memfd = 0;
t = now(CLOCK_MONOTONIC);
for (n_copying = 0;; n_copying++) {
transaction(b, csize, server_name);
if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec)
break;
}
printf("%u\t", (unsigned) ((n_copying * USEC_PER_SEC) / arg_loop_usec));
b->use_memfd = -1;
}
t = now(CLOCK_MONOTONIC);
for (n_memfd = 0;; n_memfd++) {
transaction(b, csize, server_name);
@ -245,7 +226,7 @@ int main(int argc, char *argv[]) {
MODE_BISECT,
MODE_CHART,
} mode = MODE_BISECT;
Type type = TYPE_KDBUS;
Type type = TYPE_LEGACY;
int i, pair[2] = { -1, -1 };
_cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL, *server_name = NULL;
_cleanup_close_ int bus_ref = -1;
@ -271,22 +252,9 @@ int main(int argc, char *argv[]) {
assert_se(parse_sec(argv[i], &arg_loop_usec) >= 0);
}
assert_se(!MODE_BISECT || TYPE_KDBUS);
assert_se(arg_loop_usec > 0);
if (type == TYPE_KDBUS) {
assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid_cached()) >= 0);
bus_ref = bus_kernel_create_bus(name, false, &bus_name);
if (bus_ref == -ENOENT)
exit(EXIT_TEST_SKIP);
assert_se(bus_ref >= 0);
address = strappend("kernel:path=", bus_name);
assert_se(address);
} else if (type == TYPE_LEGACY) {
if (type == TYPE_LEGACY) {
const char *e;
e = secure_getenv("DBUS_SESSION_BUS_ADDRESS");

View File

@ -1,141 +0,0 @@
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-bus.h"
#include "alloc-util.h"
#include "bus-kernel.h"
#include "bus-util.h"
#include "fd-util.h"
#include "log.h"
#include "util.h"
static int test_match(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
int *found = userdata;
*found = 1;
return 0;
}
static void test_one(
const char *path,
const char *interface,
const char *member,
bool as_list,
const char *arg0,
const char *match,
bool good) {
_cleanup_close_ int bus_ref = -1;
_cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
sd_bus *a, *b;
int r, found = 0;
assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid_cached()) >= 0);
bus_ref = bus_kernel_create_bus(name, false, &bus_name);
if (bus_ref == -ENOENT)
exit(EXIT_TEST_SKIP);
assert_se(bus_ref >= 0);
address = strappend("kernel:path=", bus_name);
assert_se(address);
r = sd_bus_new(&a);
assert_se(r >= 0);
r = sd_bus_new(&b);
assert_se(r >= 0);
r = sd_bus_set_address(a, address);
assert_se(r >= 0);
r = sd_bus_set_address(b, address);
assert_se(r >= 0);
r = sd_bus_start(a);
assert_se(r >= 0);
r = sd_bus_start(b);
assert_se(r >= 0);
log_debug("match");
r = sd_bus_add_match(b, NULL, match, test_match, &found);
assert_se(r >= 0);
log_debug("signal");
if (as_list)
r = sd_bus_emit_signal(a, path, interface, member, "as", 1, arg0);
else
r = sd_bus_emit_signal(a, path, interface, member, "s", arg0);
assert_se(r >= 0);
r = sd_bus_process(b, &m);
assert_se(r >= 0 && good == !!found);
sd_bus_unref(a);
sd_bus_unref(b);
}
int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/tuut'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "interface='waldo.com'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "member='Piep'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "member='Pi_ep'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "arg0='foobar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "arg0='foo_bar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0='foobar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0='foo_bar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0has='foobar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0has='foo_bar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar2'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/quux'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar/waldo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/quux'", false);
test_one("/", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar/waldo/'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/bar/waldo", "arg0path='/foo/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo/bar/waldo'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/", "arg0path='/foo/bar/waldo'", true);
return 0;
}

View File

@ -1,190 +0,0 @@
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include "sd-bus.h"
#include "alloc-util.h"
#include "bus-dump.h"
#include "bus-kernel.h"
#include "bus-util.h"
#include "fd-util.h"
#include "log.h"
#include "util.h"
int main(int argc, char *argv[]) {
_cleanup_close_ int bus_ref = -1;
_cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL, *bname = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
const char *ua = NULL, *ub = NULL, *the_string = NULL;
sd_bus *a, *b;
int r, pipe_fds[2];
const char *nn;
log_set_max_level(LOG_DEBUG);
assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid_cached()) >= 0);
bus_ref = bus_kernel_create_bus(name, false, &bus_name);
if (bus_ref == -ENOENT)
return EXIT_TEST_SKIP;
assert_se(bus_ref >= 0);
address = strappend("kernel:path=", bus_name);
assert_se(address);
r = sd_bus_new(&a);
assert_se(r >= 0);
r = sd_bus_new(&b);
assert_se(r >= 0);
r = sd_bus_set_description(a, "a");
assert_se(r >= 0);
r = sd_bus_set_address(a, address);
assert_se(r >= 0);
r = sd_bus_set_address(b, address);
assert_se(r >= 0);
assert_se(sd_bus_negotiate_timestamp(a, 1) >= 0);
assert_se(sd_bus_negotiate_creds(a, true, _SD_BUS_CREDS_ALL) >= 0);
assert_se(sd_bus_negotiate_timestamp(b, 0) >= 0);
assert_se(sd_bus_negotiate_creds(b, true, 0) >= 0);
r = sd_bus_start(a);
assert_se(r >= 0);
r = sd_bus_start(b);
assert_se(r >= 0);
assert_se(sd_bus_negotiate_timestamp(b, 1) >= 0);
assert_se(sd_bus_negotiate_creds(b, true, _SD_BUS_CREDS_ALL) >= 0);
r = sd_bus_get_unique_name(a, &ua);
assert_se(r >= 0);
printf("unique a: %s\n", ua);
r = sd_bus_get_description(a, &nn);
assert_se(r >= 0);
printf("name of a: %s\n", nn);
r = sd_bus_get_unique_name(b, &ub);
assert_se(r >= 0);
printf("unique b: %s\n", ub);
r = sd_bus_get_description(b, &nn);
assert_se(r >= 0);
printf("name of b: %s\n", nn);
assert_se(bus_kernel_get_bus_name(b, &bname) >= 0);
assert_se(endswith(bname, name));
r = sd_bus_call_method(a, "this.doesnt.exist", "/foo", "meh.mah", "muh", &error, NULL, "s", "yayayay");
assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_SERVICE_UNKNOWN));
assert_se(r == -EHOSTUNREACH);
r = sd_bus_add_match(b, NULL, "interface='waldo.com',member='Piep'", NULL, NULL);
assert_se(r >= 0);
r = sd_bus_emit_signal(a, "/foo/bar/waldo", "waldo.com", "Piep", "sss", "I am a string", "/this/is/a/path", "and.this.a.domain.name");
assert_se(r >= 0);
r = sd_bus_try_close(b);
assert_se(r == -EBUSY);
r = sd_bus_process_priority(b, -10, &m);
assert_se(r == 0);
r = sd_bus_process(b, &m);
assert_se(r > 0);
assert_se(m);
bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
assert_se(sd_bus_message_rewind(m, true) >= 0);
r = sd_bus_message_read(m, "s", &the_string);
assert_se(r >= 0);
assert_se(streq(the_string, "I am a string"));
sd_bus_message_unref(m);
m = NULL;
r = sd_bus_request_name(a, "net.x0pointer.foobar", 0);
assert_se(r >= 0);
r = sd_bus_message_new_method_call(b, &m, "net.x0pointer.foobar", "/a/path", "an.inter.face", "AMethod");
assert_se(r >= 0);
assert_se(pipe2(pipe_fds, O_CLOEXEC) >= 0);
assert_se(write(pipe_fds[1], "x", 1) == 1);
pipe_fds[1] = safe_close(pipe_fds[1]);
r = sd_bus_message_append(m, "h", pipe_fds[0]);
assert_se(r >= 0);
pipe_fds[0] = safe_close(pipe_fds[0]);
r = sd_bus_send(b, m, NULL);
assert_se(r >= 0);
for (;;) {
sd_bus_message_unref(m);
m = NULL;
r = sd_bus_process(a, &m);
assert_se(r > 0);
assert_se(m);
bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
assert_se(sd_bus_message_rewind(m, true) >= 0);
if (sd_bus_message_is_method_call(m, "an.inter.face", "AMethod")) {
int fd;
char x;
r = sd_bus_message_read(m, "h", &fd);
assert_se(r >= 0);
assert_se(read(fd, &x, 1) == 1);
assert_se(x == 'x');
break;
}
}
r = sd_bus_release_name(a, "net.x0pointer.foobar");
assert_se(r >= 0);
r = sd_bus_release_name(a, "net.x0pointer.foobar");
assert_se(r == -ESRCH);
r = sd_bus_try_close(a);
assert_se(r >= 0);
sd_bus_unref(a);
sd_bus_unref(b);
return 0;
}

View File

@ -1,210 +0,0 @@
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/mman.h>
#include "sd-bus.h"
#include "alloc-util.h"
#include "bus-dump.h"
#include "bus-kernel.h"
#include "bus-message.h"
#include "fd-util.h"
#include "log.h"
#include "memfd-util.h"
#include "string-util.h"
#include "util.h"
#define FIRST_ARRAY 17
#define SECOND_ARRAY 33
#define STRING_SIZE 123
int main(int argc, char *argv[]) {
_cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
const char *unique;
uint8_t *p;
sd_bus *a, *b;
int r, bus_ref;
sd_bus_message *m;
int f;
uint64_t sz;
uint32_t u32;
size_t i, l;
char *s;
_cleanup_close_ int sfd = -1;
log_set_max_level(LOG_DEBUG);
assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid_cached()) >= 0);
bus_ref = bus_kernel_create_bus(name, false, &bus_name);
if (bus_ref == -ENOENT)
return EXIT_TEST_SKIP;
assert_se(bus_ref >= 0);
address = strappend("kernel:path=", bus_name);
assert_se(address);
r = sd_bus_new(&a);
assert_se(r >= 0);
r = sd_bus_new(&b);
assert_se(r >= 0);
r = sd_bus_set_address(a, address);
assert_se(r >= 0);
r = sd_bus_set_address(b, address);
assert_se(r >= 0);
r = sd_bus_start(a);
assert_se(r >= 0);
r = sd_bus_start(b);
assert_se(r >= 0);
r = sd_bus_get_unique_name(a, &unique);
assert_se(r >= 0);
r = sd_bus_message_new_method_call(b, &m, unique, "/a/path", "an.inter.face", "AMethod");
assert_se(r >= 0);
r = sd_bus_message_open_container(m, 'r', "aysay");
assert_se(r >= 0);
r = sd_bus_message_append_array_space(m, 'y', FIRST_ARRAY, (void**) &p);
assert_se(r >= 0);
p[0] = '<';
memset(p+1, 'L', FIRST_ARRAY-2);
p[FIRST_ARRAY-1] = '>';
f = memfd_new_and_map(NULL, STRING_SIZE, (void**) &s);
assert_se(f >= 0);
s[0] = '<';
for (i = 1; i < STRING_SIZE-2; i++)
s[i] = '0' + (i % 10);
s[STRING_SIZE-2] = '>';
s[STRING_SIZE-1] = 0;
munmap(s, STRING_SIZE);
r = memfd_get_size(f, &sz);
assert_se(r >= 0);
assert_se(sz == STRING_SIZE);
r = sd_bus_message_append_string_memfd(m, f, 0, (uint64_t) -1);
assert_se(r >= 0);
close(f);
f = memfd_new_and_map(NULL, SECOND_ARRAY, (void**) &p);
assert_se(f >= 0);
p[0] = '<';
memset(p+1, 'P', SECOND_ARRAY-2);
p[SECOND_ARRAY-1] = '>';
munmap(p, SECOND_ARRAY);
r = memfd_get_size(f, &sz);
assert_se(r >= 0);
assert_se(sz == SECOND_ARRAY);
r = sd_bus_message_append_array_memfd(m, 'y', f, 0, (uint64_t) -1);
assert_se(r >= 0);
close(f);
r = sd_bus_message_close_container(m);
assert_se(r >= 0);
r = sd_bus_message_append(m, "u", 4711);
assert_se(r >= 0);
assert_se((sfd = memfd_new_and_map(NULL, 6, (void**) &p)) >= 0);
memcpy(p, "abcd\0", 6);
munmap(p, 6);
assert_se(sd_bus_message_append_string_memfd(m, sfd, 1, 4) >= 0);
r = bus_message_seal(m, 55, 99*USEC_PER_SEC);
assert_se(r >= 0);
bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
r = sd_bus_send(b, m, NULL);
assert_se(r >= 0);
sd_bus_message_unref(m);
r = sd_bus_process(a, &m);
assert_se(r > 0);
bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
sd_bus_message_rewind(m, true);
r = sd_bus_message_enter_container(m, 'r', "aysay");
assert_se(r > 0);
r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
assert_se(r > 0);
assert_se(l == FIRST_ARRAY);
assert_se(p[0] == '<');
for (i = 1; i < l-1; i++)
assert_se(p[i] == 'L');
assert_se(p[l-1] == '>');
r = sd_bus_message_read(m, "s", &s);
assert_se(r > 0);
assert_se(s[0] == '<');
for (i = 1; i < STRING_SIZE-2; i++)
assert_se(s[i] == (char) ('0' + (i % 10)));
assert_se(s[STRING_SIZE-2] == '>');
assert_se(s[STRING_SIZE-1] == 0);
r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
assert_se(r > 0);
assert_se(l == SECOND_ARRAY);
assert_se(p[0] == '<');
for (i = 1; i < l-1; i++)
assert_se(p[i] == 'P');
assert_se(p[l-1] == '>');
r = sd_bus_message_exit_container(m);
assert_se(r > 0);
r = sd_bus_message_read(m, "u", &u32);
assert_se(r > 0);
assert_se(u32 == 4711);
r = sd_bus_message_read(m, "s", &s);
assert_se(r > 0);
assert_se(streq_ptr(s, "bcd"));
sd_bus_message_unref(m);
sd_bus_unref(a);
sd_bus_unref(b);
return 0;
}

View File

@ -592,28 +592,8 @@ int bus_connect_system_systemd(sd_bus **_bus) {
if (geteuid() != 0)
return sd_bus_default_system(_bus);
/* If we are root and kdbus is not available, then let's talk
* directly to the system instance, instead of going via the
* bus */
r = sd_bus_new(&bus);
if (r < 0)
return r;
r = sd_bus_set_address(bus, KERNEL_SYSTEM_BUS_ADDRESS);
if (r < 0)
return r;
bus->bus_client = true;
r = sd_bus_start(bus);
if (r >= 0) {
*_bus = bus;
bus = NULL;
return 0;
}
bus = sd_bus_unref(bus);
/* If we are root then let's talk directly to the system
* instance, instead of going via the bus */
r = sd_bus_new(&bus);
if (r < 0)
@ -643,28 +623,8 @@ int bus_connect_user_systemd(sd_bus **_bus) {
const char *e;
int r;
/* Try via kdbus first, and then directly */
assert(_bus);
r = sd_bus_new(&bus);
if (r < 0)
return r;
if (asprintf(&bus->address, KERNEL_USER_BUS_ADDRESS_FMT, getuid()) < 0)
return -ENOMEM;
bus->bus_client = true;
r = sd_bus_start(bus);
if (r >= 0) {
*_bus = bus;
bus = NULL;
return 0;
}
bus = sd_bus_unref(bus);
e = secure_getenv("XDG_RUNTIME_DIR");
if (!e)
return sd_bus_default_user(_bus);

View File

@ -756,21 +756,10 @@ tests += [
[],
[]],
[['src/libsystemd/sd-bus/test-bus-kernel.c'],
[],
[]],
[['src/libsystemd/sd-bus/test-bus-kernel-bloom.c'],
[],
[]],
[['src/libsystemd/sd-bus/test-bus-benchmark.c'],
[],
[threads]],
[['src/libsystemd/sd-bus/test-bus-zero-copy.c'],
[],
[]],
[threads],
'', 'manual'],
[['src/libsystemd/sd-bus/test-bus-introspect.c'],
[],

View File

@ -13,8 +13,7 @@ Documentation=https://www.freedesktop.org/wiki/Software/systemd/multiseat
Wants=user.slice
After=nss-user-lookup.target user.slice
# Ask for the dbus socket. If running over kdbus, the socket will
# not be actually used.
# Ask for the dbus socket.
Wants=dbus.socket
After=dbus.socket