From 998aa62a21c69b34700f6cbbeb540beddffa9c89 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Thu, 12 Jun 2025 16:20:29 +0200 Subject: [PATCH] sd-bus: Preserve interfaces addition order When adding a new interface to the object add it at the end of the list. This way, when iterating over the list, e.g., during handling introspect call, the order of returned interfaces will mach the order in which they were added. --- src/libsystemd/sd-bus/bus-objects.c | 3 +++ test/units/TEST-23-UNIT-FILE.oneshot-restart.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index 7309ad621a0..cc1ef226f0c 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -1973,6 +1973,9 @@ static int add_object_vtable_internal( } } + if (!existing) + existing = LIST_FIND_TAIL(vtables, n->vtables); + s->node_vtable.node = n; LIST_INSERT_AFTER(vtables, n->vtables, existing, &s->node_vtable); bus->nodes_modified = true; diff --git a/test/units/TEST-23-UNIT-FILE.oneshot-restart.sh b/test/units/TEST-23-UNIT-FILE.oneshot-restart.sh index d06dbaae8cf..b5a4d2d30a7 100755 --- a/test/units/TEST-23-UNIT-FILE.oneshot-restart.sh +++ b/test/units/TEST-23-UNIT-FILE.oneshot-restart.sh @@ -90,9 +90,9 @@ read -r x <"$FIFO_FILE" assert_eq "$x" "finished" cmp -b <(systemctl show "$UNIT_NAME" -p Result -p NRestarts -p SubState) <