From ed4a6c476eaf01e3b949f286564e6d03eda397a7 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 00:44:16 +0900 Subject: [PATCH 1/9] machine: make sd_json_dispatch_field table static --- src/machine/machined-varlink.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c index 8e7ade9aec..a09c51b470 100644 --- a/src/machine/machined-varlink.c +++ b/src/machine/machined-varlink.c @@ -416,19 +416,18 @@ static int list_machine_one(sd_varlink *link, Machine *m, bool more) { } static int vl_method_list(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { - Manager *m = ASSERT_PTR(userdata); - const char *mn = NULL; - - const sd_json_dispatch_field dispatch_table[] = { - { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&mn), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, 0, 0 }, {} }; + Manager *m = ASSERT_PTR(userdata); + const char *mn = NULL; int r; assert(parameters); - r = sd_varlink_dispatch(link, parameters, dispatch_table, 0); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &mn); if (r != 0) return r; From 07dbbda0fc7f340589b74334cf69526e0352c01b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:05:24 +0900 Subject: [PATCH 2/9] ssh-generator: make sd_json_dispatch_field table static --- src/ssh-generator/ssh-proxy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ssh-generator/ssh-proxy.c b/src/ssh-generator/ssh-proxy.c index 67bdb056ef..0085e2a087 100644 --- a/src/ssh-generator/ssh-proxy.c +++ b/src/ssh-generator/ssh-proxy.c @@ -161,12 +161,12 @@ static int process_machine(const char *machine, const char *port) { uint32_t cid = VMADDR_CID_ANY; - const sd_json_dispatch_field dispatch_table[] = { - { "vSockCid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint32, PTR_TO_SIZE(&cid), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "vSockCid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint32, 0, 0 }, {} }; - r = sd_json_dispatch(result, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, NULL); + r = sd_json_dispatch(result, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &cid); if (r < 0) return log_error_errno(r, "Failed to parse Varlink reply: %m"); From 751a247794b53a9d6f953750fe20986dca0e9be1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:06:59 +0900 Subject: [PATCH 3/9] varlinkctl: make sd_json_dispatch_field table static --- src/varlinkctl/varlinkctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index 481a41208e..662a6add4b 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -380,12 +380,12 @@ static int verb_introspect(int argc, char *argv[], void *userdata) { if (r < 0) return r; - const struct sd_json_dispatch_field dispatch_table[] = { - { "interfaces", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_strv, PTR_TO_SIZE(&auto_interfaces), SD_JSON_MANDATORY }, + static const sd_json_dispatch_field dispatch_table[] = { + { "interfaces", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_strv, 0, SD_JSON_MANDATORY }, {} }; - r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, NULL); + r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &auto_interfaces); if (r < 0) return r; From 53c638db16316c1747ea5d35c7808adb48686135 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:16:53 +0900 Subject: [PATCH 4/9] updatectl: make sd_json_dispatch_field table static This also fixes memory leak of Version object on failure. Follow-up for ec15bb71c2ccd57702325a6e6626053a343f3511. --- src/sysupdate/updatectl.c | 70 ++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/src/sysupdate/updatectl.c b/src/sysupdate/updatectl.c index fad68ebd88..af27d0dc80 100644 --- a/src/sysupdate/updatectl.c +++ b/src/sysupdate/updatectl.c @@ -321,12 +321,27 @@ static int list_targets(sd_bus *bus) { return table_print_with_pager(table, SD_JSON_FORMAT_OFF, arg_pager_flags, arg_legend); } +typedef struct DescribeParams { + Version v; + sd_json_variant *contents_json; + bool newest; + bool available; + bool installed; + bool obsolete; + bool protected; + bool incomplete; +} DescribeParams; + +static void describe_params_done(DescribeParams *p) { + assert(p); + + version_done(&p->v); + sd_json_variant_unref(p->contents_json); +} + static int parse_describe(sd_bus_message *reply, Version *ret) { - Version v = {}; char *version_json = NULL; - _cleanup_(sd_json_variant_unrefp) sd_json_variant *json = NULL, *contents_json = NULL; - bool newest = false, available = false, installed = false, obsolete = false, protected = false, - incomplete = false; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *json = NULL; int r; assert(reply); @@ -342,36 +357,37 @@ static int parse_describe(sd_bus_message *reply, Version *ret) { assert(sd_json_variant_is_object(json)); - r = sd_json_dispatch(json, - (const sd_json_dispatch_field[]) { - { "version", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, PTR_TO_SIZE(&v.version), 0 }, - { "newest", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, PTR_TO_SIZE(&newest), 0 }, - { "available", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, PTR_TO_SIZE(&available), 0 }, - { "installed", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, PTR_TO_SIZE(&installed), 0 }, - { "obsolete", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, PTR_TO_SIZE(&obsolete), 0 }, - { "protected", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, PTR_TO_SIZE(&protected), 0 }, - { "incomplete", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, PTR_TO_SIZE(&incomplete), 0 }, - { "changelog_urls", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_strv, PTR_TO_SIZE(&v.changelog), 0 }, - { "contents", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&contents_json), 0 }, - {}, - }, - SD_JSON_ALLOW_EXTENSIONS, - /* userdata= */ NULL); + static const sd_json_dispatch_field dispatch_table[] = { + { "version", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(DescribeParams, v.version), 0 }, + { "newest", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(DescribeParams, newest), 0 }, + { "available", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(DescribeParams, available), 0 }, + { "installed", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(DescribeParams, installed), 0 }, + { "obsolete", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(DescribeParams, obsolete), 0 }, + { "protected", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(DescribeParams, protected), 0 }, + { "incomplete", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(DescribeParams, incomplete), 0 }, + { "changelog_urls", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_strv, offsetof(DescribeParams, v.changelog), 0 }, + { "contents", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(DescribeParams, contents_json), 0 }, + {}, + }; + + _cleanup_(describe_params_done) DescribeParams p = {}; + + r = sd_json_dispatch(json, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &p); if (r < 0) return log_error_errno(r, "Failed to parse JSON: %m"); - SET_FLAG(v.flags, UPDATE_NEWEST, newest); - SET_FLAG(v.flags, UPDATE_AVAILABLE, available); - SET_FLAG(v.flags, UPDATE_INSTALLED, installed); - SET_FLAG(v.flags, UPDATE_OBSOLETE, obsolete); - SET_FLAG(v.flags, UPDATE_PROTECTED, protected); - SET_FLAG(v.flags, UPDATE_INCOMPLETE, incomplete); + SET_FLAG(p.v.flags, UPDATE_NEWEST, p.newest); + SET_FLAG(p.v.flags, UPDATE_AVAILABLE, p.available); + SET_FLAG(p.v.flags, UPDATE_INSTALLED, p.installed); + SET_FLAG(p.v.flags, UPDATE_OBSOLETE, p.obsolete); + SET_FLAG(p.v.flags, UPDATE_PROTECTED, p.protected); + SET_FLAG(p.v.flags, UPDATE_INCOMPLETE, p.incomplete); - r = sd_json_variant_format(contents_json, 0, &v.contents_json); + r = sd_json_variant_format(p.contents_json, 0, &p.v.contents_json); if (r < 0) return log_error_errno(r, "Failed to format JSON for contents: %m"); - *ret = TAKE_STRUCT(v); + *ret = TAKE_STRUCT(p.v); return 0; } From 36df48d863f188b23735aab81f52a02ca054abb8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 00:56:53 +0900 Subject: [PATCH 5/9] resolvectl: make sd_json_dispatch_field table static --- src/resolve/resolvectl.c | 81 +++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 1fa62a4df7..0204fdf16f 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -2876,55 +2876,76 @@ static int print_answer(sd_json_variant *answer) { return 0; } +typedef struct MonitorQueryParams { + sd_json_variant *question; + sd_json_variant *answer; + sd_json_variant *collected_questions; + int rcode; + int error; + int ede_code; + const char *state; + const char *result; + const char *ede_msg; +} MonitorQueryParams; + +static void monitor_query_params_done(MonitorQueryParams *p) { + assert(p); + + sd_json_variant_unref(p->question); + sd_json_variant_unref(p->answer); + sd_json_variant_unref(p->collected_questions); +} + static void monitor_query_dump(sd_json_variant *v) { - _cleanup_(sd_json_variant_unrefp) sd_json_variant *question = NULL, *answer = NULL, *collected_questions = NULL; - int rcode = -1, error = 0, ede_code = -1; - const char *state = NULL, *result = NULL, *ede_msg = NULL; - - assert(v); - - sd_json_dispatch_field dispatch_table[] = { - { "question", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&question), SD_JSON_MANDATORY }, - { "answer", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&answer), 0 }, - { "collectedQuestions", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&collected_questions), 0 }, - { "state", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&state), SD_JSON_MANDATORY }, - { "result", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&result), 0 }, - { "rcode", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, PTR_TO_SIZE(&rcode), 0 }, - { "errno", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, PTR_TO_SIZE(&error), 0 }, - { "extendedDNSErrorCode", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, PTR_TO_SIZE(&ede_code), 0 }, - { "extendedDNSErrorMessage", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&ede_msg), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "question", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(MonitorQueryParams, question), SD_JSON_MANDATORY }, + { "answer", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(MonitorQueryParams, answer), 0 }, + { "collectedQuestions", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(MonitorQueryParams, collected_questions), 0 }, + { "state", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MonitorQueryParams, state), SD_JSON_MANDATORY }, + { "result", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MonitorQueryParams, result), 0 }, + { "rcode", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(MonitorQueryParams, rcode), 0 }, + { "errno", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(MonitorQueryParams, error), 0 }, + { "extendedDNSErrorCode", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(MonitorQueryParams, ede_code), 0 }, + { "extendedDNSErrorMessage", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MonitorQueryParams, ede_msg), 0 }, {} }; - if (sd_json_dispatch(v, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, NULL) < 0) + _cleanup_(monitor_query_params_done) MonitorQueryParams p = { + .rcode = -1, + .ede_code = -1, + }; + + assert(v); + + if (sd_json_dispatch(v, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &p) < 0) return; /* First show the current question */ - print_question('Q', ansi_highlight_cyan(), question); + print_question('Q', ansi_highlight_cyan(), p.question); /* And then show the questions that led to this one in case this was a CNAME chain */ - print_question('C', ansi_highlight_grey(), collected_questions); + print_question('C', ansi_highlight_grey(), p.collected_questions); printf("%s%s S%s: %s", - streq_ptr(state, "success") ? ansi_highlight_green() : ansi_highlight_red(), + streq_ptr(p.state, "success") ? ansi_highlight_green() : ansi_highlight_red(), special_glyph(SPECIAL_GLYPH_ARROW_LEFT), ansi_normal(), - strna(streq_ptr(state, "errno") ? errno_to_name(error) : - streq_ptr(state, "rcode-failure") ? dns_rcode_to_string(rcode) : - state)); + strna(streq_ptr(p.state, "errno") ? errno_to_name(p.error) : + streq_ptr(p.state, "rcode-failure") ? dns_rcode_to_string(p.rcode) : + p.state)); - if (!isempty(result)) - printf(": %s", result); + if (!isempty(p.result)) + printf(": %s", p.result); - if (ede_code >= 0) + if (p.ede_code >= 0) printf(" (%s%s%s)", - FORMAT_DNS_EDE_RCODE(ede_code), - !isempty(ede_msg) ? ": " : "", - strempty(ede_msg)); + FORMAT_DNS_EDE_RCODE(p.ede_code), + !isempty(p.ede_msg) ? ": " : "", + strempty(p.ede_msg)); puts(""); - print_answer(answer); + print_answer(p.answer); } static int monitor_reply( From f7923ef318c7a044bce8b19cd14b498ed1013068 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:03:09 +0900 Subject: [PATCH 6/9] resolve: make sd_json_dispatch_field table static --- src/resolve/resolved-dns-rr.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index 6a4bd6aecd..cc7a5b64b6 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -2145,26 +2145,31 @@ int dns_resource_key_to_json(DnsResourceKey *key, sd_json_variant **ret) { } int dns_resource_key_from_json(sd_json_variant *v, DnsResourceKey **ret) { - _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL; - uint16_t type = 0, class = 0; - const char *name = NULL; - int r; + struct params { + uint16_t type; + uint16_t class; + const char *name; + }; - sd_json_dispatch_field dispatch_table[] = { - { "class", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, PTR_TO_SIZE(&class), SD_JSON_MANDATORY }, - { "type", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, PTR_TO_SIZE(&type), SD_JSON_MANDATORY }, - { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&name), SD_JSON_MANDATORY }, + static const sd_json_dispatch_field dispatch_table[] = { + { "class", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(struct params, class), SD_JSON_MANDATORY }, + { "type", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(struct params, type), SD_JSON_MANDATORY }, + { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct params, name), SD_JSON_MANDATORY }, {} }; + _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL; + struct params p; + int r; + assert(v); assert(ret); - r = sd_json_dispatch(v, dispatch_table, 0, NULL); + r = sd_json_dispatch(v, dispatch_table, 0, &p); if (r < 0) return r; - key = dns_resource_key_new(class, type, name); + key = dns_resource_key_new(p.class, p.type, p.name); if (!key) return -ENOMEM; From fae0b004343641dc0e304012fe631479a15b6677 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:21:42 +0900 Subject: [PATCH 7/9] creds-util: make sd_json_dispatch_field table static --- src/shared/creds-util.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index c7a5026737..180ab560fa 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -1582,14 +1582,12 @@ int ipc_encrypt_credential(const char *name, usec_t timestamp, usec_t not_after, return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to encrypt: %s", error_id); } - r = sd_json_dispatch( - reply, - (const sd_json_dispatch_field[]) { - { "blob", SD_JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, PTR_TO_SIZE(ret), SD_JSON_MANDATORY }, - {}, - }, - SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, - /* userdata= */ NULL); + static const sd_json_dispatch_field dispatch_table[] = { + { "blob", SD_JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, 0, SD_JSON_MANDATORY }, + {}, + }; + + r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, ret); if (r < 0) return r; @@ -1649,14 +1647,12 @@ int ipc_decrypt_credential(const char *validate_name, usec_t validate_timestamp, return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to decrypt: %s", error_id); } - r = sd_json_dispatch( - reply, - (const sd_json_dispatch_field[]) { - { "data", SD_JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, PTR_TO_SIZE(ret), SD_JSON_MANDATORY }, - {}, - }, - SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, - /* userdata= */ NULL); + static const sd_json_dispatch_field dispatch_table[] = { + { "data", SD_JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, 0, SD_JSON_MANDATORY }, + {}, + }; + + r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, ret); if (r < 0) return r; From b9623381042799bbe2a6f63f20ef3c065c371e3f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:27:44 +0900 Subject: [PATCH 8/9] nsresource: make sd_json_dispatch_field table static This also adds missing error check of sd_json_dispatch(). Follow-up for 54452c7b2aa03536331fc1ec04439c89d0320b57. --- src/shared/nsresource.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/shared/nsresource.c b/src/shared/nsresource.c index 4a2a9d2e41..24ea2e2be5 100644 --- a/src/shared/nsresource.c +++ b/src/shared/nsresource.c @@ -250,6 +250,18 @@ int nsresource_add_cgroup(int userns_fd, int cgroup_fd) { return 1; } +typedef struct InterfaceParams { + char *host_interface_name; + char *namespace_interface_name; +} InterfaceParams; + +static void interface_params_done(InterfaceParams *p) { + assert(p); + + free(p->host_interface_name); + free(p->namespace_interface_name); +} + int nsresource_add_netif( int userns_fd, int netns_fd, @@ -313,20 +325,20 @@ int nsresource_add_netif( if (error_id) return log_debug_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to add network to user namespace: %s", error_id); - _cleanup_free_ char *host_interface_name = NULL, *namespace_interface_name = NULL; - r = sd_json_dispatch( - reply, - (const sd_json_dispatch_field[]) { - { "hostInterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, PTR_TO_SIZE(&host_interface_name) }, - { "namespaceInterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, PTR_TO_SIZE(&namespace_interface_name) }, - }, - SD_JSON_ALLOW_EXTENSIONS, - /* userdata= */ NULL); + static const sd_json_dispatch_field dispatch_table[] = { + { "hostInterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(InterfaceParams, host_interface_name), 0 }, + { "namespaceInterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(InterfaceParams, namespace_interface_name), 0 }, + }; + + _cleanup_(interface_params_done) InterfaceParams p = {}; + r = sd_json_dispatch(reply, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &p); + if (r < 0) + return r; if (ret_host_ifname) - *ret_host_ifname = TAKE_PTR(host_interface_name); + *ret_host_ifname = TAKE_PTR(p.host_interface_name); if (ret_namespace_ifname) - *ret_namespace_ifname = TAKE_PTR(namespace_interface_name); + *ret_namespace_ifname = TAKE_PTR(p.namespace_interface_name); return 1; } From 26d35019deb69069011b60b28527d93cec4c2218 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Sep 2024 01:34:19 +0900 Subject: [PATCH 9/9] tree-wide: drop unnecessary 'struct' --- src/libsystemd/sd-varlink/sd-varlink.c | 2 +- src/nspawn/nspawn-oci.c | 2 +- src/varlinkctl/varlinkctl.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libsystemd/sd-varlink/sd-varlink.c b/src/libsystemd/sd-varlink/sd-varlink.c index 4665913b1c..a0aa12a386 100644 --- a/src/libsystemd/sd-varlink/sd-varlink.c +++ b/src/libsystemd/sd-varlink/sd-varlink.c @@ -1229,7 +1229,7 @@ static int generic_method_get_interface_description( sd_varlink_method_flags_t flags, void *userdata) { - static const struct sd_json_dispatch_field dispatch_table[] = { + static const sd_json_dispatch_field dispatch_table[] = { { "interface", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, 0, SD_JSON_MANDATORY }, {} }; diff --git a/src/nspawn/nspawn-oci.c b/src/nspawn/nspawn-oci.c index db118699dc..11ea744562 100644 --- a/src/nspawn/nspawn-oci.c +++ b/src/nspawn/nspawn-oci.c @@ -1742,7 +1742,7 @@ static int oci_seccomp_args(const char *name, sd_json_variant *v, sd_json_dispat int r; JSON_VARIANT_ARRAY_FOREACH(e, v) { - static const struct sd_json_dispatch_field table[] = { + static const sd_json_dispatch_field table[] = { { "index", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint32, offsetof(struct scmp_arg_cmp, arg), SD_JSON_MANDATORY }, { "value", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint64, offsetof(struct scmp_arg_cmp, datum_a), SD_JSON_MANDATORY }, { "valueTwo", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint64, offsetof(struct scmp_arg_cmp, datum_b), 0 }, diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index 662a6add4b..0474ab245e 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -288,7 +288,7 @@ static int verb_info(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) { - static const struct sd_json_dispatch_field dispatch_table[] = { + static const sd_json_dispatch_field dispatch_table[] = { { "vendor", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(GetInfoData, vendor), SD_JSON_MANDATORY }, { "product", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(GetInfoData, product), SD_JSON_MANDATORY }, { "version", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(GetInfoData, version), SD_JSON_MANDATORY }, @@ -412,7 +412,7 @@ static int verb_introspect(int argc, char *argv[], void *userdata) { return r; if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) || list_methods) { - static const struct sd_json_dispatch_field dispatch_table[] = { + static const sd_json_dispatch_field dispatch_table[] = { { "description", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, 0, SD_JSON_MANDATORY }, {} };