teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0136-bus-Use-OrderedSet-for-introspection.patch

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