|
|
8d419f |
From 52af91cfd0eece566cb2b6877e622b16289525a4 Mon Sep 17 00:00:00 2001
|
|
|
8d419f |
From: Jan Janssen <medhefgo@web.de>
|
|
|
8d419f |
Date: Wed, 19 Jan 2022 10:15:36 +0100
|
|
|
8d419f |
Subject: [PATCH] bus: Use OrderedSet for introspection
|
|
|
8d419f |
|
|
|
8d419f |
Otherwise, the generated xml files are not reproducible.
|
|
|
8d419f |
|
|
|
8d419f |
(cherry picked from commit acac88340ace3cd631126eebb6d0390cd54e8231)
|
|
|
8d419f |
|
|
|
8d419f |
Resolves: #2068131
|
|
|
8d419f |
---
|
|
|
8d419f |
src/libsystemd/sd-bus/bus-introspect.c | 4 +--
|
|
|
8d419f |
src/libsystemd/sd-bus/bus-introspect.h | 4 +--
|
|
|
8d419f |
src/libsystemd/sd-bus/bus-objects.c | 45 +++++++++++++-------------
|
|
|
8d419f |
src/shared/bus-object.c | 4 +--
|
|
|
8d419f |
4 files changed, 28 insertions(+), 29 deletions(-)
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/libsystemd/sd-bus/bus-introspect.c b/src/libsystemd/sd-bus/bus-introspect.c
|
|
|
8d419f |
index b9ef6af631..eed0dae82f 100644
|
|
|
8d419f |
--- a/src/libsystemd/sd-bus/bus-introspect.c
|
|
|
8d419f |
+++ b/src/libsystemd/sd-bus/bus-introspect.c
|
|
|
8d419f |
@@ -110,7 +110,7 @@ static int set_interface_name(struct introspect *intro, const char *interface_na
|
|
|
8d419f |
return free_and_strdup(&intro->interface_name, interface_name);
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
-int introspect_write_child_nodes(struct introspect *i, Set *s, const char *prefix) {
|
|
|
8d419f |
+int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char *prefix) {
|
|
|
8d419f |
char *node;
|
|
|
8d419f |
|
|
|
8d419f |
assert(i);
|
|
|
8d419f |
@@ -118,7 +118,7 @@ int introspect_write_child_nodes(struct introspect *i, Set *s, const char *prefi
|
|
|
8d419f |
|
|
|
8d419f |
assert_se(set_interface_name(i, NULL) >= 0);
|
|
|
8d419f |
|
|
|
8d419f |
- while ((node = set_steal_first(s))) {
|
|
|
8d419f |
+ while ((node = ordered_set_steal_first(s))) {
|
|
|
8d419f |
const char *e;
|
|
|
8d419f |
|
|
|
8d419f |
e = object_path_startswith(node, prefix);
|
|
|
8d419f |
diff --git a/src/libsystemd/sd-bus/bus-introspect.h b/src/libsystemd/sd-bus/bus-introspect.h
|
|
|
8d419f |
index 34f32a4cf9..19e3ef09e2 100644
|
|
|
8d419f |
--- a/src/libsystemd/sd-bus/bus-introspect.h
|
|
|
8d419f |
+++ b/src/libsystemd/sd-bus/bus-introspect.h
|
|
|
8d419f |
@@ -5,7 +5,7 @@
|
|
|
8d419f |
|
|
|
8d419f |
#include "sd-bus.h"
|
|
|
8d419f |
|
|
|
8d419f |
-#include "set.h"
|
|
|
8d419f |
+#include "ordered-set.h"
|
|
|
8d419f |
|
|
|
8d419f |
struct introspect {
|
|
|
8d419f |
FILE *f;
|
|
|
8d419f |
@@ -17,7 +17,7 @@ struct introspect {
|
|
|
8d419f |
|
|
|
8d419f |
int introspect_begin(struct introspect *i, bool trusted);
|
|
|
8d419f |
int introspect_write_default_interfaces(struct introspect *i, bool object_manager);
|
|
|
8d419f |
-int introspect_write_child_nodes(struct introspect *i, Set *s, const char *prefix);
|
|
|
8d419f |
+int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char *prefix);
|
|
|
8d419f |
int introspect_write_interface(
|
|
|
8d419f |
struct introspect *i,
|
|
|
8d419f |
const char *interface_name,
|
|
|
8d419f |
diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c
|
|
|
8d419f |
index bf69539062..40158a7326 100644
|
|
|
8d419f |
--- a/src/libsystemd/sd-bus/bus-objects.c
|
|
|
8d419f |
+++ b/src/libsystemd/sd-bus/bus-objects.c
|
|
|
8d419f |
@@ -9,7 +9,6 @@
|
|
|
8d419f |
#include "bus-slot.h"
|
|
|
8d419f |
#include "bus-type.h"
|
|
|
8d419f |
#include "missing_capability.h"
|
|
|
8d419f |
-#include "set.h"
|
|
|
8d419f |
#include "string-util.h"
|
|
|
8d419f |
#include "strv.h"
|
|
|
8d419f |
|
|
|
8d419f |
@@ -99,7 +98,7 @@ static int add_enumerated_to_set(
|
|
|
8d419f |
sd_bus *bus,
|
|
|
8d419f |
const char *prefix,
|
|
|
8d419f |
struct node_enumerator *first,
|
|
|
8d419f |
- Set *s,
|
|
|
8d419f |
+ OrderedSet *s,
|
|
|
8d419f |
sd_bus_error *error) {
|
|
|
8d419f |
|
|
|
8d419f |
struct node_enumerator *c;
|
|
|
8d419f |
@@ -146,7 +145,7 @@ static int add_enumerated_to_set(
|
|
|
8d419f |
continue;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
- r = set_consume(s, *k);
|
|
|
8d419f |
+ r = ordered_set_consume(s, *k);
|
|
|
8d419f |
if (r == -EEXIST)
|
|
|
8d419f |
r = 0;
|
|
|
8d419f |
}
|
|
|
8d419f |
@@ -171,7 +170,7 @@ static int add_subtree_to_set(
|
|
|
8d419f |
const char *prefix,
|
|
|
8d419f |
struct node *n,
|
|
|
8d419f |
unsigned flags,
|
|
|
8d419f |
- Set *s,
|
|
|
8d419f |
+ OrderedSet *s,
|
|
|
8d419f |
sd_bus_error *error) {
|
|
|
8d419f |
|
|
|
8d419f |
struct node *i;
|
|
|
8d419f |
@@ -198,7 +197,7 @@ static int add_subtree_to_set(
|
|
|
8d419f |
if (!t)
|
|
|
8d419f |
return -ENOMEM;
|
|
|
8d419f |
|
|
|
8d419f |
- r = set_consume(s, t);
|
|
|
8d419f |
+ r = ordered_set_consume(s, t);
|
|
|
8d419f |
if (r < 0 && r != -EEXIST)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -220,10 +219,10 @@ static int get_child_nodes(
|
|
|
8d419f |
const char *prefix,
|
|
|
8d419f |
struct node *n,
|
|
|
8d419f |
unsigned flags,
|
|
|
8d419f |
- Set **_s,
|
|
|
8d419f |
+ OrderedSet **_s,
|
|
|
8d419f |
sd_bus_error *error) {
|
|
|
8d419f |
|
|
|
8d419f |
- Set *s = NULL;
|
|
|
8d419f |
+ OrderedSet *s = NULL;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
assert(bus);
|
|
|
8d419f |
@@ -231,13 +230,13 @@ static int get_child_nodes(
|
|
|
8d419f |
assert(n);
|
|
|
8d419f |
assert(_s);
|
|
|
8d419f |
|
|
|
8d419f |
- s = set_new(&string_hash_ops);
|
|
|
8d419f |
+ s = ordered_set_new(&string_hash_ops);
|
|
|
8d419f |
if (!s)
|
|
|
8d419f |
return -ENOMEM;
|
|
|
8d419f |
|
|
|
8d419f |
r = add_subtree_to_set(bus, prefix, n, flags, s, error);
|
|
|
8d419f |
if (r < 0) {
|
|
|
8d419f |
- set_free_free(s);
|
|
|
8d419f |
+ ordered_set_free_free(s);
|
|
|
8d419f |
return r;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
@@ -937,7 +936,7 @@ int introspect_path(
|
|
|
8d419f |
char **ret,
|
|
|
8d419f |
sd_bus_error *error) {
|
|
|
8d419f |
|
|
|
8d419f |
- _cleanup_set_free_free_ Set *s = NULL;
|
|
|
8d419f |
+ _cleanup_ordered_set_free_ OrderedSet *s = NULL;
|
|
|
8d419f |
_cleanup_(introspect_free) struct introspect intro = {};
|
|
|
8d419f |
struct node_vtable *c;
|
|
|
8d419f |
bool empty;
|
|
|
8d419f |
@@ -963,7 +962,7 @@ int introspect_path(
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
- empty = set_isempty(s);
|
|
|
8d419f |
+ empty = ordered_set_isempty(s);
|
|
|
8d419f |
|
|
|
8d419f |
LIST_FOREACH(vtables, c, n->vtables) {
|
|
|
8d419f |
if (require_fallback && !c->is_fallback)
|
|
|
8d419f |
@@ -1233,7 +1232,7 @@ static int process_get_managed_objects(
|
|
|
8d419f |
|
|
|
8d419f |
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
|
|
8d419f |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
|
|
8d419f |
- _cleanup_set_free_free_ Set *s = NULL;
|
|
|
8d419f |
+ _cleanup_ordered_set_free_free_ OrderedSet *s = NULL;
|
|
|
8d419f |
char *path;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -1263,7 +1262,7 @@ static int process_get_managed_objects(
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
- SET_FOREACH(path, s) {
|
|
|
8d419f |
+ ORDERED_SET_FOREACH(path, s) {
|
|
|
8d419f |
r = object_manager_serialize_path_and_fallbacks(bus, reply, path, &error);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return bus_maybe_reply_error(m, r, &error);
|
|
|
8d419f |
@@ -2352,7 +2351,7 @@ _public_ int sd_bus_emit_properties_changed(
|
|
|
8d419f |
static int object_added_append_all_prefix(
|
|
|
8d419f |
sd_bus *bus,
|
|
|
8d419f |
sd_bus_message *m,
|
|
|
8d419f |
- Set *s,
|
|
|
8d419f |
+ OrderedSet *s,
|
|
|
8d419f |
const char *prefix,
|
|
|
8d419f |
const char *path,
|
|
|
8d419f |
bool require_fallback) {
|
|
|
8d419f |
@@ -2392,10 +2391,10 @@ static int object_added_append_all_prefix(
|
|
|
8d419f |
* skip it on any of its parents. The child vtables
|
|
|
8d419f |
* always fully override any conflicting vtables of
|
|
|
8d419f |
* any parent node. */
|
|
|
8d419f |
- if (set_get(s, c->interface))
|
|
|
8d419f |
+ if (ordered_set_get(s, c->interface))
|
|
|
8d419f |
continue;
|
|
|
8d419f |
|
|
|
8d419f |
- r = set_put(s, c->interface);
|
|
|
8d419f |
+ r = ordered_set_put(s, c->interface);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -2441,7 +2440,7 @@ static int object_added_append_all_prefix(
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *path) {
|
|
|
8d419f |
- _cleanup_set_free_ Set *s = NULL;
|
|
|
8d419f |
+ _cleanup_ordered_set_free_ OrderedSet *s = NULL;
|
|
|
8d419f |
_cleanup_free_ char *prefix = NULL;
|
|
|
8d419f |
size_t pl;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
@@ -2465,7 +2464,7 @@ static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *p
|
|
|
8d419f |
* a parent that were overwritten by a child.
|
|
|
8d419f |
*/
|
|
|
8d419f |
|
|
|
8d419f |
- s = set_new(&string_hash_ops);
|
|
|
8d419f |
+ s = ordered_set_new(&string_hash_ops);
|
|
|
8d419f |
if (!s)
|
|
|
8d419f |
return -ENOMEM;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -2572,7 +2571,7 @@ _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
|
|
|
8d419f |
static int object_removed_append_all_prefix(
|
|
|
8d419f |
sd_bus *bus,
|
|
|
8d419f |
sd_bus_message *m,
|
|
|
8d419f |
- Set *s,
|
|
|
8d419f |
+ OrderedSet *s,
|
|
|
8d419f |
const char *prefix,
|
|
|
8d419f |
const char *path,
|
|
|
8d419f |
bool require_fallback) {
|
|
|
8d419f |
@@ -2605,7 +2604,7 @@ static int object_removed_append_all_prefix(
|
|
|
8d419f |
* skip it on any of its parents. The child vtables
|
|
|
8d419f |
* always fully override any conflicting vtables of
|
|
|
8d419f |
* any parent node. */
|
|
|
8d419f |
- if (set_get(s, c->interface))
|
|
|
8d419f |
+ if (ordered_set_get(s, c->interface))
|
|
|
8d419f |
continue;
|
|
|
8d419f |
|
|
|
8d419f |
r = node_vtable_get_userdata(bus, path, c, &u, &error);
|
|
|
8d419f |
@@ -2616,7 +2615,7 @@ static int object_removed_append_all_prefix(
|
|
|
8d419f |
if (r == 0)
|
|
|
8d419f |
continue;
|
|
|
8d419f |
|
|
|
8d419f |
- r = set_put(s, c->interface);
|
|
|
8d419f |
+ r = ordered_set_put(s, c->interface);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -2631,7 +2630,7 @@ static int object_removed_append_all_prefix(
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char *path) {
|
|
|
8d419f |
- _cleanup_set_free_ Set *s = NULL;
|
|
|
8d419f |
+ _cleanup_ordered_set_free_ OrderedSet *s = NULL;
|
|
|
8d419f |
_cleanup_free_ char *prefix = NULL;
|
|
|
8d419f |
size_t pl;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
@@ -2642,7 +2641,7 @@ static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char
|
|
|
8d419f |
|
|
|
8d419f |
/* see sd_bus_emit_object_added() for details */
|
|
|
8d419f |
|
|
|
8d419f |
- s = set_new(&string_hash_ops);
|
|
|
8d419f |
+ s = ordered_set_new(&string_hash_ops);
|
|
|
8d419f |
if (!s)
|
|
|
8d419f |
return -ENOMEM;
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/shared/bus-object.c b/src/shared/bus-object.c
|
|
|
8d419f |
index f2e53913fb..4ed5215e3d 100644
|
|
|
8d419f |
--- a/src/shared/bus-object.c
|
|
|
8d419f |
+++ b/src/shared/bus-object.c
|
|
|
8d419f |
@@ -156,10 +156,10 @@ int bus_introspect_implementations(
|
|
|
8d419f |
if (impl != main_impl)
|
|
|
8d419f |
bus_introspect_implementation(&intro, impl);
|
|
|
8d419f |
|
|
|
8d419f |
- _cleanup_set_free_ Set *nodes = NULL;
|
|
|
8d419f |
+ _cleanup_ordered_set_free_ OrderedSet *nodes = NULL;
|
|
|
8d419f |
|
|
|
8d419f |
for (size_t i = 0; impl->children && impl->children[i]; i++) {
|
|
|
8d419f |
- r = set_put_strdup(&nodes, impl->children[i]->path);
|
|
|
8d419f |
+ r = ordered_set_put_strdup(&nodes, impl->children[i]->path);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return log_oom();
|
|
|
8d419f |
}
|