From: Yu Watanabe Date: Wed, 28 May 2025 02:14:41 +0000 (+0900) Subject: sd-bus: rename internal structs and enums X-Git-Tag: v258-rc1~466 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d117687ab3a8c99585ff8f29a89bcf2db345091f;p=thirdparty%2Fsystemd.git sd-bus: rename internal structs and enums This renames e.g. struct bus_body_part -> BusMessageBodyPart to follow our usual coding style. Also, several struct and enum declarations are moved to relevant headers. Also, this introduces bus-forward.h. --- diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index d71274968c3..e9dade20905 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -582,7 +582,7 @@ int bus_pcap_header(size_t snaplen, const char *os, const char *info, FILE *f) { } int bus_message_pcap_frame(sd_bus_message *m, size_t snaplen, FILE *f) { - struct bus_body_part *part; + BusMessageBodyPart *part; size_t msglen, caplen, pad; uint32_t length; uint64_t ts; diff --git a/src/libsystemd/sd-bus/bus-forward.h b/src/libsystemd/sd-bus/bus-forward.h new file mode 100644 index 00000000000..0b5433d6b64 --- /dev/null +++ b/src/libsystemd/sd-bus/bus-forward.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "forward.h" + +typedef enum BusAuth BusAuth; +typedef enum BusSlotType BusSlotType; +typedef enum BusState BusState; + +typedef struct BusFilterCallback BusFilterCallback; + +typedef struct BusMatchCallback BusMatchCallback; +typedef struct BusMatchComponent BusMatchComponent; +typedef struct BusMatchNode BusMatchNode; +typedef enum BusMatchNodeType BusMatchNodeType; +typedef enum BusMatchScope BusMatchScope; + +typedef struct BusNode BusNode; +typedef struct BusNodeCallback BusNodeCallback; +typedef struct BusNodeEnumerator BusNodeEnumerator; +typedef struct BusNodeObjectManager BusNodeObjectManager; +typedef struct BusNodeVTable BusNodeVTable; +typedef struct BusVTableMember BusVTableMember; + +typedef struct BusReplyCallback BusReplyCallback; + +typedef struct BusMessageBodyPart BusMessageBodyPart; +typedef struct BusMessageContainer BusMessageContainer; +typedef struct BusMessageHeader BusMessageHeader; + +typedef struct BusIntrospect BusIntrospect; diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index e9052b76b31..e71ecf2fc81 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -3,10 +3,10 @@ #include "sd-id128.h" +#include "bus-forward.h" #include "bus-kernel.h" #include "bus-match.h" #include "constants.h" -#include "forward.h" #include "list.h" #include "runtime-scope.h" #include "socket-util.h" @@ -16,80 +16,62 @@ #define DEFAULT_SYSTEM_BUS_ADDRESS "unix:path=/run/dbus/system_bus_socket" #define DEFAULT_USER_BUS_ADDRESS_FMT "unix:path=%s/bus" -struct reply_callback { +typedef struct BusReplyCallback { sd_bus_message_handler_t callback; usec_t timeout_usec; /* this is a relative timeout until we reach the BUS_HELLO state, and an absolute one right after */ uint64_t cookie; unsigned prioq_idx; -}; +} BusReplyCallback; -struct filter_callback { +typedef struct BusFilterCallback { sd_bus_message_handler_t callback; unsigned last_iteration; - LIST_FIELDS(struct filter_callback, callbacks); -}; + LIST_FIELDS(BusFilterCallback, callbacks); +} BusFilterCallback; -struct match_callback { - sd_bus_message_handler_t callback; - sd_bus_message_handler_t install_callback; - - sd_bus_slot *install_slot; /* The AddMatch() call */ - - unsigned last_iteration; - - /* Don't dispatch this slot with messages that arrived in any iteration before or at the this - * one. We use this to ensure that matches don't apply "retroactively" and confuse the caller: - * only messages received after the match was installed will be considered. */ - uint64_t after; - - char *match_string; - - struct bus_match_node *match_node; -}; - -struct node { +typedef struct BusNode { char *path; - struct node *parent; - LIST_HEAD(struct node, child); - LIST_FIELDS(struct node, siblings); + BusNode *parent; + LIST_HEAD(BusNode, child); + LIST_FIELDS(BusNode, siblings); - LIST_HEAD(struct node_callback, callbacks); - LIST_HEAD(struct node_vtable, vtables); - LIST_HEAD(struct node_enumerator, enumerators); - LIST_HEAD(struct node_object_manager, object_managers); -}; + LIST_HEAD(BusNodeCallback, callbacks); + LIST_HEAD(BusNodeVTable, vtables); + LIST_HEAD(BusNodeEnumerator, enumerators); + LIST_HEAD(BusNodeObjectManager, object_managers); +} BusNode; -struct node_callback { - struct node *node; +typedef struct BusNodeCallback { + BusNode *node; bool is_fallback; unsigned last_iteration; sd_bus_message_handler_t callback; - LIST_FIELDS(struct node_callback, callbacks); -}; + LIST_FIELDS(BusNodeCallback, callbacks); +} BusNodeCallback; -struct node_enumerator { - struct node *node; +typedef struct BusNodeEnumerator { + BusNode *node; sd_bus_node_enumerator_t callback; unsigned last_iteration; - LIST_FIELDS(struct node_enumerator, enumerators); -}; + LIST_FIELDS(BusNodeEnumerator, enumerators); +} BusNodeEnumerator; -struct node_object_manager { - struct node *node; +typedef struct BusNodeObjectManager { + BusNode *node; - LIST_FIELDS(struct node_object_manager, object_managers); -}; + LIST_FIELDS(BusNodeObjectManager, object_managers); +} BusNodeObjectManager; -struct node_vtable { - struct node *node; +typedef struct BusNodeVTable { + BusNode *node; bool is_fallback; unsigned last_iteration; @@ -98,17 +80,17 @@ struct node_vtable { const sd_bus_vtable *vtable; sd_bus_object_find_t find; - LIST_FIELDS(struct node_vtable, vtables); -}; + LIST_FIELDS(BusNodeVTable, vtables); +} BusNodeVTable; -struct vtable_member { +typedef struct BusVTableMember { const char *path; const char *interface; const char *member; - struct node_vtable *parent; + BusNodeVTable *parent; unsigned last_iteration; const sd_bus_vtable *vtable; -}; +} BusVTableMember; typedef enum BusSlotType { BUS_REPLY_CALLBACK, @@ -144,17 +126,17 @@ typedef struct sd_bus_slot { LIST_FIELDS(sd_bus_slot, slots); union { - struct reply_callback reply_callback; - struct filter_callback filter_callback; - struct match_callback match_callback; - struct node_callback node_callback; - struct node_enumerator node_enumerator; - struct node_object_manager node_object_manager; - struct node_vtable node_vtable; + BusReplyCallback reply_callback; + BusFilterCallback filter_callback; + BusMatchCallback match_callback; + BusNodeCallback node_callback; + BusNodeEnumerator node_enumerator; + BusNodeObjectManager node_object_manager; + BusNodeVTable node_vtable; }; } sd_bus_slot; -enum bus_state { +typedef enum BusState { BUS_UNSET, BUS_WATCH_BIND, /* waiting for the socket to appear via inotify */ BUS_OPENING, /* the kernel's connect() is still not ready */ @@ -164,22 +146,22 @@ enum bus_state { BUS_CLOSING, BUS_CLOSED, _BUS_STATE_MAX, -}; +} BusState; -static inline bool BUS_IS_OPEN(enum bus_state state) { +static inline bool BUS_IS_OPEN(BusState state) { return state > BUS_UNSET && state < BUS_CLOSING; } -enum bus_auth { +typedef enum BusAuth { _BUS_AUTH_INVALID, BUS_AUTH_EXTERNAL, BUS_AUTH_ANONYMOUS -}; +} BusAuth; typedef struct sd_bus { unsigned n_ref; - enum bus_state state; + BusState state; int input_fd, output_fd; int inotify_fd; int message_version; @@ -229,10 +211,10 @@ typedef struct sd_bus { char *unique_name; uint64_t unique_id; - struct bus_match_node match_callbacks; + BusMatchNode match_callbacks; Prioq *reply_callbacks_prioq; OrderedHashmap *reply_callbacks; - LIST_HEAD(struct filter_callback, filter_callbacks); + LIST_HEAD(BusFilterCallback, filter_callbacks); Hashmap *nodes; Set *vtable_methods; @@ -254,7 +236,7 @@ typedef struct sd_bus { int last_connect_error; - enum bus_auth auth; + BusAuth auth; unsigned auth_index; struct iovec auth_iovec[3]; size_t auth_rbegin; @@ -423,4 +405,4 @@ int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error); void bus_enter_closing(sd_bus *bus); -void bus_set_state(sd_bus *bus, enum bus_state state); +void bus_set_state(sd_bus *bus, BusState state); diff --git a/src/libsystemd/sd-bus/bus-introspect.c b/src/libsystemd/sd-bus/bus-introspect.c index 2bbc9329393..cdc869ce049 100644 --- a/src/libsystemd/sd-bus/bus-introspect.c +++ b/src/libsystemd/sd-bus/bus-introspect.c @@ -69,12 +69,12 @@ " \n" \ " \n" -int introspect_begin(struct introspect *i, bool trusted) { +int introspect_begin(BusIntrospect *i, bool trusted) { FILE *f; assert(i); - *i = (struct introspect) { + *i = (BusIntrospect) { .trusted = trusted, }; @@ -88,7 +88,7 @@ int introspect_begin(struct introspect *i, bool trusted) { return 0; } -int introspect_write_default_interfaces(struct introspect *i, bool object_manager) { +int introspect_write_default_interfaces(BusIntrospect *i, bool object_manager) { assert(i); assert(i->m.f); @@ -102,7 +102,7 @@ int introspect_write_default_interfaces(struct introspect *i, bool object_manage return 0; } -static int set_interface_name(struct introspect *i, const char *interface_name) { +static int set_interface_name(BusIntrospect *i, const char *interface_name) { assert(i); assert(i->m.f); @@ -118,7 +118,7 @@ static int set_interface_name(struct introspect *i, const char *interface_name) return free_and_strdup(&i->interface_name, interface_name); } -int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char *prefix) { +int introspect_write_child_nodes(BusIntrospect *i, OrderedSet *s, const char *prefix) { char *node; assert(i); @@ -140,7 +140,7 @@ int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char return 0; } -static void introspect_write_flags(struct introspect *i, int type, uint64_t flags) { +static void introspect_write_flags(BusIntrospect *i, int type, uint64_t flags) { assert(i); assert(i->m.f); @@ -170,7 +170,7 @@ static void introspect_write_flags(struct introspect *i, int type, uint64_t flag /* Note that "names" is both an input and an output parameter. It initially points to the first argument name in a NULL-separated list of strings, and is then advanced with each argument, and the resulting pointer is returned. */ -static int introspect_write_arguments(struct introspect *i, const char *signature, const char **names, const char *direction) { +static int introspect_write_arguments(BusIntrospect *i, const char *signature, const char **names, const char *direction) { int r; assert(i); @@ -203,7 +203,7 @@ static int introspect_write_arguments(struct introspect *i, const char *signatur } int introspect_write_interface( - struct introspect *i, + BusIntrospect *i, const char *interface_name, const sd_bus_vtable *v) { @@ -270,7 +270,7 @@ int introspect_write_interface( return 0; } -int introspect_finish(struct introspect *i, char **ret) { +int introspect_finish(BusIntrospect *i, char **ret) { assert(i); assert(i->m.f); @@ -281,7 +281,7 @@ int introspect_finish(struct introspect *i, char **ret) { return memstream_finalize(&i->m, ret, NULL); } -void introspect_done(struct introspect *i) { +void introspect_done(BusIntrospect *i) { assert(i); /* Normally introspect_finish() does all the work, this is just a backup for error paths */ diff --git a/src/libsystemd/sd-bus/bus-introspect.h b/src/libsystemd/sd-bus/bus-introspect.h index f9d87c499b6..923b47dd598 100644 --- a/src/libsystemd/sd-bus/bus-introspect.h +++ b/src/libsystemd/sd-bus/bus-introspect.h @@ -1,21 +1,21 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "forward.h" +#include "bus-forward.h" #include "memstream-util.h" -struct introspect { +typedef struct BusIntrospect { MemStream m; char *interface_name; bool trusted; -}; +} BusIntrospect; -int introspect_begin(struct introspect *i, bool trusted); -int introspect_write_default_interfaces(struct introspect *i, bool object_manager); -int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char *prefix); +int introspect_begin(BusIntrospect *i, bool trusted); +int introspect_write_default_interfaces(BusIntrospect *i, bool object_manager); +int introspect_write_child_nodes(BusIntrospect *i, OrderedSet *s, const char *prefix); int introspect_write_interface( - struct introspect *i, + BusIntrospect *i, const char *interface_name, const sd_bus_vtable *v); -int introspect_finish(struct introspect *i, char **ret); -void introspect_done(struct introspect *i); +int introspect_finish(BusIntrospect *i, char **ret); +void introspect_done(BusIntrospect *i); diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index fc05f385e86..f2521d21b04 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -50,17 +50,17 @@ * ` BUS_MATCH_LEAF: E */ -static bool BUS_MATCH_IS_COMPARE(enum bus_match_node_type t) { +static bool BUS_MATCH_IS_COMPARE(BusMatchNodeType t) { return t >= BUS_MATCH_SENDER && t <= BUS_MATCH_ARG_HAS_LAST; } -static bool BUS_MATCH_CAN_HASH(enum bus_match_node_type t) { +static bool BUS_MATCH_CAN_HASH(BusMatchNodeType t) { return (t >= BUS_MATCH_MESSAGE_TYPE && t <= BUS_MATCH_PATH) || (t >= BUS_MATCH_ARG && t <= BUS_MATCH_ARG_LAST) || (t >= BUS_MATCH_ARG_HAS && t <= BUS_MATCH_ARG_HAS_LAST); } -static void bus_match_node_free(struct bus_match_node *node) { +static void bus_match_node_free(BusMatchNode *node) { assert(node); assert(node->parent); assert(!node->child); @@ -102,7 +102,7 @@ static void bus_match_node_free(struct bus_match_node *node) { free(node); } -static bool bus_match_node_maybe_free(struct bus_match_node *node) { +static bool bus_match_node_maybe_free(BusMatchNode *node) { assert(node); if (node->type == BUS_MATCH_ROOT) @@ -119,8 +119,8 @@ static bool bus_match_node_maybe_free(struct bus_match_node *node) { } static bool value_node_test( - struct bus_match_node *node, - enum bus_match_node_type parent_type, + BusMatchNode *node, + BusMatchNodeType parent_type, uint8_t value_u8, const char *value_str, char **value_strv, @@ -203,8 +203,8 @@ static bool value_node_test( } static bool value_node_same( - struct bus_match_node *node, - enum bus_match_node_type parent_type, + BusMatchNode *node, + BusMatchNodeType parent_type, uint8_t value_u8, const char *value_str) { @@ -239,7 +239,7 @@ static bool value_node_same( int bus_match_run( sd_bus *bus, - struct bus_match_node *node, + BusMatchNode *node, sd_bus_message *m) { _cleanup_strv_free_ char **test_strv = NULL; @@ -378,7 +378,7 @@ int bus_match_run( } if (BUS_MATCH_CAN_HASH(node->type)) { - struct bus_match_node *found; + BusMatchNode *found; /* Lookup via hash table, nice! So let's jump directly. */ @@ -407,7 +407,7 @@ int bus_match_run( } } else /* No hash table, so let's iterate manually... */ - for (struct bus_match_node *c = node->child; c; c = c->next) { + for (BusMatchNode *c = node->child; c; c = c->next) { if (!value_node_test(c, node->type, test_u8, test_str, test_strv, m)) continue; @@ -427,13 +427,13 @@ int bus_match_run( } static int bus_match_add_compare_value( - struct bus_match_node *where, - enum bus_match_node_type t, + BusMatchNode *where, + BusMatchNodeType t, uint8_t value_u8, const char *value_str, - struct bus_match_node **ret) { + BusMatchNode **ret) { - struct bus_match_node *c, *n = NULL; + BusMatchNode *c, *n = NULL; int r; assert(where); @@ -462,7 +462,7 @@ static int bus_match_add_compare_value( } else { /* Comparison node, doesn't exist yet? Then let's create it. */ - c = new0(struct bus_match_node, 1); + c = new0(BusMatchNode, 1); if (!c) { r = -ENOMEM; goto fail; @@ -490,7 +490,7 @@ static int bus_match_add_compare_value( } } - n = new0(struct bus_match_node, 1); + n = new0(BusMatchNode, 1); if (!n) { r = -ENOMEM; goto fail; @@ -539,16 +539,16 @@ fail: } static int bus_match_add_leaf( - struct bus_match_node *where, - struct match_callback *callback) { + BusMatchNode *where, + BusMatchCallback *callback) { - struct bus_match_node *n; + BusMatchNode *n; assert(where); assert(IN_SET(where->type, BUS_MATCH_ROOT, BUS_MATCH_VALUE)); assert(callback); - n = new0(struct bus_match_node, 1); + n = new0(BusMatchNode, 1); if (!n) return -ENOMEM; @@ -566,7 +566,7 @@ static int bus_match_add_leaf( return 1; } -enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n) { +BusMatchNodeType bus_match_node_type_from_string(const char *k, size_t n) { assert(k); if (n == 4 && startswith(k, "type")) @@ -596,7 +596,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n if (n == 5 && startswith(k, "arg")) { int a, b; - enum bus_match_node_type t; + BusMatchNodeType t; a = undecchar(k[3]); b = undecchar(k[4]); @@ -621,7 +621,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n } if (n == 9 && startswith(k, "arg") && startswith(k + 5, "path")) { - enum bus_match_node_type t; + BusMatchNodeType t; int a, b; a = undecchar(k[3]); @@ -647,7 +647,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n } if (n == 14 && startswith(k, "arg") && startswith(k + 5, "namespace")) { - enum bus_match_node_type t; + BusMatchNodeType t; int a, b; a = undecchar(k[3]); @@ -673,7 +673,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n } if (n == 8 && startswith(k, "arg") && startswith(k + 5, "has")) { - enum bus_match_node_type t; + BusMatchNodeType t; int a, b; a = undecchar(k[3]); @@ -691,11 +691,11 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n return -EINVAL; } -static int match_component_compare(const struct bus_match_component *a, const struct bus_match_component *b) { +static int match_component_compare(const BusMatchComponent *a, const BusMatchComponent *b) { return CMP(a->type, b->type); } -void bus_match_parse_free(struct bus_match_component *components, size_t n_components) { +void bus_match_parse_free(BusMatchComponent *components, size_t n_components) { for (size_t i = 0; i < n_components; i++) free(components[i].value_str); @@ -704,10 +704,10 @@ void bus_match_parse_free(struct bus_match_component *components, size_t n_compo int bus_match_parse( const char *match, - struct bus_match_component **ret_components, + BusMatchComponent **ret_components, size_t *ret_n_components) { - struct bus_match_component *components = NULL; + BusMatchComponent *components = NULL; size_t n_components = 0; int r; @@ -719,7 +719,7 @@ int bus_match_parse( while (*match != '\0') { const char *eq, *q; - enum bus_match_node_type t; + BusMatchNodeType t; size_t j = 0; _cleanup_free_ char *value = NULL; bool escaped = false, quoted; @@ -796,7 +796,7 @@ int bus_match_parse( if (!GREEDY_REALLOC(components, n_components + 1)) return -ENOMEM; - components[n_components++] = (struct bus_match_component) { + components[n_components++] = (BusMatchComponent) { .type = t, .value_str = TAKE_PTR(value), .value_u8 = u, @@ -825,7 +825,7 @@ int bus_match_parse( return 0; } -char* bus_match_to_string(struct bus_match_component *components, size_t n_components) { +char* bus_match_to_string(BusMatchComponent *components, size_t n_components) { _cleanup_(memstream_done) MemStream m = {}; FILE *f; int r; @@ -866,10 +866,10 @@ char* bus_match_to_string(struct bus_match_component *components, size_t n_compo } int bus_match_add( - struct bus_match_node *root, - struct bus_match_component *components, + BusMatchNode *root, + BusMatchComponent *components, size_t n_components, - struct match_callback *callback) { + BusMatchCallback *callback) { int r; @@ -890,10 +890,10 @@ int bus_match_add( } int bus_match_remove( - struct bus_match_node *root, - struct match_callback *callback) { + BusMatchNode *root, + BusMatchCallback *callback) { - struct bus_match_node *node, *pp; + BusMatchNode *node, *pp; assert(root); assert(callback); @@ -922,8 +922,8 @@ int bus_match_remove( return 1; } -void bus_match_free(struct bus_match_node *node) { - struct bus_match_node *c; +void bus_match_free(BusMatchNode *node) { + BusMatchNode *c; if (!node) return; @@ -943,7 +943,7 @@ void bus_match_free(struct bus_match_node *node) { bus_match_node_free(node); } -const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l) { +const char* bus_match_node_type_to_string(BusMatchNodeType t, char buf[], size_t l) { switch (t) { case BUS_MATCH_ROOT: @@ -993,7 +993,7 @@ const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[] } } -void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) { +void bus_match_dump(FILE *out, BusMatchNode *node, unsigned level) { char buf[32]; if (!node) @@ -1015,16 +1015,16 @@ void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) { putc('\n', out); if (BUS_MATCH_CAN_HASH(node->type)) { - struct bus_match_node *c; + BusMatchNode *c; HASHMAP_FOREACH(c, node->compare.children) bus_match_dump(out, c, level + 1); } - for (struct bus_match_node *c = node->child; c; c = c->next) + for (BusMatchNode *c = node->child; c; c = c->next) bus_match_dump(out, c, level + 1); } -enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, size_t n_components) { +BusMatchScope bus_match_get_scope(const BusMatchComponent *components, size_t n_components) { bool found_driver = false; if (n_components <= 0) @@ -1039,7 +1039,7 @@ enum bus_match_scope bus_match_get_scope(const struct bus_match_component *compo * driver. */ for (size_t i = 0; i < n_components; i++) { - const struct bus_match_component *c = components + i; + const BusMatchComponent *c = components + i; if (c->type == BUS_MATCH_SENDER) { if (streq_ptr(c->value_str, "org.freedesktop.DBus.Local")) diff --git a/src/libsystemd/sd-bus/bus-match.h b/src/libsystemd/sd-bus/bus-match.h index 622e00d94c6..7dcca27f565 100644 --- a/src/libsystemd/sd-bus/bus-match.h +++ b/src/libsystemd/sd-bus/bus-match.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "forward.h" +#include "bus-forward.h" -enum bus_match_node_type { +typedef enum BusMatchNodeType { BUS_MATCH_ROOT, BUS_MATCH_VALUE, BUS_MATCH_LEAF, @@ -26,11 +26,29 @@ enum bus_match_node_type { BUS_MATCH_ARG_HAS_LAST = BUS_MATCH_ARG_HAS + 63, _BUS_MATCH_NODE_TYPE_MAX, _BUS_MATCH_NODE_TYPE_INVALID = -EINVAL, -}; +} BusMatchNodeType; -struct bus_match_node { - enum bus_match_node_type type; - struct bus_match_node *parent, *next, *prev, *child; +typedef struct BusMatchCallback { + sd_bus_message_handler_t callback; + sd_bus_message_handler_t install_callback; + + sd_bus_slot *install_slot; /* The AddMatch() call */ + + unsigned last_iteration; + + /* Don't dispatch this slot with messages that arrived in any iteration before or at the this + * one. We use this to ensure that matches don't apply "retroactively" and confuse the caller: + * only messages received after the match was installed will be considered. */ + uint64_t after; + + char *match_string; + + BusMatchNode *match_node; +} BusMatchCallback; + +typedef struct BusMatchNode { + BusMatchNodeType type; + BusMatchNode *parent, *next, *prev, *child; union { struct { @@ -38,41 +56,41 @@ struct bus_match_node { uint8_t u8; } value; struct { - struct match_callback *callback; + BusMatchCallback *callback; } leaf; struct { /* If this is set, then the child is NULL */ Hashmap *children; } compare; }; -}; +} BusMatchNode; -struct bus_match_component { - enum bus_match_node_type type; +typedef struct BusMatchComponent { + BusMatchNodeType type; uint8_t value_u8; char *value_str; -}; +} BusMatchComponent; -enum bus_match_scope { +typedef enum BusMatchScope { BUS_MATCH_GENERIC, BUS_MATCH_LOCAL, BUS_MATCH_DRIVER, -}; +} BusMatchScope; -int bus_match_run(sd_bus *bus, struct bus_match_node *root, sd_bus_message *m); +int bus_match_run(sd_bus *bus, BusMatchNode *root, sd_bus_message *m); -int bus_match_add(struct bus_match_node *root, struct bus_match_component *components, size_t n_components, struct match_callback *callback); -int bus_match_remove(struct bus_match_node *root, struct match_callback *callback); +int bus_match_add(BusMatchNode *root, BusMatchComponent *components, size_t n_components, BusMatchCallback *callback); +int bus_match_remove(BusMatchNode *root, BusMatchCallback *callback); -void bus_match_free(struct bus_match_node *node); +void bus_match_free(BusMatchNode *node); -void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level); +void bus_match_dump(FILE *out, BusMatchNode *node, unsigned level); -const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l); -enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n); +const char* bus_match_node_type_to_string(BusMatchNodeType t, char buf[], size_t l); +BusMatchNodeType bus_match_node_type_from_string(const char *k, size_t n); -int bus_match_parse(const char *match, struct bus_match_component **ret_components, size_t *ret_n_components); -void bus_match_parse_free(struct bus_match_component *components, size_t n_components); -char* bus_match_to_string(struct bus_match_component *components, size_t n_components); +int bus_match_parse(const char *match, BusMatchComponent **ret_components, size_t *ret_n_components); +void bus_match_parse_free(BusMatchComponent *components, size_t n_components); +char* bus_match_to_string(BusMatchComponent *components, size_t n_components); -enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, size_t n_components); +BusMatchScope bus_match_get_scope(const BusMatchComponent *components, size_t n_components); diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 6636285526c..24fac3b1377 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -38,7 +38,7 @@ static void *adjust_pointer(const void *p, void *old_base, size_t sz, void *new_ return (uint8_t*) new_base + ((uint8_t*) p - (uint8_t*) old_base); } -static void message_free_part(sd_bus_message *m, struct bus_body_part *part) { +static void message_free_part(sd_bus_message *m, BusMessageBodyPart *part) { assert(m); assert(part); @@ -66,13 +66,13 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) { } static void message_reset_parts(sd_bus_message *m) { - struct bus_body_part *part; + BusMessageBodyPart *part; assert(m); part = &m->body; while (m->n_body_parts > 0) { - struct bus_body_part *next = part->next; + BusMessageBodyPart *next = part->next; message_free_part(m, part); part = next; m->n_body_parts--; @@ -84,7 +84,7 @@ static void message_reset_parts(sd_bus_message *m) { m->cached_rindex_part_begin = 0; } -static struct bus_container *message_get_last_container(sd_bus_message *m) { +static BusMessageContainer *message_get_last_container(sd_bus_message *m) { assert(m); if (m->n_containers == 0) @@ -95,7 +95,7 @@ static struct bus_container *message_get_last_container(sd_bus_message *m) { } static void message_free_last_container(sd_bus_message *m) { - struct bus_container *c; + BusMessageContainer *c; c = message_get_last_container(m); @@ -153,7 +153,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t sz, bool add_offset if (m->poisoned) return NULL; - old_size = sizeof(struct bus_header) + m->fields_size; + old_size = sizeof(BusMessageHeader) + m->fields_size; start = ALIGN8(old_size); new_size = start + sz; @@ -176,7 +176,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t sz, bool add_offset if (!np) goto poison; - memcpy(np, m->header, sizeof(struct bus_header)); + memcpy(np, m->header, sizeof(BusMessageHeader)); } /* Zero out padding */ @@ -185,7 +185,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t sz, bool add_offset op = m->header; m->header = np; - m->fields_size = new_size - sizeof(struct bus_header); + m->fields_size = new_size - sizeof(BusMessageHeader); /* Adjust quick access pointers */ m->path = adjust_pointer(m->path, op, old_size, m->header); @@ -201,7 +201,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t sz, bool add_offset if (m->n_header_offsets >= ELEMENTSOF(m->header_offsets)) goto poison; - m->header_offsets[m->n_header_offsets++] = new_size - sizeof(struct bus_header); + m->header_offsets[m->n_header_offsets++] = new_size - sizeof(BusMessageHeader); } return (uint8_t*) np + start; @@ -337,7 +337,7 @@ static int message_from_header( sd_bus_message **ret) { _cleanup_free_ sd_bus_message *m = NULL; - struct bus_header *h; + BusMessageHeader *h; size_t a, label_sz = 0; /* avoid false maybe-uninitialized warning */ assert(bus); @@ -345,7 +345,7 @@ static int message_from_header( assert(fds || n_fds <= 0); assert(ret); - if (message_size < sizeof(struct bus_header)) + if (message_size < sizeof(BusMessageHeader)) return -EBADMSG; h = buffer; @@ -381,9 +381,9 @@ static int message_from_header( m->fields_size = BUS_MESSAGE_BSWAP32(m, h->fields_size); m->body_size = BUS_MESSAGE_BSWAP32(m, h->body_size); - assert(message_size >= sizeof(struct bus_header)); - if (ALIGN8(m->fields_size) > message_size - sizeof(struct bus_header) || - m->body_size != message_size - sizeof(struct bus_header) - ALIGN8(m->fields_size)) + assert(message_size >= sizeof(BusMessageHeader)); + if (ALIGN8(m->fields_size) > message_size - sizeof(BusMessageHeader) || + m->body_size != message_size - sizeof(BusMessageHeader) - ALIGN8(m->fields_size)) return -EBADMSG; m->fds = fds; @@ -426,10 +426,10 @@ int bus_message_from_malloc( if (r < 0) return r; - sz = length - sizeof(struct bus_header) - ALIGN8(m->fields_size); + sz = length - sizeof(BusMessageHeader) - ALIGN8(m->fields_size); if (sz > 0) { m->n_body_parts = 1; - m->body.data = (uint8_t*) buffer + sizeof(struct bus_header) + ALIGN8(m->fields_size); + m->body.data = (uint8_t*) buffer + sizeof(BusMessageHeader) + ALIGN8(m->fields_size); m->body.size = sz; m->body.sealed = true; m->body.memfd = -EBADF; @@ -463,14 +463,14 @@ _public_ int sd_bus_message_new( /* Creation of messages with _SD_BUS_MESSAGE_TYPE_INVALID is allowed. */ assert_return(type < _SD_BUS_MESSAGE_TYPE_MAX, -EINVAL); - sd_bus_message *t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(struct bus_header)); + sd_bus_message *t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(BusMessageHeader)); if (!t) return -ENOMEM; t->n_ref = 1; t->creds = (sd_bus_creds) { SD_BUS_CREDS_INIT_FIELDS }; t->bus = sd_bus_ref(bus); - t->header = (struct bus_header*) ((uint8_t*) t + ALIGN(sizeof(struct sd_bus_message))); + t->header = (BusMessageHeader*) ((uint8_t*) t + ALIGN(sizeof(struct sd_bus_message))); t->header->endian = BUS_NATIVE_ENDIAN; t->header->type = type; t->header->version = bus->message_version; @@ -1085,8 +1085,8 @@ _public_ int sd_bus_message_set_allow_interactive_authorization(sd_bus_message * return 0; } -static struct bus_body_part *message_append_part(sd_bus_message *m) { - struct bus_body_part *part; +static BusMessageBodyPart *message_append_part(sd_bus_message *m) { + BusMessageBodyPart *part; assert(m); @@ -1099,7 +1099,7 @@ static struct bus_body_part *message_append_part(sd_bus_message *m) { } else { assert(m->body_end); - part = new0(struct bus_body_part, 1); + part = new0(BusMessageBodyPart, 1); if (!part) { m->poisoned = true; return NULL; @@ -1115,7 +1115,7 @@ static struct bus_body_part *message_append_part(sd_bus_message *m) { return part; } -static void part_zero(struct bus_body_part *part, size_t sz) { +static void part_zero(BusMessageBodyPart *part, size_t sz) { assert(part); assert(sz > 0); assert(sz < 8); @@ -1131,7 +1131,7 @@ static void part_zero(struct bus_body_part *part, size_t sz) { static int part_make_space( struct sd_bus_message *m, - struct bus_body_part *part, + BusMessageBodyPart *part, size_t sz, void **q) { @@ -1176,7 +1176,7 @@ static void message_extend_containers(sd_bus_message *m, size_t expand) { return; /* Update counters */ - for (struct bus_container *c = m->containers; c < m->containers + m->n_containers; c++) + for (BusMessageContainer *c = m->containers; c < m->containers + m->n_containers; c++) if (c->array_size) *c->array_size += expand; } @@ -1210,7 +1210,7 @@ static void *message_extend_body( } if (added > 0) { - struct bus_body_part *part = NULL; + BusMessageBodyPart *part = NULL; bool add_new_part; add_new_part = @@ -1258,7 +1258,7 @@ static void *message_extend_body( /* Readjust pointers */ if (m->n_containers > 0) - for (struct bus_container *c = m->containers; c < m->containers + m->n_containers; c++) + for (BusMessageContainer *c = m->containers; c < m->containers + m->n_containers; c++) c->array_size = adjust_pointer(c->array_size, op, os, part->data); m->error.message = (const char*) adjust_pointer(m->error.message, op, os, part->data); @@ -1302,7 +1302,7 @@ static int message_push_fd(sd_bus_message *m, int fd) { int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored) { _cleanup_close_ int fd = -EBADF; - struct bus_container *c; + BusMessageContainer *c; ssize_t align, sz; uint32_t u32; void *a; @@ -1444,7 +1444,7 @@ _public_ int sd_bus_message_append_string_space( size_t size, char **s) { - struct bus_container *c; + BusMessageContainer *c; void *a; assert_return(m, -EINVAL); @@ -1524,7 +1524,7 @@ _public_ int sd_bus_message_append_string_iovec( static int bus_message_open_array( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents, uint32_t **array_size, size_t *begin) { @@ -1533,7 +1533,7 @@ static int bus_message_open_array( int alignment; void *a, *op; size_t os; - struct bus_body_part *o; + BusMessageBodyPart *o; assert(m); assert(c); @@ -1603,7 +1603,7 @@ static int bus_message_open_array( static int bus_message_open_variant( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents) { size_t l; @@ -1653,7 +1653,7 @@ static int bus_message_open_variant( static int bus_message_open_struct( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents, size_t *begin) { @@ -1705,7 +1705,7 @@ static int bus_message_open_struct( static int bus_message_open_dict_entry( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents, size_t *begin) { @@ -1744,7 +1744,7 @@ _public_ int sd_bus_message_open_container( char type, const char *contents) { - struct bus_container *c; + BusMessageContainer *c; uint32_t *array_size = NULL; _cleanup_free_ char *signature = NULL; size_t before, begin = 0; @@ -1788,7 +1788,7 @@ _public_ int sd_bus_message_open_container( return r; /* OK, let's fill it in */ - m->containers[m->n_containers++] = (struct bus_container) { + m->containers[m->n_containers++] = (BusMessageContainer) { .enclosing = type, .signature = TAKE_PTR(signature), .array_size = array_size, @@ -1800,7 +1800,7 @@ _public_ int sd_bus_message_open_container( } _public_ int sd_bus_message_close_container(sd_bus_message *m) { - struct bus_container *c; + BusMessageContainer *c; assert_return(m, -EINVAL); assert_return(!m->sealed, -EPERM); @@ -1820,13 +1820,13 @@ _public_ int sd_bus_message_close_container(sd_bus_message *m) { return 0; } -typedef struct { +typedef struct BusTypeStack { const char *types; unsigned n_struct; unsigned n_array; -} TypeStack; +} BusTypeStack; -static int type_stack_push(TypeStack *stack, unsigned max, unsigned *i, const char *types, unsigned n_struct, unsigned n_array) { +static int type_stack_push(BusTypeStack *stack, unsigned max, unsigned *i, const char *types, unsigned n_struct, unsigned n_array) { assert(stack); assert(max > 0); @@ -1841,7 +1841,7 @@ static int type_stack_push(TypeStack *stack, unsigned max, unsigned *i, const ch return 0; } -static int type_stack_pop(TypeStack *stack, unsigned max, unsigned *i, const char **types, unsigned *n_struct, unsigned *n_array) { +static int type_stack_pop(BusTypeStack *stack, unsigned max, unsigned *i, const char **types, unsigned *n_struct, unsigned *n_array) { assert(stack); assert(max > 0); assert(types); @@ -1865,7 +1865,7 @@ _public_ int sd_bus_message_appendv( va_list ap) { unsigned n_array, n_struct; - TypeStack stack[BUS_CONTAINER_DEPTH]; + BusTypeStack stack[BUS_CONTAINER_DEPTH]; unsigned stack_ptr = 0; int r; @@ -2184,7 +2184,7 @@ _public_ int sd_bus_message_append_array_memfd( uint64_t size) { _cleanup_close_ int copy_fd = -EBADF; - struct bus_body_part *part; + BusMessageBodyPart *part; ssize_t align, sz; uint64_t real_size; void *a; @@ -2260,8 +2260,8 @@ _public_ int sd_bus_message_append_string_memfd( uint64_t size) { _cleanup_close_ int copy_fd = -EBADF; - struct bus_body_part *part; - struct bus_container *c; + BusMessageBodyPart *part; + BusMessageContainer *c; uint64_t real_size; void *a; int r; @@ -2375,7 +2375,7 @@ static int bus_message_close_header(sd_bus_message *m) { } _public_ int sd_bus_message_seal(sd_bus_message *m, uint64_t cookie, uint64_t timeout_usec) { - struct bus_body_part *part; + BusMessageBodyPart *part; size_t a; unsigned i; int r; @@ -2466,7 +2466,7 @@ _public_ int sd_bus_message_seal(sd_bus_message *m, uint64_t cookie, uint64_t ti return 0; } -int bus_body_part_map(struct bus_body_part *part) { +int bus_body_part_map(BusMessageBodyPart *part) { void *p; size_t psz, shift; @@ -2508,7 +2508,7 @@ int bus_body_part_map(struct bus_body_part *part) { return 0; } -void bus_body_part_unmap(struct bus_body_part *part) { +void bus_body_part_unmap(BusMessageBodyPart *part) { assert_se(part); @@ -2532,7 +2532,7 @@ void bus_body_part_unmap(struct bus_body_part *part) { } static bool message_end_of_signature(sd_bus_message *m) { - struct bus_container *c; + BusMessageContainer *c; assert(m); @@ -2541,7 +2541,7 @@ static bool message_end_of_signature(sd_bus_message *m) { } static bool message_end_of_array(sd_bus_message *m, size_t index) { - struct bus_container *c; + BusMessageContainer *c; assert(m); @@ -2569,8 +2569,8 @@ _public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) { return false; } -static struct bus_body_part* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) { - struct bus_body_part *part; +static BusMessageBodyPart* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) { + BusMessageBodyPart *part; size_t begin; int r; @@ -2619,7 +2619,7 @@ static int message_peek_body( void **ret) { size_t k, start, end, padding; - struct bus_body_part *part; + BusMessageBodyPart *part; uint8_t *q; assert(m); @@ -2712,7 +2712,7 @@ static bool validate_object_path(const char *s, size_t l) { } _public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) { - struct bus_container *c; + BusMessageContainer *c; size_t rindex; void *q; int r; @@ -2853,7 +2853,7 @@ _public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) { static int bus_message_enter_array( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents, uint32_t **array_size) { @@ -2907,7 +2907,7 @@ static int bus_message_enter_array( static int bus_message_enter_variant( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents) { size_t rindex; @@ -2962,7 +2962,7 @@ static int bus_message_enter_variant( static int bus_message_enter_struct( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents) { size_t l; @@ -2997,7 +2997,7 @@ static int bus_message_enter_struct( static int bus_message_enter_dict_entry( sd_bus_message *m, - struct bus_container *c, + BusMessageContainer *c, const char *contents) { size_t l; @@ -3036,7 +3036,7 @@ static int bus_message_enter_dict_entry( _public_ int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *contents) { - struct bus_container *c; + BusMessageContainer *c; uint32_t *array_size = NULL; _cleanup_free_ char *signature = NULL; size_t before; @@ -3116,7 +3116,7 @@ _public_ int sd_bus_message_enter_container(sd_bus_message *m, return r; /* OK, let's fill it in */ - m->containers[m->n_containers++] = (struct bus_container) { + m->containers[m->n_containers++] = (BusMessageContainer) { .enclosing = type, .signature = TAKE_PTR(signature), @@ -3131,7 +3131,7 @@ _public_ int sd_bus_message_enter_container(sd_bus_message *m, } _public_ int sd_bus_message_exit_container(sd_bus_message *m) { - struct bus_container *c; + BusMessageContainer *c; assert_return(m, -EINVAL); assert_return(m->sealed, -EPERM); @@ -3158,7 +3158,7 @@ _public_ int sd_bus_message_exit_container(sd_bus_message *m) { } static void message_quit_container(sd_bus_message *m) { - struct bus_container *c; + BusMessageContainer *c; assert(m); assert(m->sealed); @@ -3178,7 +3178,7 @@ static void message_quit_container(sd_bus_message *m) { } _public_ int sd_bus_message_peek_type(sd_bus_message *m, char *ret_type, const char **ret_contents) { - struct bus_container *c; + BusMessageContainer *c; int r; assert_return(m, -EINVAL); @@ -3291,7 +3291,7 @@ eof: } _public_ int sd_bus_message_rewind(sd_bus_message *m, int complete) { - struct bus_container *c; + BusMessageContainer *c; assert_return(m, -EINVAL); assert_return(m->sealed, -EPERM); @@ -3317,7 +3317,7 @@ _public_ int sd_bus_message_readv( va_list ap) { unsigned n_array, n_struct; - TypeStack stack[BUS_CONTAINER_DEPTH]; + BusTypeStack stack[BUS_CONTAINER_DEPTH]; unsigned stack_ptr = 0; unsigned n_loop = 0; int r; @@ -3532,7 +3532,7 @@ _public_ int sd_bus_message_skip(sd_bus_message *m, const char *types) { /* If types is NULL, read exactly one element */ if (!types) { - struct bus_container *c; + BusMessageContainer *c; size_t l; if (message_end_of_signature(m)) @@ -3692,7 +3692,7 @@ _public_ int sd_bus_message_read_array( const void **ptr, size_t *size) { - struct bus_container *c; + BusMessageContainer *c; void *p; size_t sz; ssize_t align; @@ -4266,7 +4266,7 @@ int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) { size_t total; void *p, *e; size_t i; - struct bus_body_part *part; + BusMessageBodyPart *part; assert(m); assert(buffer); @@ -4430,7 +4430,7 @@ _public_ int sd_bus_message_get_errno(sd_bus_message *m) { } _public_ const char* sd_bus_message_get_signature(sd_bus_message *m, int complete) { - struct bus_container *c; + BusMessageContainer *c; assert_return(m, NULL); diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h index 0f1cc8f33e5..d4c80022795 100644 --- a/src/libsystemd/sd-bus/bus-message.h +++ b/src/libsystemd/sd-bus/bus-message.h @@ -7,11 +7,23 @@ #include "sd-bus-protocol.h" #include "bus-creds.h" +#include "bus-forward.h" #include "bus-protocol.h" -#include "forward.h" #include "memory-util.h" -struct bus_container { +typedef struct BusMessageHeader { + uint8_t endian; + uint8_t type; + uint8_t flags; + uint8_t version; + uint32_t body_size; + /* Note that what the bus spec calls "serial" we'll call "cookie" instead, because we don't + * want to imply that the cookie was in any way monotonically increasing. */ + uint32_t serial; + uint32_t fields_size; +} _packed_ BusMessageHeader; + +typedef struct BusMessageContainer { char enclosing; /* Indexes into the signature string */ @@ -24,10 +36,10 @@ struct bus_container { uint32_t *array_size; char *peeked_signature; -}; +} BusMessageContainer; -struct bus_body_part { - struct bus_body_part *next; +typedef struct BusMessageBodyPart { + BusMessageBodyPart *next; void *data; void *mmap_begin; size_t size; @@ -39,7 +51,7 @@ struct bus_body_part { bool munmap_this:1; bool sealed:1; bool is_zero:1; -}; +} BusMessageBodyPart; typedef struct sd_bus_message { /* Caveat: a message can be referenced in two different ways: the main (user-facing) way will also @@ -81,24 +93,24 @@ typedef struct sd_bus_message { bool sensitive:1; /* The first bytes of the message */ - struct bus_header *header; + BusMessageHeader *header; size_t fields_size; size_t body_size; size_t user_body_size; - struct bus_body_part body; - struct bus_body_part *body_end; + BusMessageBodyPart body; + BusMessageBodyPart *body_end; unsigned n_body_parts; size_t rindex; - struct bus_body_part *cached_rindex_part; + BusMessageBodyPart *cached_rindex_part; size_t cached_rindex_part_begin; uint32_t n_fds; int *fds; - struct bus_container root_container, *containers; + BusMessageContainer root_container, *containers; size_t n_containers; struct iovec *iovec; @@ -142,19 +154,19 @@ static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) { static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) { return - sizeof(struct bus_header) + + sizeof(BusMessageHeader) + ALIGN8(m->fields_size) + m->body_size; } static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) { return - sizeof(struct bus_header) + + sizeof(BusMessageHeader) + ALIGN8(m->fields_size); } static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) { - return (uint8_t*) m->header + sizeof(struct bus_header); + return (uint8_t*) m->header + sizeof(BusMessageHeader); } int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz); @@ -174,8 +186,8 @@ int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv); #define MESSAGE_FOREACH_PART(part, i, m) \ for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next) -int bus_body_part_map(struct bus_body_part *part); -void bus_body_part_unmap(struct bus_body_part *part); +int bus_body_part_map(BusMessageBodyPart *part); +void bus_body_part_unmap(BusMessageBodyPart *part); int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m); diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index 3e827770c84..7309ad621a0 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -20,7 +20,7 @@ static int node_vtable_get_userdata( sd_bus *bus, const char *path, - struct node_vtable *c, + BusNodeVTable *c, void **userdata, sd_bus_error *error) { @@ -77,7 +77,7 @@ static void *vtable_property_convert_userdata(const sd_bus_vtable *p, void *u) { static int vtable_property_get_userdata( sd_bus *bus, const char *path, - struct vtable_member *p, + BusVTableMember *p, void **userdata, sd_bus_error *error) { @@ -102,7 +102,7 @@ static int vtable_property_get_userdata( static int add_enumerated_to_set( sd_bus *bus, const char *prefix, - struct node_enumerator *first, + BusNodeEnumerator *first, OrderedSet *s, sd_bus_error *error) { @@ -174,7 +174,7 @@ enum { static int add_subtree_to_set( sd_bus *bus, const char *prefix, - struct node *n, + BusNode *n, unsigned flags, OrderedSet *s, sd_bus_error *error) { @@ -222,7 +222,7 @@ static int add_subtree_to_set( static int get_child_nodes( sd_bus *bus, const char *prefix, - struct node *n, + BusNode *n, unsigned flags, OrderedSet **ret, sd_bus_error *error) { @@ -250,7 +250,7 @@ static int get_child_nodes( static int node_callbacks_run( sd_bus *bus, sd_bus_message *m, - struct node_callback *first, + BusNodeCallback *first, bool require_fallback, bool *found_object) { @@ -301,7 +301,7 @@ static int node_callbacks_run( #define CAPABILITY_SHIFT(x) (((x) >> __builtin_ctzll(_SD_BUS_VTABLE_CAPABILITY_MASK)) & 0xFFFF) -static int check_access(sd_bus *bus, sd_bus_message *m, struct vtable_member *c, sd_bus_error *error) { +static int check_access(sd_bus *bus, sd_bus_message *m, BusVTableMember *c, sd_bus_error *error) { uint64_t cap; int r; @@ -340,7 +340,7 @@ static int check_access(sd_bus *bus, sd_bus_message *m, struct vtable_member *c, static int method_callbacks_run( sd_bus *bus, sd_bus_message *m, - struct vtable_member *c, + BusVTableMember *c, bool require_fallback, bool *found_object) { @@ -565,7 +565,7 @@ static int invoke_property_set( static int property_get_set_callbacks_run( sd_bus *bus, sd_bus_message *m, - struct vtable_member *c, + BusVTableMember *c, bool require_fallback, bool is_get, bool *found_object) { @@ -697,7 +697,7 @@ static int vtable_append_one_property( sd_bus *bus, sd_bus_message *reply, const char *path, - struct node_vtable *c, + BusNodeVTable *c, const sd_bus_vtable *v, void *userdata, sd_bus_error *error) { @@ -752,7 +752,7 @@ static int vtable_append_all_properties( sd_bus *bus, sd_bus_message *reply, const char *path, - struct node_vtable *c, + BusNodeVTable *c, void *userdata, sd_bus_error *error) { @@ -800,7 +800,7 @@ static int vtable_append_all_properties( static int property_get_all_callbacks_run( sd_bus *bus, sd_bus_message *m, - struct node_vtable *first, + BusNodeVTable *first, bool require_fallback, const char *iface, bool *found_object) { @@ -881,7 +881,7 @@ static int property_get_all_callbacks_run( static int bus_node_exists( sd_bus *bus, - struct node *n, + BusNode *n, const char *path, bool require_fallback) { @@ -923,7 +923,7 @@ static int bus_node_exists( int introspect_path( sd_bus *bus, const char *path, - struct node *n, + BusNode *n, bool require_fallback, bool ignore_nodes_modified, bool *found_object, @@ -931,7 +931,7 @@ int introspect_path( sd_bus_error *error) { _cleanup_ordered_set_free_ OrderedSet *s = NULL; - _cleanup_(introspect_done) struct introspect intro = {}; + _cleanup_(introspect_done) BusIntrospect intro = {}; bool empty; int r; @@ -1006,7 +1006,7 @@ int introspect_path( static int process_introspect( sd_bus *bus, sd_bus_message *m, - struct node *n, + BusNode *n, bool require_fallback, bool *found_object) { @@ -1053,7 +1053,7 @@ static int object_manager_serialize_path( const char *previous_interface = NULL; bool found_something = false; - struct node *n; + BusNode *n; int r; assert(bus); @@ -1227,7 +1227,7 @@ static int object_manager_serialize_path_and_fallbacks( static int process_get_managed_objects( sd_bus *bus, sd_bus_message *m, - struct node *n, + BusNode *n, bool require_fallback, bool *found_object) { @@ -1290,8 +1290,8 @@ static int object_find_and_run( bool require_fallback, bool *found_object) { - struct node *n; - struct vtable_member vtable_key, *v; + BusNode *n; + BusVTableMember vtable_key, *v; int r; assert(bus); @@ -1484,8 +1484,8 @@ int bus_process_object(sd_bus *bus, sd_bus_message *m) { return 1; } -static struct node* bus_node_allocate(sd_bus *bus, const char *path) { - struct node *n, *parent; +static BusNode* bus_node_allocate(sd_bus *bus, const char *path) { + BusNode *n, *parent; const char *e; _cleanup_free_ char *s = NULL; char *p; @@ -1519,7 +1519,7 @@ static struct node* bus_node_allocate(sd_bus *bus, const char *path) { return NULL; } - n = new0(struct node, 1); + n = new0(BusNode, 1); if (!n) return NULL; @@ -1538,7 +1538,7 @@ static struct node* bus_node_allocate(sd_bus *bus, const char *path) { return n; } -void bus_node_gc(sd_bus *b, struct node *n) { +void bus_node_gc(sd_bus *b, BusNode *n) { assert(b); if (!n) @@ -1561,8 +1561,8 @@ void bus_node_gc(sd_bus *b, struct node *n) { free(n); } -static int bus_find_parent_object_manager(sd_bus *bus, struct node **out, const char *path, bool* path_has_object_manager) { - struct node *n; +static int bus_find_parent_object_manager(sd_bus *bus, BusNode **out, const char *path, bool* path_has_object_manager) { + BusNode *n; assert(bus); assert(path); @@ -1607,7 +1607,7 @@ static int bus_add_object( void *userdata) { sd_bus_slot *s; - struct node *n; + BusNode *n; int r; assert_return(bus, -EINVAL); @@ -1620,7 +1620,7 @@ static int bus_add_object( if (!n) return -ENOMEM; - s = bus_slot_allocate(bus, !slot, BUS_NODE_CALLBACK, sizeof(struct node_callback), userdata); + s = bus_slot_allocate(bus, !slot, BUS_NODE_CALLBACK, sizeof(BusNodeCallback), userdata); if (!s) { r = -ENOMEM; goto fail; @@ -1665,7 +1665,7 @@ _public_ int sd_bus_add_fallback( return bus_add_object(bus, slot, true, prefix, callback, userdata); } -static void vtable_member_hash_func(const struct vtable_member *m, struct siphash *state) { +static void vtable_member_hash_func(const BusVTableMember *m, struct siphash *state) { assert(m); string_hash_func(m->path, state); @@ -1673,7 +1673,7 @@ static void vtable_member_hash_func(const struct vtable_member *m, struct siphas string_hash_func(m->member, state); } -static int vtable_member_compare_func(const struct vtable_member *x, const struct vtable_member *y) { +static int vtable_member_compare_func(const BusVTableMember *x, const BusVTableMember *y) { int r; assert(x); @@ -1692,7 +1692,7 @@ static int vtable_member_compare_func(const struct vtable_member *x, const struc DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR( vtable_member_hash_ops, - struct vtable_member, vtable_member_hash_func, vtable_member_compare_func, free); + BusVTableMember, vtable_member_hash_func, vtable_member_compare_func, free); typedef enum { NAMES_FIRST_PART = 1 << 0, /* first part of argument name list (input names). It is reset by names_are_valid() */ @@ -1796,9 +1796,9 @@ static int add_object_vtable_internal( void *userdata) { sd_bus_slot *s = NULL; - struct node_vtable *existing = NULL; + BusNodeVTable *existing = NULL; const sd_bus_vtable *v; - struct node *n; + BusNode *n; int r; const char *names = ""; names_flags nf; @@ -1839,7 +1839,7 @@ static int add_object_vtable_internal( } } - s = bus_slot_allocate(bus, !slot, BUS_NODE_VTABLE, sizeof(struct node_vtable), userdata); + s = bus_slot_allocate(bus, !slot, BUS_NODE_VTABLE, sizeof(BusNodeVTable), userdata); if (!s) { r = -ENOMEM; goto fail; @@ -1861,7 +1861,7 @@ static int add_object_vtable_internal( switch (v->type) { case _SD_BUS_VTABLE_METHOD: { - struct vtable_member *m; + BusVTableMember *m; nf = NAMES_FIRST_PART; if (bus_vtable_has_names(vtable)) @@ -1878,7 +1878,7 @@ static int add_object_vtable_internal( goto fail; } - m = new0(struct vtable_member, 1); + m = new0(BusVTableMember, 1); if (!m) { r = -ENOMEM; goto fail; @@ -1915,7 +1915,7 @@ static int add_object_vtable_internal( _fallthrough_; case _SD_BUS_VTABLE_PROPERTY: { - struct vtable_member *m; + BusVTableMember *m; if (!member_name_is_valid(v->x.property.member) || !signature_is_single(v->x.property.signature, false) || @@ -1928,7 +1928,7 @@ static int add_object_vtable_internal( goto fail; } - m = new0(struct vtable_member, 1); + m = new0(BusVTableMember, 1); if (!m) { r = -ENOMEM; goto fail; @@ -2023,7 +2023,7 @@ _public_ int sd_bus_add_node_enumerator( void *userdata) { sd_bus_slot *s; - struct node *n; + BusNode *n; int r; assert_return(bus, -EINVAL); @@ -2036,7 +2036,7 @@ _public_ int sd_bus_add_node_enumerator( if (!n) return -ENOMEM; - s = bus_slot_allocate(bus, !slot, BUS_NODE_ENUMERATOR, sizeof(struct node_enumerator), userdata); + s = bus_slot_allocate(bus, !slot, BUS_NODE_ENUMERATOR, sizeof(BusNodeEnumerator), userdata); if (!s) { r = -ENOMEM; goto fail; @@ -2072,8 +2072,8 @@ static int emit_properties_changed_on_interface( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; bool has_invalidating = false, has_changing = false; - struct vtable_member key = {}; - struct node *n; + BusVTableMember key = {}; + BusNode *n; void *u = NULL; int r; @@ -2125,7 +2125,7 @@ static int emit_properties_changed_on_interface( * PropertiesChanged message */ STRV_FOREACH(property, names) { - struct vtable_member *v; + BusVTableMember *v; assert_return(member_name_is_valid(*property), -EINVAL); @@ -2221,7 +2221,7 @@ static int emit_properties_changed_on_interface( if (names) { STRV_FOREACH(property, names) { - struct vtable_member *v; + BusVTableMember *v; key.member = *property; assert_se(v = set_get(bus->vtable_properties, &key)); @@ -2365,7 +2365,7 @@ static int object_added_append_all_prefix( bool require_fallback) { const char *previous_interface = NULL; - struct node *n; + BusNode *n; int r; assert(bus); @@ -2515,7 +2515,7 @@ static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *p _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; - struct node *object_manager; + BusNode *object_manager; int r; /* @@ -2587,7 +2587,7 @@ static int object_removed_append_all_prefix( bool require_fallback) { const char *previous_interface = NULL; - struct node *n; + BusNode *n; int r; assert(bus); @@ -2695,7 +2695,7 @@ static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char _public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; - struct node *object_manager; + BusNode *object_manager; int r; /* @@ -2768,7 +2768,7 @@ static int interfaces_added_append_one_prefix( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; bool found_interface = false; - struct node *n; + BusNode *n; void *u = NULL; int r; @@ -2865,7 +2865,7 @@ static int interfaces_added_append_one( _public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; - struct node *object_manager; + BusNode *object_manager; int r; assert_return(bus, -EINVAL); @@ -2960,7 +2960,7 @@ _public_ int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const c _public_ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; - struct node *object_manager; + BusNode *object_manager; int r; assert_return(bus, -EINVAL); @@ -3021,7 +3021,7 @@ _public_ int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const _public_ int sd_bus_add_object_manager(sd_bus *bus, sd_bus_slot **slot, const char *path) { sd_bus_slot *s; - struct node *n; + BusNode *n; int r; assert_return(bus, -EINVAL); @@ -3033,7 +3033,7 @@ _public_ int sd_bus_add_object_manager(sd_bus *bus, sd_bus_slot **slot, const ch if (!n) return -ENOMEM; - s = bus_slot_allocate(bus, !slot, BUS_NODE_OBJECT_MANAGER, sizeof(struct node_object_manager), NULL); + s = bus_slot_allocate(bus, !slot, BUS_NODE_OBJECT_MANAGER, sizeof(BusNodeObjectManager), NULL); if (!s) { r = -ENOMEM; goto fail; diff --git a/src/libsystemd/sd-bus/bus-objects.h b/src/libsystemd/sd-bus/bus-objects.h index 51bfa70ae5e..a1cbe4b6ffa 100644 --- a/src/libsystemd/sd-bus/bus-objects.h +++ b/src/libsystemd/sd-bus/bus-objects.h @@ -1,19 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "forward.h" - -struct node; +#include "bus-forward.h" const sd_bus_vtable* bus_vtable_next(const sd_bus_vtable *vtable, const sd_bus_vtable *v); bool bus_vtable_has_names(const sd_bus_vtable *vtable); int bus_process_object(sd_bus *bus, sd_bus_message *m); -void bus_node_gc(sd_bus *b, struct node *n); +void bus_node_gc(sd_bus *b, BusNode *n); int introspect_path( sd_bus *bus, const char *path, - struct node *n, + BusNode *n, bool require_fallback, bool ignore_nodes_modified, bool *found_object, diff --git a/src/libsystemd/sd-bus/bus-protocol.h b/src/libsystemd/sd-bus/bus-protocol.h index 92e251727c1..5539867f15e 100644 --- a/src/libsystemd/sd-bus/bus-protocol.h +++ b/src/libsystemd/sd-bus/bus-protocol.h @@ -3,22 +3,6 @@ #include -#include "forward.h" - -/* Packet header */ - -struct _packed_ bus_header { - uint8_t endian; - uint8_t type; - uint8_t flags; - uint8_t version; - uint32_t body_size; - /* Note that what the bus spec calls "serial" we'll call "cookie" instead, because we don't - * want to imply that the cookie was in any way monotonically increasing. */ - uint32_t serial; - uint32_t fields_size; -}; - /* Endianness */ enum { diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 3b6debadb03..172cb23f5e5 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -4,6 +4,7 @@ #include "alloc-util.h" #include "bus-control.h" +#include "bus-internal.h" #include "bus-objects.h" #include "bus-slot.h" #include "prioq.h" @@ -120,12 +121,12 @@ void bus_slot_disconnect(sd_bus_slot *slot, bool unref) { const sd_bus_vtable *v; for (v = slot->node_vtable.vtable; v->type != _SD_BUS_VTABLE_END; v = bus_vtable_next(slot->node_vtable.vtable, v)) { - struct vtable_member *x = NULL; + BusVTableMember *x = NULL; switch (v->type) { case _SD_BUS_VTABLE_METHOD: { - struct vtable_member key; + BusVTableMember key; key.path = slot->node_vtable.node->path; key.interface = slot->node_vtable.interface; @@ -137,7 +138,7 @@ void bus_slot_disconnect(sd_bus_slot *slot, bool unref) { case _SD_BUS_VTABLE_PROPERTY: case _SD_BUS_VTABLE_WRITABLE_PROPERTY: { - struct vtable_member key; + BusVTableMember key; key.path = slot->node_vtable.node->path; key.interface = slot->node_vtable.interface; diff --git a/src/libsystemd/sd-bus/bus-slot.h b/src/libsystemd/sd-bus/bus-slot.h index 5bd3b081eac..21feab57295 100644 --- a/src/libsystemd/sd-bus/bus-slot.h +++ b/src/libsystemd/sd-bus/bus-slot.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "bus-internal.h" -#include "forward.h" +#include "bus-forward.h" sd_bus_slot *bus_slot_allocate(sd_bus *bus, bool floating, BusSlotType type, size_t extra, void *userdata); diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 9d911aaaa61..a8d47d84282 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -64,7 +64,7 @@ static int append_iovec(sd_bus_message *m, const void *p, size_t sz) { } static int bus_message_setup_iovec(sd_bus_message *m) { - struct bus_body_part *part; + BusMessageBodyPart *part; unsigned n, i; int r; @@ -1285,8 +1285,8 @@ static int bus_socket_read_message_need(sd_bus *bus, size_t *need) { assert(need); assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO)); - if (bus->rbuffer_size < sizeof(struct bus_header)) { - *need = sizeof(struct bus_header) + 8; + if (bus->rbuffer_size < sizeof(BusMessageHeader)) { + *need = sizeof(BusMessageHeader) + 8; /* Minimum message size: * @@ -1320,7 +1320,7 @@ static int bus_socket_read_message_need(sd_bus *bus, size_t *need) { } else return -EBADMSG; - sum = (uint64_t) sizeof(struct bus_header) + (uint64_t) ALIGN8(b) + (uint64_t) a; + sum = (uint64_t) sizeof(BusMessageHeader) + (uint64_t) ALIGN8(b) + (uint64_t) a; if (sum >= BUS_MESSAGE_SIZE_MAX) return -ENOBUFS; diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c index 9e5b5e96206..6e9968f11b9 100644 --- a/src/libsystemd/sd-bus/bus-track.c +++ b/src/libsystemd/sd-bus/bus-track.c @@ -9,11 +9,11 @@ #include "log.h" #include "string-util.h" -struct track_item { +typedef struct BusTrackItem { unsigned n_ref; char *name; sd_bus_slot *slot; -}; +} BusTrackItem; struct sd_bus_track { unsigned n_ref; @@ -41,7 +41,7 @@ struct sd_bus_track { "member='NameOwnerChanged'," \ "arg0='", name, "'") -static struct track_item* track_item_free(struct track_item *i) { +static BusTrackItem* track_item_free(BusTrackItem *i) { if (!i) return NULL; @@ -50,10 +50,10 @@ static struct track_item* track_item_free(struct track_item *i) { return mfree(i); } -DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(struct track_item, track_item, track_item_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct track_item*, track_item_unref); +DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(BusTrackItem, track_item, track_item_free); +DEFINE_TRIVIAL_CLEANUP_FUNC(BusTrackItem*, track_item_unref); DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(track_item_hash_ops, char, string_hash_func, string_compare_func, - struct track_item, track_item_free); + BusTrackItem, track_item_free); static void bus_track_add_to_queue(sd_bus_track *track) { assert(track); @@ -97,7 +97,7 @@ static void bus_track_remove_from_queue(sd_bus_track *track) { } static int bus_track_remove_name_fully(sd_bus_track *track, const char *name) { - struct track_item *i; + BusTrackItem *i; assert(track); assert(name); @@ -181,8 +181,8 @@ static int on_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus } _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) { - _cleanup_(track_item_unrefp) struct track_item *n = NULL; - struct track_item *i; + _cleanup_(track_item_unrefp) BusTrackItem *n = NULL; + BusTrackItem *i; const char *match; int r; @@ -212,11 +212,11 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) { if (r < 0) return r; - n = new(struct track_item, 1); + n = new(BusTrackItem, 1); if (!n) return -ENOMEM; - *n = (struct track_item) { + *n = (BusTrackItem) { .n_ref = 1, }; @@ -260,7 +260,7 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) { } _public_ int sd_bus_track_remove_name(sd_bus_track *track, const char *name) { - struct track_item *i; + BusTrackItem *i; assert_return(name, -EINVAL); @@ -482,7 +482,7 @@ _public_ int sd_bus_track_count_sender(sd_bus_track *track, sd_bus_message *m) { } _public_ int sd_bus_track_count_name(sd_bus_track *track, const char *name) { - struct track_item *i; + BusTrackItem *i; assert_return(service_name_is_valid(name), -EINVAL); diff --git a/src/libsystemd/sd-bus/fuzz-bus-match.c b/src/libsystemd/sd-bus/fuzz-bus-match.c index e6e3dd97d0f..32821912a4d 100644 --- a/src/libsystemd/sd-bus/fuzz-bus-match.c +++ b/src/libsystemd/sd-bus/fuzz-bus-match.c @@ -23,7 +23,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { r = sd_bus_new(&bus); assert_se(r >= 0); - _cleanup_(bus_match_free) struct bus_match_node root = { + _cleanup_(bus_match_free) BusMatchNode root = { .type = BUS_MATCH_ROOT, }; @@ -50,7 +50,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { offset = end ? (size_t) (end - (char*) data + 1) : size; - struct bus_match_component *components; + BusMatchComponent *components; size_t n_components; r = bus_match_parse(line, &components, &n_components); if (IN_SET(r, -EINVAL, -ENOMEM)) { diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index c13a8982121..07bf7003a2e 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -522,7 +522,7 @@ static int synthesize_connected_signal(sd_bus *bus) { return 0; } -void bus_set_state(sd_bus *bus, enum bus_state state) { +void bus_set_state(sd_bus *bus, BusState state) { static const char* const table[_BUS_STATE_MAX] = { [BUS_UNSET] = "UNSET", [BUS_WATCH_BIND] = "WATCH_BIND", @@ -616,7 +616,7 @@ static int bus_send_hello(sd_bus *bus) { } int bus_start_running(sd_bus *bus) { - struct reply_callback *c; + BusReplyCallback *c; usec_t n; int r; @@ -2294,7 +2294,7 @@ static usec_t calc_elapse(sd_bus *bus, uint64_t usec) { } static int timeout_compare(const void *a, const void *b) { - const struct reply_callback *x = a, *y = b; + const BusReplyCallback *x = a, *y = b; if (x->timeout_usec != 0 && y->timeout_usec == 0) return -1; @@ -2347,7 +2347,7 @@ _public_ int sd_bus_call_async( return r; if (slot || callback) { - s = bus_slot_allocate(bus, !slot, BUS_REPLY_CALLBACK, sizeof(struct reply_callback), userdata); + s = bus_slot_allocate(bus, !slot, BUS_REPLY_CALLBACK, sizeof(BusReplyCallback), userdata); if (!s) return -ENOMEM; @@ -2622,7 +2622,7 @@ _public_ int sd_bus_get_events(sd_bus *bus) { } _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) { - struct reply_callback *c; + BusReplyCallback *c; assert_return(bus, -EINVAL); assert_return(bus = bus_resolve(bus), -ENOPKG); @@ -2681,7 +2681,7 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) { static int process_timeout(sd_bus *bus) { _cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message* m = NULL; - struct reply_callback *c; + BusReplyCallback *c; sd_bus_slot *slot; bool is_hello; usec_t n; @@ -2771,7 +2771,7 @@ static int process_hello(sd_bus *bus, sd_bus_message *m) { static int process_reply(sd_bus *bus, sd_bus_message *m) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *synthetic_reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL; - struct reply_callback *c; + BusReplyCallback *c; sd_bus_slot *slot; bool is_hello; int r; @@ -3140,7 +3140,7 @@ static int bus_exit_now(sd_bus *bus, sd_event *event) { assert_not_reached(); } -static int process_closing_reply_callback(sd_bus *bus, struct reply_callback *c) { +static int process_closing_reply_callback(sd_bus *bus, BusReplyCallback *c) { _cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; sd_bus_slot *slot; @@ -3196,7 +3196,7 @@ static int process_closing_reply_callback(sd_bus *bus, struct reply_callback *c) static int process_closing(sd_bus *bus, sd_bus_message **ret) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; _cleanup_(sd_event_unrefp) sd_event *event = NULL; - struct reply_callback *c; + BusReplyCallback *c; int r; assert(bus); @@ -3480,7 +3480,7 @@ _public_ int sd_bus_add_filter( assert_return(callback, -EINVAL); assert_return(!bus_origin_changed(bus), -ECHILD); - s = bus_slot_allocate(bus, !slot, BUS_FILTER_CALLBACK, sizeof(struct filter_callback), userdata); + s = bus_slot_allocate(bus, !slot, BUS_FILTER_CALLBACK, sizeof(BusFilterCallback), userdata); if (!s) return -ENOMEM; @@ -3568,7 +3568,7 @@ int bus_add_match_full( void *userdata, uint64_t timeout_usec) { - struct bus_match_component *components = NULL; + BusMatchComponent *components = NULL; size_t n_components = 0; _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *s = NULL; int r; @@ -3584,7 +3584,7 @@ int bus_add_match_full( if (r < 0) return r; - s = bus_slot_allocate(bus, !slot, BUS_MATCH_CALLBACK, sizeof(struct match_callback), userdata); + s = bus_slot_allocate(bus, !slot, BUS_MATCH_CALLBACK, sizeof(BusMatchCallback), userdata); if (!s) return -ENOMEM; @@ -3592,7 +3592,7 @@ int bus_add_match_full( s->match_callback.install_callback = install_callback; if (bus->bus_client) { - enum bus_match_scope scope; + BusMatchScope scope; scope = bus_match_get_scope(components, n_components); diff --git a/src/libsystemd/sd-bus/test-bus-introspect.c b/src/libsystemd/sd-bus/test-bus-introspect.c index fe59819674a..19f409a2122 100644 --- a/src/libsystemd/sd-bus/test-bus-introspect.c +++ b/src/libsystemd/sd-bus/test-bus-introspect.c @@ -6,7 +6,7 @@ #include "tests.h" static void test_manual_introspection_one(const sd_bus_vtable vtable[]) { - struct introspect intro = {}; + BusIntrospect intro = {}; _cleanup_free_ char *s = NULL; log_info("/* %s */", __func__); diff --git a/src/libsystemd/sd-bus/test-bus-match.c b/src/libsystemd/sd-bus/test-bus-match.c index 7b212c8eaa5..58ba71e21f6 100644 --- a/src/libsystemd/sd-bus/test-bus-match.c +++ b/src/libsystemd/sd-bus/test-bus-match.c @@ -37,8 +37,8 @@ static bool mask_contains(unsigned a[], unsigned n) { return true; } -static int match_add(sd_bus_slot *slots, struct bus_match_node *root, const char *match, int value) { - struct bus_match_component *components; +static int match_add(sd_bus_slot *slots, BusMatchNode *root, const char *match, int value) { + BusMatchComponent *components; size_t n_components; sd_bus_slot *s; int r; @@ -57,8 +57,8 @@ static int match_add(sd_bus_slot *slots, struct bus_match_node *root, const char return bus_match_add(root, components, n_components, &s->match_callback); } -static void test_match_scope(const char *match, enum bus_match_scope scope) { - struct bus_match_component *components = NULL; +static void test_match_scope(const char *match, BusMatchScope scope) { + BusMatchComponent *components = NULL; size_t n_components = 0; CLEANUP_ARRAY(components, n_components, bus_match_parse_free); @@ -68,7 +68,7 @@ static void test_match_scope(const char *match, enum bus_match_scope scope) { } int main(int argc, char *argv[]) { - struct bus_match_node root = { + BusMatchNode root = { .type = BUS_MATCH_ROOT, }; @@ -123,7 +123,7 @@ int main(int argc, char *argv[]) { assert_se(bus_match_run(NULL, &root, m) == 0); assert_se(mask_contains((unsigned[]) { 9, 5, 10, 12, 14, 7, 15, 16, 17 }, 9)); - for (enum bus_match_node_type i = 0; i < _BUS_MATCH_NODE_TYPE_MAX; i++) { + for (BusMatchNodeType i = 0; i < _BUS_MATCH_NODE_TYPE_MAX; i++) { char buf[32]; const char *x; diff --git a/src/shared/bus-object.c b/src/shared/bus-object.c index bc5995a67f9..d05619a3d4d 100644 --- a/src/shared/bus-object.c +++ b/src/shared/bus-object.c @@ -84,7 +84,7 @@ static const BusObjectImplementation* find_implementation( } static int bus_introspect_implementation( - struct introspect *intro, + BusIntrospect *intro, const BusObjectImplementation *impl) { int r; @@ -128,7 +128,7 @@ int bus_introspect_implementations( return 0; } - struct introspect intro = {}; + BusIntrospect intro = {}; bool is_interface = sd_bus_interface_name_is_valid(pattern); impl = find_implementation(pattern, bus_objects);