[systemd-devel] [PATCH 2/7] libsystemd-bus: query minimum buffer size for KDBUS_CMD_NAME_QUERY
Daniel Mack
zonque at gmail.com
Fri Nov 15 10:32:18 PST 2013
When starting in kernel mode, determine the minimum buffer size for
subsequent KDBUS_CMD_NAME_QUERY calls. The value returned by kdbus is
dependant on kernel config settings and may vary from system to system
and also in the future, but it is fix for a bus lifetime.
---
src/libsystemd-bus/bus-internal.h | 3 +++
src/libsystemd-bus/bus-kernel.c | 11 +++++++++++
2 files changed, 14 insertions(+)
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index 4f9d941..088bdad 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -226,6 +226,9 @@ struct sd_bus {
void *kdbus_buffer;
+ /* Minimum buffer size for KDBUS_CMD_NAME_QUERY calls */
+ size_t name_query_min_size;
+
/* 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
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 3ea85d4..94eabfc 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -314,6 +314,7 @@ fail:
int bus_kernel_take_fd(sd_bus *b) {
struct kdbus_cmd_hello hello;
+ struct kdbus_cmd_name_info dummy_info;
int r;
assert(b);
@@ -356,6 +357,16 @@ int bus_kernel_take_fd(sd_bus *b) {
b->bus_client = true;
b->can_fds = !!(hello.conn_flags & KDBUS_HELLO_ACCEPT_FD);
+ /* Send a NAME_QUERY with an empty info struct. That will tell us the
+ * size of the return buffer that we have to provide for future name
+ * queries. */
+ zero(dummy_info);
+ r = ioctl(b->input_fd, KDBUS_CMD_NAME_QUERY, &dummy_info);
+ if (r < 0 && errno != EMSGSIZE)
+ return -errno;
+
+ b->name_query_min_size = dummy_info.size;
+
r = bus_start_running(b);
if (r < 0)
return r;
--
1.8.4.2
More information about the systemd-devel
mailing list