summaryrefslogtreecommitdiffstats
path: root/src/shared/nsresource.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-18 18:27:44 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-09-18 18:34:57 +0200
commitb9623381042799bbe2a6f63f20ef3c065c371e3f (patch)
tree2fec6f0c89454f7dea53e2df58c83f4210d485f6 /src/shared/nsresource.c
parentcreds-util: make sd_json_dispatch_field table static (diff)
downloadsystemd-b9623381042799bbe2a6f63f20ef3c065c371e3f.tar.xz
systemd-b9623381042799bbe2a6f63f20ef3c065c371e3f.zip
nsresource: make sd_json_dispatch_field table static
This also adds missing error check of sd_json_dispatch(). Follow-up for 54452c7b2aa03536331fc1ec04439c89d0320b57.
Diffstat (limited to '')
-rw-r--r--src/shared/nsresource.c34
1 files 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;
}