[systemd-commits] 3 commits - TODO src/core src/libsystemd
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Nov 25 11:55:44 PST 2014
TODO | 3 -
src/core/busname.c | 82 ++++++++++++++++++++++++++++++++++++-
src/libsystemd/sd-bus/bus-kernel.c | 5 ++
src/libsystemd/sd-bus/kdbus.h | 9 ++--
4 files changed, 92 insertions(+), 7 deletions(-)
New commits:
commit 6363357378e295ee9dfc23e7c5a9f8793b06519c
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 25 20:50:55 2014 +0100
update TODO
diff --git a/TODO b/TODO
index 25fbdaa..87fe30a 100644
--- a/TODO
+++ b/TODO
@@ -35,6 +35,8 @@ External:
Features:
+* kdbus: peeking is subject to a race when we look at a message while the message is being migrated to the implementor's connection. Needs kernel fix, and then we need to invoke the FREE ioctl in busname_peek_message()
+
* kdbus: for some reason "busctl monitor" only shows metadata for signal msgs, never method call or method reply msgs
* add "systemctl start -v foobar.service" that shows logs of a service
@@ -314,7 +316,6 @@ Features:
- when kdbus does not take our message without memfds, try again with memfds
- systemd-bus-proxyd needs to enforce good old XML policy
- allow updating attach flags during runtime
- - pid1: peek into activating message when activating a service
- introduce sd_bus_emit_object_added()/sd_bus_emit_object_removed() that automatically includes the build-in interfaces in the list
- port to sd-resolve for connecting to TCP dbus servers
- see if we can drop more message validation on the sending side
commit bd5f920f1288c0d4d488629fadf067f709227030
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 25 19:32:48 2014 +0100
core: show log message about process triggering kdbus service activation
diff --git a/src/core/busname.c b/src/core/busname.c
index 68cb6ca..1583d57 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <sys/mman.h>
+
#include "special.h"
#include "bus-kernel.h"
#include "bus-internal.h"
@@ -26,6 +28,7 @@
#include "service.h"
#include "dbus-busname.h"
#include "busname.h"
+#include "kdbus.h"
static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
[BUSNAME_DEAD] = UNIT_INACTIVE,
@@ -301,8 +304,7 @@ static int busname_open_fd(BusName *n) {
mode = UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user";
n->starter_fd = bus_kernel_open_bus_fd(mode, &path);
if (n->starter_fd < 0) {
- log_warning_unit(UNIT(n)->id, "Failed to open %s: %s",
- path ?: "kdbus", strerror(-n->starter_fd));
+ log_warning_unit(UNIT(n)->id, "Failed to open %s: %s", path ?: "kdbus", strerror(-n->starter_fd));
return n->starter_fd;
}
@@ -725,6 +727,81 @@ _pure_ static const char *busname_sub_state_to_string(Unit *u) {
return busname_state_to_string(BUSNAME(u)->state);
}
+static int busname_peek_message(BusName *n) {
+ struct kdbus_cmd_recv cmd_recv = {
+ .flags = KDBUS_RECV_PEEK,
+ };
+ const char *comm = NULL;
+ struct kdbus_item *d;
+ struct kdbus_msg *k;
+ size_t start, ps, sz, delta;
+ void *p = NULL;
+ pid_t pid = 0;
+ int r;
+
+ assert(n);
+
+ /* Generate a friendly log message about which process caused
+ * triggering of this bus name. This simply peeks the metadata
+ * of the first queued message and logs it. */
+
+ r = ioctl(n->starter_fd, KDBUS_CMD_MSG_RECV, &cmd_recv);
+ if (r < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ return 0;
+
+ log_error_unit(UNIT(n)->id, "%s: Failed to query activation message: %m", UNIT(n)->id);
+ return -errno;
+ }
+
+ /* We map as late as possible, and unmap imemdiately after
+ * use. On 32bit address space is scarce and we want to be
+ * able to handle a lot of activator connections at the same
+ * time, and hence shouldn't keep the mmap()s around for
+ * longer than necessary. */
+
+ ps = page_size();
+ start = (cmd_recv.offset / ps) * ps;
+ delta = cmd_recv.offset - start;
+ sz = PAGE_ALIGN(delta + cmd_recv.msg_size);
+
+ p = mmap(NULL, sz, PROT_READ, MAP_SHARED, n->starter_fd, start);
+ if (p == MAP_FAILED) {
+ log_error_unit(UNIT(n)->id, "%s: Failed to map activation message: %m", UNIT(n)->id);
+ r = -errno;
+ goto finish;
+ }
+
+ k = (struct kdbus_msg *) ((uint8_t *) p + delta);
+ KDBUS_ITEM_FOREACH(d, k, items) {
+ switch (d->type) {
+
+ case KDBUS_ITEM_PIDS:
+ pid = d->pids.pid;
+ break;
+
+ case KDBUS_ITEM_PID_COMM:
+ comm = d->str;
+ break;
+ }
+ }
+
+ if (pid > 0)
+ log_debug_unit(UNIT(n)->id, "%s: Activation triggered by process " PID_FMT " (%s)", UNIT(n)->id, pid, strna(comm));
+
+ r = 0;
+
+finish:
+ if (p)
+ (void) munmap(p, sz);
+
+ /* Hint: we don't invoke KDBUS_CMD_MSG_FREE here, as we only
+ * PEEKed the message, and didn't ask for it to be dropped
+ * from the queue. */
+
+ return r;
+}
+
static int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
BusName *n = userdata;
@@ -742,6 +819,7 @@ static int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents
goto fail;
}
+ busname_peek_message(n);
busname_enter_running(n);
return 0;
fail:
diff --git a/src/libsystemd/sd-bus/kdbus.h b/src/libsystemd/sd-bus/kdbus.h
index ae900c2..3e841f4 100644
--- a/src/libsystemd/sd-bus/kdbus.h
+++ b/src/libsystemd/sd-bus/kdbus.h
@@ -494,10 +494,11 @@ enum kdbus_recv_flags {
* broadcast messages that have been lost since the
* last call.
* @msg_size: Filled by the kernel with the actual message size. This
- * mirrors the 'size' member of the message stored at
- * @offset, but allows callers to access it without mapping
- * their pool. By using @msg_size and @offset, you can map
- * only the message itself, not the whole pool.
+ * is the full size of the slice placed at @offset. It
+ * includes the memory used for the kdbus_msg object, but
+ * also for all appended VECs. By using @msg_size and
+ * @offset, you can map a single message, instead of
+ * mapping the whole pool.
*
* This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
*/
commit f9a458c66672992dd34ad0c7cfec3795b897d711
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 25 19:54:18 2014 +0100
sd-bus: react properly to EOVERFLOW by generating a log message about dropped broadcast messages and proceeding
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 0927d82..e03e447 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -1185,6 +1185,11 @@ int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority) {
if (errno == EAGAIN)
return 0;
+ if (errno == EOVERFLOW) {
+ log_debug("%s: kdbus reports %" PRIu64 " dropped broadcast messages, ignoring.", strna(bus->description), (uint64_t) recv.dropped_msgs);
+ return 0;
+ }
+
return -errno;
}
More information about the systemd-commits
mailing list