diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-07-12 11:22:58 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-07-16 11:57:32 +0200 |
commit | 25ff515b398da61171a570baee641290374cec1a (patch) | |
tree | a41558cc31c2ed18c4b3262ed1812cdc5e0cc360 /src | |
parent | Merge pull request #33695 from DaanDeMeyer/epel (diff) | |
download | systemd-25ff515b398da61171a570baee641290374cec1a.tar.xz systemd-25ff515b398da61171a570baee641290374cec1a.zip |
sd-varlink: make our internal Varlink API public as sd-varlink.[ch]
It's time. sd-json was already done earlier in this cycle, let's now
make sd-varlink public too.
This is mostly just a search/replace job of epical proportions.
I left some functions internal (mostly IDL handling), and I turned some
static inline calls into regular calls.
Diffstat (limited to 'src')
114 files changed, 3730 insertions, 3445 deletions
diff --git a/src/boot/bootctl-reboot-to-firmware.c b/src/boot/bootctl-reboot-to-firmware.c index fbde7cbb66..0bedd230bb 100644 --- a/src/boot/bootctl-reboot-to-firmware.c +++ b/src/boot/bootctl-reboot-to-firmware.c @@ -38,7 +38,7 @@ int verb_reboot_to_firmware(int argc, char *argv[], void *userdata) { } } -int vl_method_set_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_set_reboot_to_firmware(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "state", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, 0, 0 }, {} @@ -46,30 +46,30 @@ int vl_method_set_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, bool b; int r; - r = varlink_dispatch(link, parameters, dispatch_table, &b); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &b); if (r != 0) return r; r = efi_set_reboot_to_firmware(b); if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) - return varlink_error(link, "io.systemd.BootControl.RebootToFirmwareNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.BootControl.RebootToFirmwareNotSupported", NULL); if (r < 0) return r; - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -int vl_method_get_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_get_reboot_to_firmware(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { int r; if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); r = efi_get_reboot_to_firmware(); if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) - return varlink_error(link, "io.systemd.BootControl.RebootToFirmwareNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.BootControl.RebootToFirmwareNotSupported", NULL); if (r < 0) return r; - return varlink_replybo(link, SD_JSON_BUILD_PAIR_BOOLEAN("state", r)); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR_BOOLEAN("state", r)); } diff --git a/src/boot/bootctl-reboot-to-firmware.h b/src/boot/bootctl-reboot-to-firmware.h index 4fc3241343..e9cf9bf3a6 100644 --- a/src/boot/bootctl-reboot-to-firmware.h +++ b/src/boot/bootctl-reboot-to-firmware.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "varlink.h" +#include "sd-varlink.h" int verb_reboot_to_firmware(int argc, char *argv[], void *userdata); -int vl_method_set_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); -int vl_method_get_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); +int vl_method_set_reboot_to_firmware(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +int vl_method_get_reboot_to_firmware(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index d2c7d50d12..113d27410f 100644 --- a/src/boot/bootctl-status.c +++ b/src/boot/bootctl-status.c @@ -835,7 +835,7 @@ int verb_unlink(int argc, char *argv[], void *userdata) { return verb_list(argc, argv, userdata); } -int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_list_boot_entries(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL; dev_t esp_devid = 0, xbootldr_devid = 0; int r; @@ -843,10 +843,10 @@ int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, Varl assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - if (!FLAGS_SET(flags, VARLINK_METHOD_MORE)) - return varlink_error(link, VARLINK_ERROR_EXPECTED_MORE, NULL); + if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE)) + return sd_varlink_error(link, SD_VARLINK_ERROR_EXPECTED_MORE, NULL); r = acquire_esp(/* unprivileged_mode= */ false, /* graceful= */ false, @@ -876,7 +876,7 @@ int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, Varl _cleanup_(sd_json_variant_unrefp) sd_json_variant *previous = NULL; for (size_t i = 0; i < config.n_entries; i++) { if (previous) { - r = varlink_notifybo(link, SD_JSON_BUILD_PAIR_VARIANT("entry", previous)); + r = sd_varlink_notifybo(link, SD_JSON_BUILD_PAIR_VARIANT("entry", previous)); if (r < 0) return r; @@ -889,7 +889,7 @@ int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, Varl } if (!previous) - return varlink_error(link, "io.systemd.BootControl.NoSuchBootEntry", NULL); + return sd_varlink_error(link, "io.systemd.BootControl.NoSuchBootEntry", NULL); - return varlink_replybo(link, SD_JSON_BUILD_PAIR_VARIANT("entry", previous)); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR_VARIANT("entry", previous)); } diff --git a/src/boot/bootctl-status.h b/src/boot/bootctl-status.h index e276ba35eb..44542f4dbd 100644 --- a/src/boot/bootctl-status.h +++ b/src/boot/bootctl-status.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "varlink.h" +#include "sd-varlink.h" int verb_status(int argc, char *argv[], void *userdata); int verb_list(int argc, char *argv[], void *userdata); int verb_unlink(int argc, char *argv[], void *userdata); -int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); +int vl_method_list_boot_entries(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index e609028731..b2f84f00f7 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -2,6 +2,8 @@ #include <getopt.h> +#include "sd-varlink.h" + #include "blockdev-util.h" #include "bootctl.h" #include "bootctl-install.h" @@ -22,7 +24,6 @@ #include "parse-argument.h" #include "pretty-print.h" #include "utf8.h" -#include "varlink.h" #include "varlink-io.systemd.BootControl.h" #include "verbs.h" #include "virt.h" @@ -432,7 +433,7 @@ static int parse_argv(int argc, char *argv[]) { if (arg_dry_run && argv[optind] && !STR_IN_SET(argv[optind], "unlink", "cleanup")) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--dry is only supported with --unlink or --cleanup"); - r = varlink_invocation(VARLINK_ALLOW_ACCEPT); + r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT); if (r < 0) return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m"); if (r > 0) { @@ -485,19 +486,19 @@ static int run(int argc, char *argv[]) { return r; if (arg_varlink) { - _cleanup_(varlink_server_unrefp) VarlinkServer *varlink_server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; /* Invocation as Varlink service */ - r = varlink_server_new(&varlink_server, VARLINK_SERVER_ROOT_ONLY); + r = sd_varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ROOT_ONLY); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - r = varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_BootControl); + r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_BootControl); if (r < 0) return log_error_errno(r, "Failed to add Varlink interface: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( varlink_server, "io.systemd.BootControl.ListBootEntries", vl_method_list_boot_entries, "io.systemd.BootControl.SetRebootToFirmware", vl_method_set_reboot_to_firmware, @@ -505,7 +506,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to bind Varlink methods: %m"); - r = varlink_server_loop_auto(varlink_server); + r = sd_varlink_server_loop_auto(varlink_server); if (r < 0) return log_error_errno(r, "Failed to run Varlink event loop: %m"); diff --git a/src/core/core-varlink.c b/src/core/core-varlink.c index 8457392e7a..a336430bf4 100644 --- a/src/core/core-varlink.c +++ b/src/core/core-varlink.c @@ -1,11 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-varlink.h" + #include "core-varlink.h" #include "json-util.h" #include "mkdir-label.h" #include "strv.h" #include "user-util.h" -#include "varlink.h" #include "varlink-io.systemd.UserDatabase.h" #include "varlink-io.systemd.ManagedOOM.h" @@ -147,11 +148,11 @@ int manager_varlink_send_managed_oom_update(Unit *u) { if (MANAGER_IS_SYSTEM(u->manager)) /* in system mode, oomd is our client, thus send out notifications as replies to the * initiating method call from them. */ - r = varlink_notify(u->manager->managed_oom_varlink, v); + r = sd_varlink_notify(u->manager->managed_oom_varlink, v); else /* in user mode, we are oomd's client, thus send out notifications as method calls that do * not expect a reply. */ - r = varlink_send(u->manager->managed_oom_varlink, "io.systemd.oom.ReportManagedOOMCGroups", v); + r = sd_varlink_send(u->manager->managed_oom_varlink, "io.systemd.oom.ReportManagedOOMCGroups", v); return r; } @@ -211,9 +212,9 @@ static int build_managed_oom_cgroups_json(Manager *m, sd_json_variant **ret) { } static int vl_method_subscribe_managed_oom_cgroups( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, - VarlinkMethodFlags flags, + sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; @@ -224,37 +225,37 @@ static int vl_method_subscribe_managed_oom_cgroups( assert(link); - r = varlink_get_peer_pid(link, &pid); + r = sd_varlink_get_peer_pid(link, &pid); if (r < 0) return r; u = manager_get_unit_by_pid(m, pid); if (!u) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); /* This is meant to be a deterrent and not actual security. The alternative is to check for the systemd-oom * user that this unit runs as, but NSS lookups are blocking and not allowed from PID 1. */ if (!streq(u->id, "systemd-oomd.service")) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); /* We only take one subscriber for this method so return an error if there's already an existing one. * This shouldn't happen since systemd-oomd is the only client of this method. */ - if (FLAGS_SET(flags, VARLINK_METHOD_MORE) && m->managed_oom_varlink) - return varlink_error(link, "io.systemd.ManagedOOM.SubscriptionTaken", NULL); + if (FLAGS_SET(flags, SD_VARLINK_METHOD_MORE) && m->managed_oom_varlink) + return sd_varlink_error(link, "io.systemd.ManagedOOM.SubscriptionTaken", NULL); r = build_managed_oom_cgroups_json(m, &v); if (r < 0) return r; - if (!FLAGS_SET(flags, VARLINK_METHOD_MORE)) - return varlink_reply(link, v); + if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE)) + return sd_varlink_reply(link, v); assert(!m->managed_oom_varlink); - m->managed_oom_varlink = varlink_ref(link); - return varlink_notify(m->managed_oom_varlink, v); + m->managed_oom_varlink = sd_varlink_ref(link); + return sd_varlink_notify(m->managed_oom_varlink, v); } static int manager_varlink_send_managed_oom_initial(Manager *m) { @@ -272,10 +273,10 @@ static int manager_varlink_send_managed_oom_initial(Manager *m) { if (r < 0) return r; - return varlink_send(m->managed_oom_varlink, "io.systemd.oom.ReportManagedOOMCGroups", v); + return sd_varlink_send(m->managed_oom_varlink, "io.systemd.oom.ReportManagedOOMCGroups", v); } -static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, @@ -296,12 +297,12 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.DynamicUser")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (uid_is_valid(p.uid)) r = dynamic_user_lookup_uid(m, p.uid, &found_name); @@ -321,7 +322,7 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, continue; if (v) { - r = varlink_notify(link, v); + r = sd_varlink_notify(link, v); if (r < 0) return r; @@ -334,12 +335,12 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, } if (!v) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } if (r == -ESRCH) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -347,13 +348,13 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, un = found_name ?: p.user_name; if (!user_match_lookup_parameters(&p, un, uid)) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_user_json(un, uid, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } static int build_group_json(const char *group_name, gid_t gid, sd_json_variant **ret) { @@ -381,7 +382,7 @@ static bool group_match_lookup_parameters(LookupParameters *p, const char *name, return true; } -static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, @@ -402,12 +403,12 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.DynamicUser")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (gid_is_valid(p.gid)) r = dynamic_user_lookup_uid(m, (uid_t) p.gid, &found_name); @@ -429,7 +430,7 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters continue; if (v) { - r = varlink_notify(link, v); + r = sd_varlink_notify(link, v); if (r < 0) return r; @@ -442,12 +443,12 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters } if (!v) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } if (r == -ESRCH) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -455,16 +456,16 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters gn = found_name ?: p.group_name; if (!group_match_lookup_parameters(&p, gn, gid)) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_group_json(gn, gid, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } -static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_memberships(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_STRICT }, @@ -478,48 +479,48 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.DynamicUser")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); /* We don't support auxiliary groups with dynamic users. */ - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } -static void vl_disconnect(VarlinkServer *s, Varlink *link, void *userdata) { +static void vl_disconnect(sd_varlink_server *s, sd_varlink *link, void *userdata) { Manager *m = ASSERT_PTR(userdata); assert(s); assert(link); if (link == m->managed_oom_varlink) - m->managed_oom_varlink = varlink_unref(link); + m->managed_oom_varlink = sd_varlink_unref(link); } -static int manager_setup_varlink_server(Manager *m, VarlinkServer **ret) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; +static int manager_setup_varlink_server(Manager *m, sd_varlink_server **ret) { + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); assert(ret); - r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_debug_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(s, m); + sd_varlink_server_set_userdata(s, m); - r = varlink_server_add_interface_many( + r = sd_varlink_server_add_interface_many( s, &vl_interface_io_systemd_UserDatabase, &vl_interface_io_systemd_ManagedOOM); if (r < 0) return log_debug_errno(r, "Failed to add interfaces to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( s, "io.systemd.UserDatabase.GetUserRecord", vl_method_get_user_record, "io.systemd.UserDatabase.GetGroupRecord", vl_method_get_group_record, @@ -528,7 +529,7 @@ static int manager_setup_varlink_server(Manager *m, VarlinkServer **ret) { if (r < 0) return log_debug_errno(r, "Failed to register varlink methods: %m"); - r = varlink_server_bind_disconnect(s, vl_disconnect); + r = sd_varlink_server_bind_disconnect(s, vl_disconnect); if (r < 0) return log_debug_errno(r, "Failed to register varlink disconnect handler: %m"); @@ -537,7 +538,7 @@ static int manager_setup_varlink_server(Manager *m, VarlinkServer **ret) { } static int manager_varlink_init_system(Manager *m) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); @@ -566,13 +567,13 @@ static int manager_varlink_init_system(Manager *m) { "Failed to check if varlink socket '%s' exists: %m", address); } - r = varlink_server_listen_address(s, address, 0666); + r = sd_varlink_server_listen_address(s, address, 0666); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket '%s': %m", address); } } - r = varlink_server_attach_event(s, m->event, EVENT_PRIORITY_IPC); + r = sd_varlink_server_attach_event(s, m->event, EVENT_PRIORITY_IPC); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); @@ -580,18 +581,18 @@ static int manager_varlink_init_system(Manager *m) { return 1; } -static int vl_reply(Varlink *link, sd_json_variant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) { +static int vl_reply(sd_varlink *link, sd_json_variant *parameters, const char *error_id, sd_varlink_reply_flags_t flags, void *userdata) { Manager *m = ASSERT_PTR(userdata); int r; if (error_id) log_debug("varlink systemd-oomd client error: %s", error_id); - if (FLAGS_SET(flags, VARLINK_REPLY_ERROR) && FLAGS_SET(flags, VARLINK_REPLY_LOCAL)) { - /* Varlink connection was closed, likely because of systemd-oomd restart. Let's try to + if (FLAGS_SET(flags, SD_VARLINK_REPLY_ERROR) && FLAGS_SET(flags, SD_VARLINK_REPLY_LOCAL)) { + /* sd_varlink connection was closed, likely because of systemd-oomd restart. Let's try to * reconnect and send the initial ManagedOOM update again. */ - m->managed_oom_varlink = varlink_unref(link); + m->managed_oom_varlink = sd_varlink_unref(link); log_debug("Reconnecting to %s", VARLINK_ADDR_PATH_MANAGED_OOM_USER); @@ -604,7 +605,7 @@ static int vl_reply(Varlink *link, sd_json_variant *parameters, const char *erro } static int manager_varlink_init_user(Manager *m) { - _cleanup_(varlink_close_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_close_unrefp) sd_varlink *link = NULL; int r; assert(m); @@ -615,7 +616,7 @@ static int manager_varlink_init_user(Manager *m) { if (MANAGER_IS_TEST_RUN(m)) return 0; - r = varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_USER); + r = sd_varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_USER); if (r < 0) { if (r == -ENOENT || ERRNO_IS_DISCONNECT(r)) { log_debug("systemd-oomd varlink unix socket not found, skipping user manager varlink setup"); @@ -624,13 +625,13 @@ static int manager_varlink_init_user(Manager *m) { return log_error_errno(r, "Failed to connect to %s: %m", VARLINK_ADDR_PATH_MANAGED_OOM_USER); } - varlink_set_userdata(link, m); + sd_varlink_set_userdata(link, m); - r = varlink_bind_reply(link, vl_reply); + r = sd_varlink_bind_reply(link, vl_reply); if (r < 0) return r; - r = varlink_attach_event(link, m->event, EVENT_PRIORITY_IPC); + r = sd_varlink_attach_event(link, m->event, EVENT_PRIORITY_IPC); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); @@ -653,8 +654,8 @@ void manager_varlink_done(Manager *m) { * the manager, and only then disconnect it — in two steps – so that we don't end up accidentally * unreffing it twice. After all, closing the connection might cause the disconnect handler we * installed (vl_disconnect() above) to be called, where we will unref it too. */ - varlink_close_unref(TAKE_PTR(m->managed_oom_varlink)); + sd_varlink_close_unref(TAKE_PTR(m->managed_oom_varlink)); - m->varlink_server = varlink_server_unref(m->varlink_server); - m->managed_oom_varlink = varlink_close_unref(m->managed_oom_varlink); + m->varlink_server = sd_varlink_server_unref(m->varlink_server); + m->managed_oom_varlink = sd_varlink_close_unref(m->managed_oom_varlink); } diff --git a/src/core/manager-serialize.c b/src/core/manager-serialize.c index b4af82b4e1..8d998d40c1 100644 --- a/src/core/manager-serialize.c +++ b/src/core/manager-serialize.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-varlink.h" + #include "clean-ipc.h" #include "core-varlink.h" #include "dbus.h" @@ -15,7 +17,7 @@ #include "syslog-util.h" #include "unit-serialize.h" #include "user-util.h" -#include "varlink-internal.h" +#include "varlink-serialize.h" int manager_open_serialization(Manager *m, FILE **ret_f) { assert(ret_f); diff --git a/src/core/manager.h b/src/core/manager.h index 0641b2726f..2dfaf33dd0 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -7,6 +7,7 @@ #include "sd-bus.h" #include "sd-device.h" #include "sd-event.h" +#include "sd-varlink.h" #include "common-signal.h" #include "cgroup-util.h" @@ -16,7 +17,6 @@ #include "list.h" #include "prioq.h" #include "ratelimit.h" -#include "varlink.h" struct libmnt_monitor; typedef struct Unit Unit; @@ -486,12 +486,12 @@ struct Manager { unsigned sigchldgen; unsigned notifygen; - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; /* When we're a system manager, this object manages the subscription from systemd-oomd to PID1 that's * used to report changes in ManagedOOM settings (systemd server - oomd client). When * we're a user manager, this object manages the client connection from the user manager to * systemd-oomd to report changes in ManagedOOM settings (systemd client - oomd server). */ - Varlink *managed_oom_varlink; + sd_varlink *managed_oom_varlink; /* Reference to RestrictFileSystems= BPF program */ struct restrict_fs_bpf *restrict_fs; diff --git a/src/creds/creds.c b/src/creds/creds.c index 05f69ad926..be98e74915 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -4,6 +4,7 @@ #include <unistd.h> #include "sd-json.h" +#include "sd-varlink.h" #include "build.h" #include "bus-polkit.h" @@ -29,7 +30,6 @@ #include "tpm2-pcr.h" #include "tpm2-util.h" #include "user-util.h" -#include "varlink.h" #include "varlink-io.systemd.Credentials.h" #include "verbs.h" @@ -1056,7 +1056,7 @@ static int parse_argv(int argc, char *argv[]) { if (arg_tpm2_public_key_pcr_mask == UINT32_MAX) arg_tpm2_public_key_pcr_mask = UINT32_C(1) << TPM2_PCR_KERNEL_BOOT; - r = varlink_invocation(VARLINK_ALLOW_ACCEPT); + r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT); if (r < 0) return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m"); arg_varlink = r; @@ -1126,7 +1126,7 @@ static void method_encrypt_parameters_done(MethodEncryptParameters *p) { } static int settle_scope( - Varlink *link, + sd_varlink *link, CredentialScope *scope, uid_t *uid, CredentialFlags *flags, @@ -1140,7 +1140,7 @@ static int settle_scope( assert(uid); assert(flags); - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -1163,13 +1163,13 @@ static int settle_scope( } else { assert(*scope == CREDENTIAL_SYSTEM); if (uid_is_valid(*uid)) - return varlink_error_invalid_parameter_name(link, "uid"); + return sd_varlink_error_invalid_parameter_name(link, "uid"); } return 0; } -static int vl_method_encrypt(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_encrypt(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodEncryptParameters, name), 0 }, @@ -1197,28 +1197,28 @@ static int vl_method_encrypt(Varlink *link, sd_json_variant *parameters, Varlink assert(link); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.name && !credential_name_valid(p.name)) - return varlink_error_invalid_parameter_name(link, "name"); + return sd_varlink_error_invalid_parameter_name(link, "name"); /* Specifying both or neither the text string and the binary data is not allowed */ if (!!p.text == !!p.data.iov_base) - return varlink_error_invalid_parameter_name(link, "data"); + return sd_varlink_error_invalid_parameter_name(link, "data"); if (p.timestamp == UINT64_MAX) { p.timestamp = now(CLOCK_REALTIME); timestamp_fresh = true; } else timestamp_fresh = timestamp_is_fresh(p.timestamp); if (p.not_after != UINT64_MAX && p.not_after < p.timestamp) - return varlink_error_invalid_parameter_name(link, "notAfter"); + return sd_varlink_error_invalid_parameter_name(link, "notAfter"); r = settle_scope(link, &p.scope, &p.uid, &cflags, /* any_scope_after_polkit= */ NULL); if (r < 0) return r; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -1251,7 +1251,7 @@ static int vl_method_encrypt(Varlink *link, sd_json_variant *parameters, Varlink cflags, &output); if (r == -ESRCH) - return varlink_error(link, "io.systemd.Credentials.NoSuchUser", NULL); + return sd_varlink_error(link, "io.systemd.Credentials.NoSuchUser", NULL); if (r < 0) return r; @@ -1264,7 +1264,7 @@ static int vl_method_encrypt(Varlink *link, sd_json_variant *parameters, Varlink /* Let's also mark the (theoretically encrypted) reply as sensitive, in case the NULL encryption scheme was used. */ sd_json_variant_sensitive(reply); - return varlink_reply(link, reply); + return sd_varlink_reply(link, reply); } typedef struct MethodDecryptParameters { @@ -1281,7 +1281,7 @@ static void method_decrypt_parameters_done(MethodDecryptParameters *p) { iovec_done_erase(&p->blob); } -static int vl_method_decrypt(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_decrypt(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodDecryptParameters, name), 0 }, @@ -1306,12 +1306,12 @@ static int vl_method_decrypt(Varlink *link, sd_json_variant *parameters, Varlink assert(link); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.name && !credential_name_valid(p.name)) - return varlink_error_invalid_parameter_name(link, "name"); + return sd_varlink_error_invalid_parameter_name(link, "name"); if (p.timestamp == UINT64_MAX) { p.timestamp = now(CLOCK_REALTIME); timestamp_fresh = true; @@ -1322,7 +1322,7 @@ static int vl_method_decrypt(Varlink *link, sd_json_variant *parameters, Varlink if (r < 0) return r; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -1363,15 +1363,15 @@ static int vl_method_decrypt(Varlink *link, sd_json_variant *parameters, Varlink } if (r == -EBADMSG) - return varlink_error(link, "io.systemd.Credentials.BadFormat", NULL); + return sd_varlink_error(link, "io.systemd.Credentials.BadFormat", NULL); if (r == -EREMOTE) - return varlink_error(link, "io.systemd.Credentials.NameMismatch", NULL); + return sd_varlink_error(link, "io.systemd.Credentials.NameMismatch", NULL); if (r == -ESTALE) - return varlink_error(link, "io.systemd.Credentials.TimeMismatch", NULL); + return sd_varlink_error(link, "io.systemd.Credentials.TimeMismatch", NULL); if (r == -ESRCH) - return varlink_error(link, "io.systemd.Credentials.NoSuchUser", NULL); + return sd_varlink_error(link, "io.systemd.Credentials.NoSuchUser", NULL); if (r == -EMEDIUMTYPE) - return varlink_error(link, "io.systemd.Credentials.BadScope", NULL); + return sd_varlink_error(link, "io.systemd.Credentials.BadScope", NULL); if (r < 0) return r; @@ -1383,7 +1383,7 @@ static int vl_method_decrypt(Varlink *link, sd_json_variant *parameters, Varlink sd_json_variant_sensitive(reply); - return varlink_reply(link, reply); + return sd_varlink_reply(link, reply); } static int run(int argc, char *argv[]) { @@ -1396,29 +1396,29 @@ static int run(int argc, char *argv[]) { return r; if (arg_varlink) { - _cleanup_(varlink_server_unrefp) VarlinkServer *varlink_server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; _cleanup_(hashmap_freep) Hashmap *polkit_registry = NULL; /* Invocation as Varlink service */ - r = varlink_server_new(&varlink_server, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA|VARLINK_SERVER_INPUT_SENSITIVE); + r = sd_varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA|SD_VARLINK_SERVER_INPUT_SENSITIVE); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - r = varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_Credentials); + r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_Credentials); if (r < 0) return log_error_errno(r, "Failed to add Varlink interface: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( varlink_server, "io.systemd.Credentials.Encrypt", vl_method_encrypt, "io.systemd.Credentials.Decrypt", vl_method_decrypt); if (r < 0) return log_error_errno(r, "Failed to bind Varlink methods: %m"); - varlink_server_set_userdata(varlink_server, &polkit_registry); + sd_varlink_server_set_userdata(varlink_server, &polkit_registry); - r = varlink_server_loop_auto(varlink_server); + r = sd_varlink_server_loop_auto(varlink_server); if (r < 0) return log_error_errno(r, "Failed to run Varlink event loop: %m"); diff --git a/src/fuzz/fuzz-varlink-idl.c b/src/fuzz/fuzz-varlink-idl.c index c5c013d206..1ed34e4ce9 100644 --- a/src/fuzz/fuzz-varlink-idl.c +++ b/src/fuzz/fuzz-varlink-idl.c @@ -2,16 +2,18 @@ #include <unistd.h> +#include "sd-varlink-idl.h" + #include "errno-util.h" #include "fd-util.h" #include "fuzz.h" #include "io-util.h" #include "log.h" #include "string-util.h" -#include "varlink-idl.h" +#include "varlink-idl-util.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - _cleanup_(varlink_interface_freep) VarlinkInterface *vi = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *vi = NULL; _cleanup_free_ char *str = NULL, *dump = NULL; int r; @@ -28,7 +30,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; } - assert_se(varlink_idl_format(vi, &dump) >= 0); + assert_se(sd_varlink_idl_format(vi, &dump) >= 0); (void) varlink_idl_consistent(vi, LOG_DEBUG); return 0; diff --git a/src/fuzz/fuzz-varlink.c b/src/fuzz/fuzz-varlink.c index 50139faf3f..2342e34d8f 100644 --- a/src/fuzz/fuzz-varlink.c +++ b/src/fuzz/fuzz-varlink.c @@ -2,22 +2,23 @@ #include <unistd.h> +#include "sd-varlink.h" + #include "errno-util.h" #include "fd-util.h" #include "fuzz.h" #include "hexdecoct.h" #include "iovec-util.h" -#include "varlink.h" #include "log.h" static FILE *null = NULL; -static int method_something(Varlink *v, sd_json_variant *p, VarlinkMethodFlags flags, void *userdata) { +static int method_something(sd_varlink *v, sd_json_variant *p, sd_varlink_method_flags_t flags, void *userdata) { sd_json_variant_dump(p, SD_JSON_FORMAT_NEWLINE|SD_JSON_FORMAT_PRETTY, null, NULL); return 0; } -static int reply_callback(Varlink *v, sd_json_variant *p, const char *error_id, VarlinkReplyFlags flags, void *userdata) { +static int reply_callback(sd_varlink *v, sd_json_variant *p, const char *error_id, sd_varlink_reply_flags_t flags, void *userdata) { sd_json_variant_dump(p, SD_JSON_FORMAT_NEWLINE|SD_JSON_FORMAT_PRETTY, null, NULL); return 0; } @@ -88,8 +89,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_close_pair_ int server_pair[2] = EBADF_PAIR, client_pair[2] = EBADF_PAIR; _cleanup_(sd_event_source_unrefp) sd_event_source *idle_event_source = NULL, *server_event_source = NULL, *client_event_source = NULL; - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; - _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *c = NULL; _cleanup_(sd_event_unrefp) sd_event *e = NULL; fuzz_setup_logging(); @@ -100,22 +101,22 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { /* Test one: write the data as method call to a server */ assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, server_pair) >= 0); - assert_se(varlink_server_new(&s, 0) >= 0); - assert_se(varlink_server_set_description(s, "myserver") >= 0); - assert_se(varlink_server_attach_event(s, e, 0) >= 0); - assert_se(varlink_server_add_connection(s, server_pair[0], NULL) >= 0); + assert_se(sd_varlink_server_new(&s, 0) >= 0); + assert_se(sd_varlink_server_set_description(s, "myserver") >= 0); + assert_se(sd_varlink_server_attach_event(s, e, 0) >= 0); + assert_se(sd_varlink_server_add_connection(s, server_pair[0], NULL) >= 0); TAKE_FD(server_pair[0]); - assert_se(varlink_server_bind_method(s, "io.test.DoSomething", method_something) >= 0); + assert_se(sd_varlink_server_bind_method(s, "io.test.DoSomething", method_something) >= 0); assert_se(sd_event_add_io(e, &server_event_source, server_pair[1], EPOLLIN|EPOLLOUT, io_callback, &server_iov) >= 0); /* Test two: write the data as method response to a client */ assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, client_pair) >= 0); - assert_se(varlink_connect_fd(&c, client_pair[0]) >= 0); + assert_se(sd_varlink_connect_fd(&c, client_pair[0]) >= 0); TAKE_FD(client_pair[0]); - assert_se(varlink_set_description(c, "myclient") >= 0); - assert_se(varlink_attach_event(c, e, 0) >= 0); - assert_se(varlink_bind_reply(c, reply_callback) >= 0); - assert_se(varlink_invoke(c, "io.test.DoSomething", NULL) >= 0); + assert_se(sd_varlink_set_description(c, "myclient") >= 0); + assert_se(sd_varlink_attach_event(c, e, 0) >= 0); + assert_se(sd_varlink_bind_reply(c, reply_callback) >= 0); + assert_se(sd_varlink_invoke(c, "io.test.DoSomething", NULL) >= 0); assert_se(sd_event_add_io(e, &client_event_source, client_pair[1], EPOLLIN|EPOLLOUT, io_callback, &client_iov) >= 0); assert_se(sd_event_add_defer(e, &idle_event_source, idle_callback, NULL) >= 0); diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 417b5e342e..cb26ed530b 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -293,7 +293,7 @@ Manager* manager_free(Manager *m) { hashmap_free(m->public_keys); - varlink_server_unref(m->varlink_server); + sd_varlink_server_unref(m->varlink_server); free(m->userdb_service); free(m->default_file_system_type); @@ -1008,17 +1008,17 @@ static int manager_bind_varlink(Manager *m) { assert(m); assert(!m->varlink_server); - r = varlink_server_new(&m->varlink_server, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA|VARLINK_SERVER_INPUT_SENSITIVE); + r = sd_varlink_server_new(&m->varlink_server, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA|SD_VARLINK_SERVER_INPUT_SENSITIVE); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(m->varlink_server, m); + sd_varlink_server_set_userdata(m->varlink_server, m); - r = varlink_server_add_interface(m->varlink_server, &vl_interface_io_systemd_UserDatabase); + r = sd_varlink_server_add_interface(m->varlink_server, &vl_interface_io_systemd_UserDatabase); if (r < 0) return log_error_errno(r, "Failed to add UserDatabase interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( m->varlink_server, "io.systemd.UserDatabase.GetUserRecord", vl_method_get_user_record, "io.systemd.UserDatabase.GetGroupRecord", vl_method_get_group_record, @@ -1039,11 +1039,11 @@ static int manager_bind_varlink(Manager *m) { } else socket_path = "/run/systemd/userdb/io.systemd.Home"; - r = varlink_server_listen_address(m->varlink_server, socket_path, 0666); + r = sd_varlink_server_listen_address(m->varlink_server, socket_path, 0666); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(m->varlink_server, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(m->varlink_server, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); diff --git a/src/home/homed-manager.h b/src/home/homed-manager.h index 20bbb4cfeb..3369284e2a 100644 --- a/src/home/homed-manager.h +++ b/src/home/homed-manager.h @@ -6,12 +6,12 @@ #include "sd-bus.h" #include "sd-device.h" #include "sd-event.h" +#include "sd-varlink.h" typedef struct Manager Manager; #include "hashmap.h" #include "homed-home.h" -#include "varlink.h" /* The LUKS free disk space rebalancing logic goes through this state machine */ typedef enum RebalanceState { @@ -55,7 +55,7 @@ struct Manager { Home *gc_focus; - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; char *userdb_service; EVP_PKEY *private_key; /* actually a pair of private and public key */ diff --git a/src/home/homed-varlink.c b/src/home/homed-varlink.c index bde25353ab..54559d3a08 100644 --- a/src/home/homed-varlink.c +++ b/src/home/homed-varlink.c @@ -18,14 +18,14 @@ typedef struct LookupParameters { const char *service; } LookupParameters; -static bool client_is_trusted(Varlink *link, Home *h) { +static bool client_is_trusted(sd_varlink *link, Home *h) { uid_t peer_uid; int r; assert(link); assert(h); - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) { log_debug_errno(r, "Unable to query peer UID, ignoring: %m"); return false; @@ -70,7 +70,7 @@ static bool home_user_match_lookup_parameters(LookupParameters *p, Home *h) { return true; } -int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, @@ -90,12 +90,12 @@ int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, Varlin assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, m->userdb_service)) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (uid_is_valid(p.uid)) h = hashmap_get(m->homes_by_uid, UID_TO_PTR(p.uid)); @@ -114,7 +114,7 @@ int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, Varlin if (v) { /* An entry set from the previous iteration? Then send it now */ - r = varlink_notify(link, v); + r = sd_varlink_notify(link, v); if (r < 0) return r; @@ -129,16 +129,16 @@ int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, Varlin } if (!v) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } if (!h) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (!home_user_match_lookup_parameters(&p, h)) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); trusted = client_is_trusted(link, h); @@ -146,7 +146,7 @@ int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, Varlin if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } static int build_group_json(Home *h, sd_json_variant **ret) { @@ -183,7 +183,7 @@ static bool home_group_match_lookup_parameters(LookupParameters *p, Home *h) { return true; } -int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, @@ -202,12 +202,12 @@ int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, Varli assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, m->userdb_service)) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (gid_is_valid(p.gid)) h = hashmap_get(m->homes_by_uid, UID_TO_PTR((uid_t) p.gid)); @@ -221,7 +221,7 @@ int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, Varli continue; if (v) { - r = varlink_notify(link, v); + r = sd_varlink_notify(link, v); if (r < 0) return r; @@ -234,25 +234,25 @@ int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, Varli } if (!v) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } if (!h) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (!home_group_match_lookup_parameters(&p, h)) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_group_json(h, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } -int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_get_memberships(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_STRICT }, @@ -268,25 +268,25 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, m->userdb_service)) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (p.user_name) { const char *last = NULL; h = hashmap_get(m->homes_by_name, p.user_name); if (!h) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (p.group_name) { if (!strv_contains(h->record->member_of, p.group_name)) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(h->user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(p.group_name))); @@ -294,7 +294,7 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin STRV_FOREACH(i, h->record->member_of) { if (last) { - r = varlink_notifybo( + r = sd_varlink_notifybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(h->user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last))); @@ -306,7 +306,7 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin } if (last) - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(h->user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last))); @@ -320,7 +320,7 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin continue; if (last) { - r = varlink_notifybo( + r = sd_varlink_notifybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(p.group_name))); @@ -332,7 +332,7 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin } if (last) - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(p.group_name))); @@ -345,7 +345,7 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin if (last_user_name) { assert(last_group_name); - r = varlink_notifybo( + r = sd_varlink_notifybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last_user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last_group_name))); @@ -360,12 +360,12 @@ int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, Varlin if (last_user_name) { assert(last_group_name); - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last_user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last_group_name))); } } - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } diff --git a/src/home/homed-varlink.h b/src/home/homed-varlink.h index bb1d4c0686..9bfea3a448 100644 --- a/src/home/homed-varlink.h +++ b/src/home/homed-varlink.h @@ -3,6 +3,6 @@ #include "homed-manager.h" -int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); -int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); -int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); +int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +int vl_method_get_memberships(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 1adbb8eece..74ed6301d9 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -80,7 +80,7 @@ typedef struct Context { sd_event *event; sd_bus *bus; - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; Hashmap *polkit_registry; } Context; @@ -102,7 +102,7 @@ static void context_destroy(Context *c) { hashmap_free(c->polkit_registry); sd_event_unref(c->event); sd_bus_flush_close_unref(c->bus); - varlink_server_unref(c->varlink_server); + sd_varlink_server_unref(c->varlink_server); } static void context_read_etc_hostname(Context *c) { @@ -1601,7 +1601,7 @@ static int connect_bus(Context *c) { return 0; } -static int vl_method_describe(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_describe(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { VARLINK_DISPATCH_POLKIT_FIELD, {} @@ -1614,7 +1614,7 @@ static int vl_method_describe(Varlink *link, sd_json_variant *parameters, Varlin assert(link); assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, /* userdata= */ NULL); + r = sd_varlink_dispatch(link, parameters, dispatch_table, /* userdata= */ NULL); if (r != 0) return r; @@ -1638,7 +1638,7 @@ static int vl_method_describe(Varlink *link, sd_json_variant *parameters, Varlin if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } static int connect_varlink(Context *c) { @@ -1648,31 +1648,31 @@ static int connect_varlink(Context *c) { assert(c->event); assert(!c->varlink_server); - r = varlink_server_new(&c->varlink_server, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&c->varlink_server, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - varlink_server_set_userdata(c->varlink_server, c); + sd_varlink_server_set_userdata(c->varlink_server, c); - r = varlink_server_add_interface(c->varlink_server, &vl_interface_io_systemd_Hostname); + r = sd_varlink_server_add_interface(c->varlink_server, &vl_interface_io_systemd_Hostname); if (r < 0) - return log_error_errno(r, "Failed to add Hostname interface to varlink server: %m"); + return log_error_errno(r, "Failed to add Hostname interface to Varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( c->varlink_server, "io.systemd.Hostname.Describe", vl_method_describe); if (r < 0) return log_error_errno(r, "Failed to bind Varlink method calls: %m"); - r = varlink_server_attach_event(c->varlink_server, c->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(c->varlink_server, c->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach Varlink server to event loop: %m"); - r = varlink_server_listen_auto(c->varlink_server); + r = sd_varlink_server_listen_auto(c->varlink_server); if (r < 0) return log_error_errno(r, "Failed to bind to passed Varlink sockets: %m"); if (r == 0) { - r = varlink_server_listen_address(c->varlink_server, "/run/systemd/io.systemd.Hostname", 0666); + r = sd_varlink_server_listen_address(c->varlink_server, "/run/systemd/io.systemd.Hostname", 0666); if (r < 0) return log_error_errno(r, "Failed to bind to Varlink socket: %m"); } @@ -1683,7 +1683,7 @@ static int connect_varlink(Context *c) { static bool context_check_idle(void *userdata) { Context *c = ASSERT_PTR(userdata); - return varlink_server_current_connections(c->varlink_server) == 0 && + return sd_varlink_server_current_connections(c->varlink_server) == 0 && hashmap_isempty(c->polkit_registry); } diff --git a/src/import/importd.c b/src/import/importd.c index 112180c846..79c2e45276 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -4,6 +4,7 @@ #include <sys/wait.h> #include "sd-bus.h" +#include "sd-varlink.h" #include "alloc-util.h" #include "build-path.h" @@ -40,8 +41,8 @@ #include "strv.h" #include "syslog-util.h" #include "user-util.h" -#include "varlink.h" #include "varlink-io.systemd.Import.h" +#include "varlink-util.h" #include "web-util.h" typedef struct Transfer Transfer; @@ -97,7 +98,7 @@ struct Transfer { struct Manager { sd_event *event; sd_bus *bus; - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; uint32_t current_transfer_id; Hashmap *transfers; @@ -126,7 +127,7 @@ static const char* const transfer_type_table[_TRANSFER_TYPE_MAX] = { DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(transfer_type, TransferType); -DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(varlink_hash_ops, void, trivial_hash_func, trivial_compare_func, Varlink, varlink_unref); +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(varlink_hash_ops, void, trivial_hash_func, trivial_compare_func, sd_varlink, sd_varlink_unref); static Transfer *transfer_unref(Transfer *t) { if (!t) @@ -622,7 +623,7 @@ static Manager *manager_unref(Manager *m) { hashmap_free(m->polkit_registry); m->bus = sd_bus_flush_close_unref(m->bus); - m->varlink_server = varlink_server_unref(m->varlink_server); + m->varlink_server = sd_varlink_server_unref(m->varlink_server); sd_event_unref(m->event); @@ -1786,7 +1787,7 @@ static int make_transfer_json(Transfer *t, sd_json_variant **ret) { return 0; } -static int vl_method_list_transfers(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_list_transfers(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { struct p { ImageClass class; @@ -1805,12 +1806,12 @@ static int vl_method_list_transfers(Varlink *link, sd_json_variant *parameters, assert(link); assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; - if (!FLAGS_SET(flags, VARLINK_METHOD_MORE)) - return varlink_error(link, VARLINK_ERROR_EXPECTED_MORE, NULL); + if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE)) + return sd_varlink_error(link, SD_VARLINK_ERROR_EXPECTED_MORE, NULL); Transfer *previous = NULL, *t; HASHMAP_FOREACH(t, m->transfers) { @@ -1825,7 +1826,7 @@ static int vl_method_list_transfers(Varlink *link, sd_json_variant *parameters, if (r < 0) return r; - r = varlink_notify(link, v); + r = sd_varlink_notify(link, v); if (r < 0) return r; } @@ -1840,16 +1841,16 @@ static int vl_method_list_transfers(Varlink *link, sd_json_variant *parameters, if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } - return varlink_error(link, "io.systemd.Import.NoTransfers", NULL); + return sd_varlink_error(link, "io.systemd.Import.NoTransfers", NULL); } static JSON_DISPATCH_ENUM_DEFINE(json_dispatch_import_verify, ImportVerify, import_verify_from_string); static JSON_DISPATCH_ENUM_DEFINE(json_dispatch_import_type, ImportType, import_type_from_string); -static int vl_method_pull(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_pull(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { struct p { const char *remote, *local; @@ -1883,15 +1884,15 @@ static int vl_method_pull(Varlink *link, sd_json_variant *parameters, VarlinkMet assert(link); assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!http_url_is_valid(p.remote) && !file_url_is_valid(p.remote)) - return varlink_error_invalid_parameter_name(link, "remote"); + return sd_varlink_error_invalid_parameter_name(link, "remote"); if (p.local && !image_name_is_valid(p.local)) - return varlink_error_invalid_parameter_name(link, "local"); + return sd_varlink_error_invalid_parameter_name(link, "local"); uint64_t transfer_flags = (p.force * IMPORT_FORCE) | (p.read_only * IMPORT_READ_ONLY) | (p.keep_download * IMPORT_PULL_KEEP_DOWNLOAD); @@ -1902,7 +1903,7 @@ static int vl_method_pull(Varlink *link, sd_json_variant *parameters, VarlinkMet assert(tt >= 0); if (manager_find(m, tt, p.remote)) - return varlink_errorbo(link, "io.systemd.Import.AlreadyInProgress", SD_JSON_BUILD_PAIR_STRING("remote", p.remote)); + return sd_varlink_errorbo(link, "io.systemd.Import.AlreadyInProgress", SD_JSON_BUILD_PAIR_STRING("remote", p.remote)); r = varlink_verify_polkit_async( link, @@ -1944,17 +1945,17 @@ static int vl_method_pull(Varlink *link, sd_json_variant *parameters, VarlinkMet return r; /* If more was not set, just return the download id, and be done with it */ - if (!FLAGS_SET(flags, VARLINK_METHOD_MORE)) - return varlink_replybo(link, SD_JSON_BUILD_PAIR("id", SD_JSON_BUILD_UNSIGNED(t->id))); + if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE)) + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR("id", SD_JSON_BUILD_UNSIGNED(t->id))); /* Otherwise add this connection to the set of subscriptions, return the id, but keep the thing running */ r = set_ensure_put(&t->varlink_subscribed, &varlink_hash_ops, link); if (r < 0) return r; - varlink_ref(link); + sd_varlink_ref(link); - r = varlink_notifybo(link, SD_JSON_BUILD_PAIR("id", SD_JSON_BUILD_UNSIGNED(t->id))); + r = sd_varlink_notifybo(link, SD_JSON_BUILD_PAIR("id", SD_JSON_BUILD_UNSIGNED(t->id))); if (r < 0) return r; @@ -1969,32 +1970,32 @@ static int manager_connect_varlink(Manager *m) { assert(m->event); assert(!m->varlink_server); - r = varlink_server_new(&m->varlink_server, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&m->varlink_server, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - varlink_server_set_userdata(m->varlink_server, m); + sd_varlink_server_set_userdata(m->varlink_server, m); - r = varlink_server_add_interface(m->varlink_server, &vl_interface_io_systemd_Import); + r = sd_varlink_server_add_interface(m->varlink_server, &vl_interface_io_systemd_Import); if (r < 0) return log_error_errno(r, "Failed to add Import interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( m->varlink_server, "io.systemd.Import.ListTransfers", vl_method_list_transfers, "io.systemd.Import.Pull", vl_method_pull); if (r < 0) return log_error_errno(r, "Failed to bind Varlink method calls: %m"); - r = varlink_server_attach_event(m->varlink_server, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(m->varlink_server, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach Varlink server to event loop: %m"); - r = varlink_server_listen_auto(m->varlink_server); + r = sd_varlink_server_listen_auto(m->varlink_server); if (r < 0) return log_error_errno(r, "Failed to bind to passed Varlink sockets: %m"); if (r == 0) { - r = varlink_server_listen_address(m->varlink_server, "/run/systemd/io.systemd.Import", 0666); + r = sd_varlink_server_listen_address(m->varlink_server, "/run/systemd/io.systemd.Import", 0666); if (r < 0) return log_error_errno(r, "Failed to bind to Varlink socket: %m"); } @@ -2007,7 +2008,7 @@ static bool manager_check_idle(void *userdata) { return hashmap_isempty(m->transfers) && hashmap_isempty(m->polkit_registry) && - varlink_server_current_connections(m->varlink_server) == 0; + sd_varlink_server_current_connections(m->varlink_server) == 0; } static void manager_parse_env(Manager *m) { diff --git a/src/journal/journalctl-varlink.c b/src/journal/journalctl-varlink.c index 89aed05334..712e93292d 100644 --- a/src/journal/journalctl-varlink.c +++ b/src/journal/journalctl-varlink.c @@ -1,15 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-varlink.h" + #include "errno-util.h" #include "journal-internal.h" #include "journal-vacuum.h" #include "journalctl.h" #include "journalctl-util.h" #include "journalctl-varlink.h" -#include "varlink.h" +#include "varlink-util.h" -static int varlink_connect_journal(Varlink **ret) { - _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; +static int varlink_connect_journal(sd_varlink **ret) { + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL; const char *address; int r; @@ -19,19 +21,19 @@ static int varlink_connect_journal(Varlink **ret) { strjoina("/run/systemd/journal.", arg_namespace, "/io.systemd.journal") : "/run/systemd/journal/io.systemd.journal"; - r = varlink_connect_address(&vl, address); + r = sd_varlink_connect_address(&vl, address); if (r < 0) return r; - (void) varlink_set_description(vl, "journal"); - (void) varlink_set_relative_timeout(vl, USEC_INFINITY); + (void) sd_varlink_set_description(vl, "journal"); + (void) sd_varlink_set_relative_timeout(vl, USEC_INFINITY); *ret = TAKE_PTR(vl); return 0; } int action_flush_to_var(void) { - _cleanup_(varlink_flush_close_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL; int r; assert(arg_action == ACTION_FLUSH); @@ -54,7 +56,7 @@ int action_flush_to_var(void) { } int action_relinquish_var(void) { - _cleanup_(varlink_flush_close_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL; int r; assert(arg_action == ACTION_RELINQUISH_VAR); @@ -72,7 +74,7 @@ int action_relinquish_var(void) { } int action_rotate(void) { - _cleanup_(varlink_flush_close_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL; int r; assert(IN_SET(arg_action, ACTION_ROTATE, ACTION_ROTATE_AND_VACUUM)); @@ -121,7 +123,7 @@ int action_rotate_and_vacuum(void) { } int action_sync(void) { - _cleanup_(varlink_flush_close_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL; int r; assert(arg_action == ACTION_SYNC); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 28bd223c9e..57db614691 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -2187,11 +2187,11 @@ static int server_connect_notify(Server *s) { } static int synchronize_second_half(sd_event_source *event_source, void *userdata) { - Varlink *link = ASSERT_PTR(userdata); + sd_varlink *link = ASSERT_PTR(userdata); Server *s; int r; - assert_se(s = varlink_get_userdata(link)); + assert_se(s = sd_varlink_get_userdata(link)); /* This is the "second half" of the Synchronize() varlink method. This function is called as deferred * event source at a low priority to ensure the synchronization completes after all queued log @@ -2205,14 +2205,14 @@ static int synchronize_second_half(sd_event_source *event_source, void *userdata if (r < 0) return log_error_errno(r, "Failed to mark event source as non-floating: %m"); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } static void synchronize_destroy(void *userdata) { - varlink_unref(userdata); + sd_varlink_unref(userdata); } -static int vl_method_synchronize(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_synchronize(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_event_source_unrefp) sd_event_source *event_source = NULL; Server *s = ASSERT_PTR(userdata); int r; @@ -2220,7 +2220,7 @@ static int vl_method_synchronize(Varlink *link, sd_json_variant *parameters, Var assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); log_info("Received client request to sync journal."); @@ -2236,7 +2236,7 @@ static int vl_method_synchronize(Varlink *link, sd_json_variant *parameters, Var if (r < 0) return log_error_errno(r, "Failed to set event source destroy callback: %m"); - varlink_ref(link); /* The varlink object is now left to the destroy callback to unref */ + sd_varlink_ref(link); /* The varlink object is now left to the destroy callback to unref */ r = sd_event_source_set_priority(event_source, SD_EVENT_PRIORITY_NORMAL+15); if (r < 0) @@ -2253,53 +2253,53 @@ static int vl_method_synchronize(Varlink *link, sd_json_variant *parameters, Var return 0; } -static int vl_method_rotate(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_rotate(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Server *s = ASSERT_PTR(userdata); assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); log_info("Received client request to rotate journal, rotating."); server_full_rotate(s); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -static int vl_method_flush_to_var(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_flush_to_var(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Server *s = ASSERT_PTR(userdata); assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); if (s->namespace) - return varlink_error(link, "io.systemd.Journal.NotSupportedByNamespaces", NULL); + return sd_varlink_error(link, "io.systemd.Journal.NotSupportedByNamespaces", NULL); log_info("Received client request to flush runtime journal."); server_full_flush(s); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -static int vl_method_relinquish_var(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_relinquish_var(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Server *s = ASSERT_PTR(userdata); assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); if (s->namespace) - return varlink_error(link, "io.systemd.Journal.NotSupportedByNamespaces", NULL); + return sd_varlink_error(link, "io.systemd.Journal.NotSupportedByNamespaces", NULL); log_info("Received client request to relinquish %s access.", s->system_storage.path); server_relinquish_var(s); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -static int vl_connect(VarlinkServer *server, Varlink *link, void *userdata) { +static int vl_connect(sd_varlink_server *server, sd_varlink *link, void *userdata) { Server *s = ASSERT_PTR(userdata); assert(server); @@ -2310,7 +2310,7 @@ static int vl_connect(VarlinkServer *server, Varlink *link, void *userdata) { return 0; } -static void vl_disconnect(VarlinkServer *server, Varlink *link, void *userdata) { +static void vl_disconnect(sd_varlink_server *server, sd_varlink *link, void *userdata) { Server *s = ASSERT_PTR(userdata); assert(server); @@ -2324,17 +2324,17 @@ static int server_open_varlink(Server *s, const char *socket, int fd) { assert(s); - r = varlink_server_new(&s->varlink_server, VARLINK_SERVER_ROOT_ONLY|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&s->varlink_server, SD_VARLINK_SERVER_ROOT_ONLY|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return r; - varlink_server_set_userdata(s->varlink_server, s); + sd_varlink_server_set_userdata(s->varlink_server, s); - r = varlink_server_add_interface(s->varlink_server, &vl_interface_io_systemd_Journal); + r = sd_varlink_server_add_interface(s->varlink_server, &vl_interface_io_systemd_Journal); if (r < 0) return log_error_errno(r, "Failed to add Journal interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( s->varlink_server, "io.systemd.Journal.Synchronize", vl_method_synchronize, "io.systemd.Journal.Rotate", vl_method_rotate, @@ -2343,22 +2343,22 @@ static int server_open_varlink(Server *s, const char *socket, int fd) { if (r < 0) return r; - r = varlink_server_bind_connect(s->varlink_server, vl_connect); + r = sd_varlink_server_bind_connect(s->varlink_server, vl_connect); if (r < 0) return r; - r = varlink_server_bind_disconnect(s->varlink_server, vl_disconnect); + r = sd_varlink_server_bind_disconnect(s->varlink_server, vl_disconnect); if (r < 0) return r; if (fd < 0) - r = varlink_server_listen_address(s->varlink_server, socket, 0600); + r = sd_varlink_server_listen_address(s->varlink_server, socket, 0600); else - r = varlink_server_listen_fd(s->varlink_server, fd); + r = sd_varlink_server_listen_fd(s->varlink_server, fd); if (r < 0) return r; - r = varlink_server_attach_event(s->varlink_server, s->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(s->varlink_server, s->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return r; @@ -2423,7 +2423,7 @@ static bool server_is_idle(Server *s) { return false; /* We aren't idle if we have a varlink client */ - if (varlink_server_current_connections(s->varlink_server) > 0) + if (sd_varlink_server_current_connections(s->varlink_server) > 0) return false; /* If we have stdout streams we aren't idle */ @@ -2898,7 +2898,7 @@ Server* server_free(Server *s) { ordered_hashmap_free_with_destructor(s->user_journals, journal_file_offline_close); - varlink_server_unref(s->varlink_server); + sd_varlink_server_unref(s->varlink_server); sd_event_source_unref(s->syslog_event_source); sd_event_source_unref(s->native_event_source); diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index f9405e18c7..1f9e5dcf67 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -5,7 +5,7 @@ #include <sys/types.h> #include "sd-event.h" -#include "socket-util.h" +#include "sd-varlink.h" typedef struct Server Server; @@ -18,8 +18,8 @@ typedef struct Server Server; #include "list.h" #include "prioq.h" #include "ratelimit.h" +#include "socket-util.h" #include "time-util.h" -#include "varlink.h" typedef enum Storage { STORAGE_AUTO, @@ -185,7 +185,7 @@ struct Server { ClientContext *my_context; /* the context of journald itself */ ClientContext *pid1_context; /* the context of PID 1 */ - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; }; #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID=")) diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index ccd902df3d..af2ea430f5 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -948,4 +948,100 @@ global: sd_json_variant_unref; sd_json_variant_unref_many; sd_json_variant_unsigned; + sd_varlink_attach_event; + sd_varlink_bind_reply; + sd_varlink_call; + sd_varlink_call_full; + sd_varlink_callb; + sd_varlink_callb_ap; + sd_varlink_callb_full; + sd_varlink_close; + sd_varlink_close_unref; + sd_varlink_collect; + sd_varlink_collect_full; + sd_varlink_collectb; + sd_varlink_connect_address; + sd_varlink_connect_exec; + sd_varlink_connect_fd; + sd_varlink_connect_fd_pair; + sd_varlink_connect_url; + sd_varlink_detach_event; + sd_varlink_dispatch; + sd_varlink_dispatch_again; + sd_varlink_error; + sd_varlink_error_errno; + sd_varlink_error_invalid_parameter; + sd_varlink_error_invalid_parameter_name; + sd_varlink_error_to_errno; + sd_varlink_errorb; + sd_varlink_flush; + sd_varlink_flush_close_unref; + sd_varlink_get_current_parameters; + sd_varlink_get_event; + sd_varlink_get_events; + sd_varlink_get_fd; + sd_varlink_get_peer_gid; + sd_varlink_get_peer_pid; + sd_varlink_get_peer_pidfd; + sd_varlink_get_peer_uid; + sd_varlink_get_server; + sd_varlink_get_timeout; + sd_varlink_get_userdata; + sd_varlink_idl_dump; + sd_varlink_idl_format; + sd_varlink_idl_format_full; + sd_varlink_invocation; + sd_varlink_invoke; + sd_varlink_invokeb; + sd_varlink_is_idle; + sd_varlink_notify; + sd_varlink_notifyb; + sd_varlink_observe; + sd_varlink_observeb; + sd_varlink_peek_dup_fd; + sd_varlink_peek_fd; + sd_varlink_process; + sd_varlink_push_dup_fd; + sd_varlink_push_fd; + sd_varlink_ref; + sd_varlink_reply; + sd_varlink_replyb; + sd_varlink_send; + sd_varlink_sendb; + sd_varlink_server_add_connection; + sd_varlink_server_add_connection_pair; + sd_varlink_server_add_connection_stdio; + sd_varlink_server_add_interface; + sd_varlink_server_add_interface_many_internal; + sd_varlink_server_attach_event; + sd_varlink_server_bind_connect; + sd_varlink_server_bind_disconnect; + sd_varlink_server_bind_method; + sd_varlink_server_bind_method_many_internal; + sd_varlink_server_connections_max; + sd_varlink_server_connections_per_uid_max; + sd_varlink_server_current_connections; + sd_varlink_server_detach_event; + sd_varlink_server_get_event; + sd_varlink_server_get_userdata; + sd_varlink_server_listen_address; + sd_varlink_server_listen_auto; + sd_varlink_server_listen_fd; + sd_varlink_server_loop_auto; + sd_varlink_server_new; + sd_varlink_server_set_connections_max; + sd_varlink_server_set_connections_per_uid_max; + sd_varlink_server_set_description; + sd_varlink_server_set_exit_on_idle; + sd_varlink_server_set_userdata; + sd_varlink_server_shutdown; + sd_varlink_set_allow_fd_passing_input; + sd_varlink_set_allow_fd_passing_output; + sd_varlink_set_description; + sd_varlink_set_input_sensitive; + sd_varlink_set_relative_timeout; + sd_varlink_set_userdata; + sd_varlink_take_fd; + sd_varlink_unref; + sd_varlink_wait; } LIBSYSTEMD_256; diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index ee7b18da82..d73c3a8974 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -73,6 +73,16 @@ sd_json_sources = files( ############################################################ +sd_varlink_sources = files( + 'sd-varlink/sd-varlink.c', + 'sd-varlink/sd-varlink-idl.c', + 'sd-varlink/varlink-io.systemd.c', + 'sd-varlink/varlink-org.varlink.service.c', + 'sd-varlink/varlink-util.c', +) + +############################################################ + libsystemd_sources = files( 'sd-bus/bus-common-errors.c', 'sd-bus/bus-container.c', @@ -116,7 +126,7 @@ libsystemd_sources = files( 'sd-network/sd-network.c', 'sd-path/sd-path.c', 'sd-resolve/sd-resolve.c', -) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources + sd_json_sources +) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources + sd_json_sources + sd_varlink_sources libsystemd_c_args = ['-fvisibility=default'] diff --git a/src/shared/varlink-idl.c b/src/libsystemd/sd-varlink/sd-varlink-idl.c index e6a4942ad8..8ca7725b06 100644 --- a/src/shared/varlink-idl.c +++ b/src/libsystemd/sd-varlink/sd-varlink-idl.c @@ -1,12 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-varlink-idl.h" + #include "json-util.h" #include "memstream-util.h" #include "set.h" #include "strv.h" #include "terminal-util.h" #include "utf8.h" -#include "varlink-idl.h" +#include "varlink-idl-util.h" #define DEPTH_MAX 64U @@ -23,7 +25,7 @@ enum { #define varlink_idl_log(error, format, ...) log_debug_errno(error, "Varlink-IDL: " format, ##__VA_ARGS__) #define varlink_idl_log_full(level, error, format, ...) log_full_errno(level, error, "Varlink-IDL: " format, ##__VA_ARGS__) -static int varlink_idl_format_all_fields(FILE *f, const VarlinkSymbol *symbol, VarlinkFieldDirection direction, const char *indent, const char *const colors[static _COLOR_MAX], size_t cols); +static int varlink_idl_format_all_fields(FILE *f, const sd_varlink_symbol *symbol, sd_varlink_field_direction_t direction, const char *indent, const char *const colors[static _COLOR_MAX], size_t cols); static int varlink_idl_format_comment( FILE *f, @@ -76,7 +78,7 @@ static int varlink_idl_format_comment( static int varlink_idl_format_comment_fields( FILE *f, - const VarlinkField *start, + const sd_varlink_field *start, size_t n, const char *indent, const char *const colors[static _COLOR_MAX], @@ -89,7 +91,7 @@ static int varlink_idl_format_comment_fields( assert(start); - for (const VarlinkField *c = start; n > 0; c++, n--) { + for (const sd_varlink_field *c = start; n > 0; c++, n--) { r = varlink_idl_format_comment(f, ASSERT_PTR(c->name), indent, colors, cols); if (r < 0) return r; @@ -98,20 +100,20 @@ static int varlink_idl_format_comment_fields( return 0; } -static const VarlinkField *varlink_idl_symbol_find_start_comment( - const VarlinkSymbol *symbol, - const VarlinkField *field) { +static const sd_varlink_field *varlink_idl_symbol_find_start_comment( + const sd_varlink_symbol *symbol, + const sd_varlink_field *field) { assert(symbol); assert(field); assert(field >= symbol->fields); - const VarlinkField *start = NULL; + const sd_varlink_field *start = NULL; - for (const VarlinkField *c1 = field; c1 > symbol->fields; c1--) { - const VarlinkField *c0 = c1 - 1; + for (const sd_varlink_field *c1 = field; c1 > symbol->fields; c1--) { + const sd_varlink_field *c0 = c1 - 1; - if (c0->field_type != _VARLINK_FIELD_COMMENT) + if (c0->field_type != _SD_VARLINK_FIELD_COMMENT) break; start = c0; @@ -122,7 +124,7 @@ static const VarlinkField *varlink_idl_symbol_find_start_comment( static int varlink_idl_format_enum_values( FILE *f, - const VarlinkSymbol *symbol, + const sd_varlink_symbol *symbol, const char *indent, const char *const colors[static _COLOR_MAX], size_t cols) { @@ -133,15 +135,15 @@ static int varlink_idl_format_enum_values( assert(f); assert(symbol); - assert(symbol->symbol_type == VARLINK_ENUM_TYPE); + assert(symbol->symbol_type == SD_VARLINK_ENUM_TYPE); indent2 = strjoin(strempty(indent), "\t"); if (!indent2) return -ENOMEM; - for (const VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { + for (const sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { - if (field->field_type == _VARLINK_FIELD_COMMENT) /* skip comments at first */ + if (field->field_type == _SD_VARLINK_FIELD_COMMENT) /* skip comments at first */ continue; if (first) { @@ -153,7 +155,7 @@ static int varlink_idl_format_enum_values( /* We found an enum value we want to output. In this case, start by outputting all * immediately preceding comments. For that find the first comment in the series before the * enum value, so that we can start printing from there. */ - const VarlinkField *start_comment = varlink_idl_symbol_find_start_comment(symbol, field); + const sd_varlink_field *start_comment = varlink_idl_symbol_find_start_comment(symbol, field); if (start_comment) { r = varlink_idl_format_comment_fields(f, start_comment, field - start_comment, indent2, colors, cols); @@ -180,14 +182,14 @@ static int varlink_idl_format_enum_values( static int varlink_idl_format_field( FILE *f, - const VarlinkField *field, + const sd_varlink_field *field, const char *indent, const char *const colors[static _COLOR_MAX], size_t cols) { assert(f); assert(field); - assert(field->field_type != _VARLINK_FIELD_COMMENT); + assert(field->field_type != _SD_VARLINK_FIELD_COMMENT); fputs(strempty(indent), f); fputs(colors[COLOR_IDENTIFIER], f); @@ -195,15 +197,15 @@ static int varlink_idl_format_field( fputs(colors[COLOR_RESET], f); fputs(": ", f); - if (FLAGS_SET(field->field_flags, VARLINK_NULLABLE)) { + if (FLAGS_SET(field->field_flags, SD_VARLINK_NULLABLE)) { fputs(colors[COLOR_MARKS], f); fputs("?", f); fputs(colors[COLOR_RESET], f); } - switch (field->field_flags & (VARLINK_MAP|VARLINK_ARRAY)) { + switch (field->field_flags & (SD_VARLINK_MAP|SD_VARLINK_ARRAY)) { - case VARLINK_MAP: + case SD_VARLINK_MAP: fputs(colors[COLOR_MARKS], f); fputs("[", f); fputs(colors[COLOR_FIELD_TYPE], f); @@ -213,7 +215,7 @@ static int varlink_idl_format_field( fputs(colors[COLOR_RESET], f); break; - case VARLINK_ARRAY: + case SD_VARLINK_ARRAY: fputs(colors[COLOR_MARKS], f); fputs("[]", f); fputs(colors[COLOR_RESET], f); @@ -228,46 +230,46 @@ static int varlink_idl_format_field( switch (field->field_type) { - case VARLINK_BOOL: + case SD_VARLINK_BOOL: fputs(colors[COLOR_FIELD_TYPE], f); fputs("bool", f); fputs(colors[COLOR_RESET], f); break; - case VARLINK_INT: + case SD_VARLINK_INT: fputs(colors[COLOR_FIELD_TYPE], f); fputs("int", f); fputs(colors[COLOR_RESET], f); break; - case VARLINK_FLOAT: + case SD_VARLINK_FLOAT: fputs(colors[COLOR_FIELD_TYPE], f); fputs("float", f); fputs(colors[COLOR_RESET], f); break; - case VARLINK_STRING: + case SD_VARLINK_STRING: fputs(colors[COLOR_FIELD_TYPE], f); fputs("string", f); fputs(colors[COLOR_RESET], f); break; - case VARLINK_OBJECT: + case SD_VARLINK_OBJECT: fputs(colors[COLOR_FIELD_TYPE], f); fputs("object", f); fputs(colors[COLOR_RESET], f); break; - case VARLINK_NAMED_TYPE: + case SD_VARLINK_NAMED_TYPE: fputs(colors[COLOR_IDENTIFIER], f); fputs(ASSERT_PTR(field->named_type), f); fputs(colors[COLOR_RESET], f); break; - case VARLINK_STRUCT: - return varlink_idl_format_all_fields(f, ASSERT_PTR(field->symbol), VARLINK_REGULAR, indent, colors, cols); + case SD_VARLINK_STRUCT: + return varlink_idl_format_all_fields(f, ASSERT_PTR(field->symbol), SD_VARLINK_REGULAR, indent, colors, cols); - case VARLINK_ENUM: + case SD_VARLINK_ENUM: return varlink_idl_format_enum_values(f, ASSERT_PTR(field->symbol), indent, colors, cols); default: @@ -279,8 +281,8 @@ static int varlink_idl_format_field( static int varlink_idl_format_all_fields( FILE *f, - const VarlinkSymbol *symbol, - VarlinkFieldDirection filter_direction, + const sd_varlink_symbol *symbol, + sd_varlink_field_direction_t filter_direction, const char *indent, const char *const colors[static _COLOR_MAX], size_t cols) { @@ -291,15 +293,15 @@ static int varlink_idl_format_all_fields( assert(f); assert(symbol); - assert(IN_SET(symbol->symbol_type, VARLINK_STRUCT_TYPE, VARLINK_METHOD, VARLINK_ERROR)); + assert(IN_SET(symbol->symbol_type, SD_VARLINK_STRUCT_TYPE, SD_VARLINK_METHOD, SD_VARLINK_ERROR)); indent2 = strjoin(strempty(indent), "\t"); if (!indent2) return -ENOMEM; - for (const VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { + for (const sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { - if (field->field_type == _VARLINK_FIELD_COMMENT) /* skip comments at first */ + if (field->field_type == _SD_VARLINK_FIELD_COMMENT) /* skip comments at first */ continue; if (field->field_direction != filter_direction) @@ -314,7 +316,7 @@ static int varlink_idl_format_all_fields( /* We found a field we want to output. In this case, start by outputting all immediately * preceding comments. For that find the first comment in the series before the field, so * that we can start printing from there. */ - const VarlinkField *start_comment = varlink_idl_symbol_find_start_comment(symbol, field); + const sd_varlink_field *start_comment = varlink_idl_symbol_find_start_comment(symbol, field); if (start_comment) { r = varlink_idl_format_comment_fields(f, start_comment, field - start_comment, indent2, colors, cols); @@ -340,7 +342,7 @@ static int varlink_idl_format_all_fields( static int varlink_idl_format_symbol( FILE *f, - const VarlinkSymbol *symbol, + const sd_varlink_symbol *symbol, const char *const colors[static _COLOR_MAX], size_t cols) { int r; @@ -350,7 +352,7 @@ static int varlink_idl_format_symbol( switch (symbol->symbol_type) { - case VARLINK_ENUM_TYPE: + case SD_VARLINK_ENUM_TYPE: fputs(colors[COLOR_SYMBOL_TYPE], f); fputs("type ", f); fputs(colors[COLOR_IDENTIFIER], f); @@ -360,24 +362,24 @@ static int varlink_idl_format_symbol( r = varlink_idl_format_enum_values(f, symbol, /* indent= */ NULL, colors, cols); break; - case VARLINK_STRUCT_TYPE: + case SD_VARLINK_STRUCT_TYPE: fputs(colors[COLOR_SYMBOL_TYPE], f); fputs("type ", f); fputs(colors[COLOR_IDENTIFIER], f); fputs(symbol->name, f); fputs(colors[COLOR_RESET], f); - r = varlink_idl_format_all_fields(f, symbol, VARLINK_REGULAR, /* indent= */ NULL, colors, cols); + r = varlink_idl_format_all_fields(f, symbol, SD_VARLINK_REGULAR, /* indent= */ NULL, colors, cols); break; - case VARLINK_METHOD: + case SD_VARLINK_METHOD: fputs(colors[COLOR_SYMBOL_TYPE], f); fputs("method ", f); fputs(colors[COLOR_IDENTIFIER], f); fputs(symbol->name, f); fputs(colors[COLOR_RESET], f); - r = varlink_idl_format_all_fields(f, symbol, VARLINK_INPUT, /* indent= */ NULL, colors, cols); + r = varlink_idl_format_all_fields(f, symbol, SD_VARLINK_INPUT, /* indent= */ NULL, colors, cols); if (r < 0) return r; @@ -385,17 +387,17 @@ static int varlink_idl_format_symbol( fputs(" -> ", f); fputs(colors[COLOR_RESET], f); - r = varlink_idl_format_all_fields(f, symbol, VARLINK_OUTPUT, /* indent= */ NULL, colors, cols); + r = varlink_idl_format_all_fields(f, symbol, SD_VARLINK_OUTPUT, /* indent= */ NULL, colors, cols); break; - case VARLINK_ERROR: + case SD_VARLINK_ERROR: fputs(colors[COLOR_SYMBOL_TYPE], f); fputs("error ", f); fputs(colors[COLOR_IDENTIFIER], f); fputs(symbol->name, f); fputs(colors[COLOR_RESET], f); - r = varlink_idl_format_all_fields(f, symbol, VARLINK_REGULAR, /* indent= */ NULL, colors, cols); + r = varlink_idl_format_all_fields(f, symbol, SD_VARLINK_REGULAR, /* indent= */ NULL, colors, cols); break; default: @@ -410,8 +412,8 @@ static int varlink_idl_format_symbol( static int varlink_idl_format_all_symbols( FILE *f, - const VarlinkInterface *interface, - VarlinkSymbolType filter_type, + const sd_varlink_interface *interface, + sd_varlink_symbol_type_t filter_type, const char *const colors[static _COLOR_MAX], size_t cols) { @@ -420,12 +422,12 @@ static int varlink_idl_format_all_symbols( assert(f); assert(interface); - for (const VarlinkSymbol *const*symbol = interface->symbols; *symbol; symbol++) { + for (const sd_varlink_symbol *const*symbol = interface->symbols; *symbol; symbol++) { if ((*symbol)->symbol_type != filter_type) continue; - if ((*symbol)->symbol_type == _VARLINK_INTERFACE_COMMENT) { + if ((*symbol)->symbol_type == _SD_VARLINK_INTERFACE_COMMENT) { /* Interface comments we'll output directly. */ r = varlink_idl_format_comment(f, ASSERT_PTR((*symbol)->name), /* indent= */ NULL, colors, cols); if (r < 0) @@ -438,11 +440,11 @@ static int varlink_idl_format_all_symbols( /* Symbol comments we'll only output if we are outputting the symbol they belong to. Scan * backwards for symbol comments. */ - const VarlinkSymbol *const*start_comment = NULL; - for (const VarlinkSymbol *const*c1 = symbol; c1 > interface->symbols; c1--) { - const VarlinkSymbol *const *c0 = c1 - 1; + const sd_varlink_symbol *const*start_comment = NULL; + for (const sd_varlink_symbol *const*c1 = symbol; c1 > interface->symbols; c1--) { + const sd_varlink_symbol *const *c0 = c1 - 1; - if ((*c0)->symbol_type != _VARLINK_SYMBOL_COMMENT) + if ((*c0)->symbol_type != _SD_VARLINK_SYMBOL_COMMENT) break; start_comment = c0; @@ -450,7 +452,7 @@ static int varlink_idl_format_all_symbols( /* Found one or more comments, output them now */ if (start_comment) - for (const VarlinkSymbol *const*c = start_comment; c < symbol; c++) { + for (const sd_varlink_symbol *const*c = start_comment; c < symbol; c++) { r = varlink_idl_format_comment(f, ASSERT_PTR((*c)->name), /* indent= */ NULL, colors, cols); if (r < 0) return r; @@ -464,7 +466,7 @@ static int varlink_idl_format_all_symbols( return 0; } -int varlink_idl_dump(FILE *f, int use_colors, size_t cols, const VarlinkInterface *interface) { +_public_ int sd_varlink_idl_dump(FILE *f, const sd_varlink_interface *interface, sd_varlink_idl_format_flags_t flags, size_t cols) { static const char* const color_table[_COLOR_MAX] = { [COLOR_SYMBOL_TYPE] = ANSI_HIGHLIGHT_GREEN, [COLOR_FIELD_TYPE] = ANSI_HIGHLIGHT_BLUE, @@ -485,13 +487,13 @@ int varlink_idl_dump(FILE *f, int use_colors, size_t cols, const VarlinkInterfac if (!f) f = stdout; - if (use_colors < 0) - use_colors = colors_enabled(); + bool use_colors = FLAGS_SET(flags, SD_VARLINK_IDL_FORMAT_COLOR) || + (FLAGS_SET(flags, SD_VARLINK_IDL_FORMAT_COLOR_AUTO) && colors_enabled()); const char *const *colors = use_colors ? color_table : color_off; /* First output interface comments */ - r = varlink_idl_format_all_symbols(f, interface, _VARLINK_INTERFACE_COMMENT, colors, cols); + r = varlink_idl_format_all_symbols(f, interface, _SD_VARLINK_INTERFACE_COMMENT, colors, cols); if (r < 0) return r; @@ -503,11 +505,11 @@ int varlink_idl_dump(FILE *f, int use_colors, size_t cols, const VarlinkInterfac fputs("\n", f); /* Then output all symbols, ordered by symbol type */ - for (VarlinkSymbolType t = 0; t < _VARLINK_SYMBOL_TYPE_MAX; t++) { + for (sd_varlink_symbol_type_t t = 0; t < _SD_VARLINK_SYMBOL_TYPE_MAX; t++) { /* Interface comments we already have output above. Symbol comments are output when the * symbol they belong to are output, hence filter both here. */ - if (IN_SET(t, _VARLINK_SYMBOL_COMMENT, _VARLINK_INTERFACE_COMMENT)) + if (IN_SET(t, _SD_VARLINK_SYMBOL_COMMENT, _SD_VARLINK_INTERFACE_COMMENT)) continue; r = varlink_idl_format_all_symbols(f, interface, t, colors, cols); @@ -518,21 +520,25 @@ int varlink_idl_dump(FILE *f, int use_colors, size_t cols, const VarlinkInterfac return 0; } -int varlink_idl_format_full(const VarlinkInterface *interface, size_t cols, char **ret) { +_public_ int sd_varlink_idl_format_full(const sd_varlink_interface *interface, sd_varlink_idl_format_flags_t flags, size_t cols, char **ret) { _cleanup_(memstream_done) MemStream memstream = {}; int r; if (!memstream_init(&memstream)) return -errno; - r = varlink_idl_dump(memstream.f, /* use_colors= */ false, cols, interface); + r = sd_varlink_idl_dump(memstream.f, interface, flags, cols); if (r < 0) return r; return memstream_finalize(&memstream, ret, NULL); } -static VarlinkSymbol *varlink_symbol_free(VarlinkSymbol *symbol) { +_public_ int sd_varlink_idl_format(const sd_varlink_interface *interface, char **ret) { + return sd_varlink_idl_format_full(interface, 0, SIZE_MAX, ret); +} + +static sd_varlink_symbol *varlink_symbol_free(sd_varlink_symbol *symbol) { if (!symbol) return NULL; @@ -540,8 +546,8 @@ static VarlinkSymbol *varlink_symbol_free(VarlinkSymbol *symbol) { free((char*) symbol->name); - for (size_t i = 0; symbol->fields[i].field_type != _VARLINK_FIELD_TYPE_END_MARKER; i++) { - VarlinkField *field = symbol->fields + i; + for (size_t i = 0; symbol->fields[i].field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; i++) { + sd_varlink_field *field = symbol->fields + i; free((void*) field->name); free((void*) field->named_type); @@ -549,14 +555,14 @@ static VarlinkSymbol *varlink_symbol_free(VarlinkSymbol *symbol) { /* The symbol pointer might either point to a named symbol, in which case that symbol is * owned by the interface, or by an anomyous symbol, in which case it is owned by us, and we * need to free it */ - if (field->symbol && field->field_type != VARLINK_NAMED_TYPE) - varlink_symbol_free((VarlinkSymbol*) field->symbol); + if (field->symbol && field->field_type != SD_VARLINK_NAMED_TYPE) + varlink_symbol_free((sd_varlink_symbol*) field->symbol); } return mfree(symbol); } -VarlinkInterface* varlink_interface_free(VarlinkInterface *interface) { +sd_varlink_interface* varlink_interface_free(sd_varlink_interface *interface) { if (!interface) return NULL; @@ -571,25 +577,25 @@ VarlinkInterface* varlink_interface_free(VarlinkInterface *interface) { free((char*) interface->name); for (size_t i = 0; interface->symbols[i]; i++) - varlink_symbol_free((VarlinkSymbol*) interface->symbols[i]); + varlink_symbol_free((sd_varlink_symbol*) interface->symbols[i]); return mfree(interface); } -DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkSymbol*, varlink_symbol_free); +DEFINE_TRIVIAL_CLEANUP_FUNC(sd_varlink_symbol*, varlink_symbol_free); -static int varlink_interface_realloc(VarlinkInterface **interface, size_t n_symbols) { - VarlinkInterface *n; +static int varlink_interface_realloc(sd_varlink_interface **interface, size_t n_symbols) { + sd_varlink_interface *n; assert(interface); n_symbols++; /* Space for trailing NULL end marker symbol */ /* Overflow check */ - if (n_symbols > (SIZE_MAX - offsetof(VarlinkInterface, symbols)) / sizeof(VarlinkSymbol*)) + if (n_symbols > (SIZE_MAX - offsetof(sd_varlink_interface, symbols)) / sizeof(sd_varlink_symbol*)) return -ENOMEM; - n = realloc0(*interface, offsetof(VarlinkInterface, symbols) + sizeof(VarlinkSymbol*) * n_symbols); + n = realloc0(*interface, offsetof(sd_varlink_interface, symbols) + sizeof(sd_varlink_symbol*) * n_symbols); if (!n) return -ENOMEM; @@ -597,18 +603,18 @@ static int varlink_interface_realloc(VarlinkInterface **interface, size_t n_symb return 0; } -static int varlink_symbol_realloc(VarlinkSymbol **symbol, size_t n_fields) { - VarlinkSymbol *n; +static int varlink_symbol_realloc(sd_varlink_symbol **symbol, size_t n_fields) { + sd_varlink_symbol *n; assert(symbol); n_fields++; /* Space for trailing end marker field */ /* Overflow check */ - if (n_fields > (SIZE_MAX - offsetof(VarlinkSymbol, fields)) / sizeof(VarlinkField)) + if (n_fields > (SIZE_MAX - offsetof(sd_varlink_symbol, fields)) / sizeof(sd_varlink_field)) return -ENOMEM; - n = realloc0(*symbol, offsetof(VarlinkSymbol, fields) + sizeof(VarlinkField) * n_fields); + n = realloc0(*symbol, offsetof(sd_varlink_symbol, fields) + sizeof(sd_varlink_field) * n_fields); if (!n) return -ENOMEM; @@ -772,13 +778,13 @@ static int varlink_idl_subparse_whitespace( return 1; } -static int varlink_idl_subparse_struct_or_enum(const char **p, unsigned *line, unsigned *column, VarlinkSymbol **symbol, size_t *n_fields, VarlinkFieldDirection direction, unsigned depth); +static int varlink_idl_subparse_struct_or_enum(const char **p, unsigned *line, unsigned *column, sd_varlink_symbol **symbol, size_t *n_fields, sd_varlink_field_direction_t direction, unsigned depth); static int varlink_idl_subparse_field_type( const char **p, unsigned *line, unsigned *column, - VarlinkField *field, + sd_varlink_field *field, unsigned depth) { size_t l; @@ -794,10 +800,10 @@ static int varlink_idl_subparse_field_type( return r; if (startswith(*p, "?")) { - field->field_flags |= VARLINK_NULLABLE; + field->field_flags |= SD_VARLINK_NULLABLE; l = 1; } else { - field->field_flags &= ~VARLINK_NULLABLE; + field->field_flags &= ~SD_VARLINK_NULLABLE; l = 0; } @@ -806,13 +812,13 @@ static int varlink_idl_subparse_field_type( if (startswith(*p, "[]")) { l = 2; - field->field_flags = (field->field_flags & ~VARLINK_MAP) | VARLINK_ARRAY; + field->field_flags = (field->field_flags & ~SD_VARLINK_MAP) | SD_VARLINK_ARRAY; } else if (startswith(*p, "[string]")) { l = 8; - field->field_flags = (field->field_flags & ~VARLINK_ARRAY) | VARLINK_MAP; + field->field_flags = (field->field_flags & ~SD_VARLINK_ARRAY) | SD_VARLINK_MAP; } else { l = 0; - field->field_flags = field->field_flags & ~(VARLINK_MAP | VARLINK_ARRAY); + field->field_flags = field->field_flags & ~(SD_VARLINK_MAP | SD_VARLINK_ARRAY); } advance_line_column(*p, l, line, column); @@ -820,28 +826,28 @@ static int varlink_idl_subparse_field_type( if (startswith(*p, "bool")) { l = 4; - field->field_type = VARLINK_BOOL; + field->field_type = SD_VARLINK_BOOL; } else if (startswith(*p, "int")) { l = 3; - field->field_type = VARLINK_INT; + field->field_type = SD_VARLINK_INT; } else if (startswith(*p, "float")) { l = 5; - field->field_type = VARLINK_FLOAT; + field->field_type = SD_VARLINK_FLOAT; } else if (startswith(*p, "string")) { l = 6; - field->field_type = VARLINK_STRING; + field->field_type = SD_VARLINK_STRING; } else if (startswith(*p, "object")) { l = 6; - field->field_type = VARLINK_OBJECT; + field->field_type = SD_VARLINK_OBJECT; } else if (**p == '(') { - _cleanup_(varlink_symbol_freep) VarlinkSymbol *symbol = NULL; + _cleanup_(varlink_symbol_freep) sd_varlink_symbol *symbol = NULL; size_t n_fields = 0; r = varlink_symbol_realloc(&symbol, n_fields); if (r < 0) return r; - symbol->symbol_type = _VARLINK_SYMBOL_TYPE_INVALID; + symbol->symbol_type = _SD_VARLINK_SYMBOL_TYPE_INVALID; r = varlink_idl_subparse_struct_or_enum( p, @@ -849,16 +855,16 @@ static int varlink_idl_subparse_field_type( column, &symbol, &n_fields, - VARLINK_REGULAR, + SD_VARLINK_REGULAR, depth + 1); if (r < 0) return r; - if (symbol->symbol_type == VARLINK_STRUCT_TYPE) - field->field_type = VARLINK_STRUCT; + if (symbol->symbol_type == SD_VARLINK_STRUCT_TYPE) + field->field_type = SD_VARLINK_STRUCT; else { - assert(symbol->symbol_type == VARLINK_ENUM_TYPE); - field->field_type = VARLINK_ENUM; + assert(symbol->symbol_type == SD_VARLINK_ENUM_TYPE); + field->field_type = SD_VARLINK_ENUM; } field->symbol = TAKE_PTR(symbol); @@ -873,7 +879,7 @@ static int varlink_idl_subparse_field_type( return varlink_idl_log(SYNTHETIC_ERRNO(EBADMSG), "%u:%u: Premature EOF.", *line, *column); field->named_type = TAKE_PTR(token); - field->field_type = VARLINK_NAMED_TYPE; + field->field_type = SD_VARLINK_NAMED_TYPE; l = 0; } @@ -887,9 +893,9 @@ static int varlink_idl_subparse_struct_or_enum( const char **p, unsigned *line, unsigned *column, - VarlinkSymbol **symbol, + sd_varlink_symbol **symbol, size_t *n_fields, - VarlinkFieldDirection direction, + sd_varlink_field_direction_t direction, unsigned depth) { enum { @@ -956,10 +962,10 @@ static int varlink_idl_subparse_struct_or_enum( if (r < 0) return r; - VarlinkField *field = (*symbol)->fields + (*n_fields)++; - *field = (VarlinkField) { + sd_varlink_field *field = (*symbol)->fields + (*n_fields)++; + *field = (sd_varlink_field) { .name = TAKE_PTR(comment), - .field_type = _VARLINK_FIELD_COMMENT, + .field_type = _SD_VARLINK_FIELD_COMMENT, }; } else if (streq(token, ")")) state = STATE_DONE; @@ -979,11 +985,11 @@ static int varlink_idl_subparse_struct_or_enum( return varlink_idl_log(SYNTHETIC_ERRNO(EBADMSG), "%u:%u: Premature EOF.", *line, *column); if (streq(token, ":")) { - VarlinkField *field; + sd_varlink_field *field; if ((*symbol)->symbol_type < 0) - (*symbol)->symbol_type = VARLINK_STRUCT_TYPE; - if ((*symbol)->symbol_type == VARLINK_ENUM_TYPE) + (*symbol)->symbol_type = SD_VARLINK_STRUCT_TYPE; + if ((*symbol)->symbol_type == SD_VARLINK_ENUM_TYPE) return varlink_idl_log(SYNTHETIC_ERRNO(EBADMSG), "%u:%u: Enum with struct fields, refusing.", *line, *column); r = varlink_symbol_realloc(symbol, *n_fields + 1); @@ -991,9 +997,9 @@ static int varlink_idl_subparse_struct_or_enum( return r; field = (*symbol)->fields + (*n_fields)++; - *field = (VarlinkField) { + *field = (sd_varlink_field) { .name = TAKE_PTR(field_name), - .field_type = _VARLINK_FIELD_TYPE_INVALID, + .field_type = _SD_VARLINK_FIELD_TYPE_INVALID, .field_direction = direction, }; @@ -1006,11 +1012,11 @@ static int varlink_idl_subparse_struct_or_enum( allowed_chars = NULL; } else if (STR_IN_SET(token, ",", ")")) { - VarlinkField *field; + sd_varlink_field *field; if ((*symbol)->symbol_type < 0) - (*symbol)->symbol_type = VARLINK_ENUM_TYPE; - if ((*symbol)->symbol_type != VARLINK_ENUM_TYPE) + (*symbol)->symbol_type = SD_VARLINK_ENUM_TYPE; + if ((*symbol)->symbol_type != SD_VARLINK_ENUM_TYPE) return varlink_idl_log(SYNTHETIC_ERRNO(EBADMSG), "%u:%u: Struct with enum fields, refusing.", *line, *column); r = varlink_symbol_realloc(symbol, *n_fields + 1); @@ -1018,9 +1024,9 @@ static int varlink_idl_subparse_struct_or_enum( return r; field = (*symbol)->fields + (*n_fields)++; - *field = (VarlinkField) { + *field = (sd_varlink_field) { .name = TAKE_PTR(field_name), - .field_type = VARLINK_ENUM_VALUE, + .field_type = SD_VARLINK_ENUM_VALUE, }; if (streq(token, ",")) { @@ -1064,14 +1070,14 @@ static int varlink_idl_subparse_struct_or_enum( return 0; } -static int varlink_idl_resolve_symbol_types(VarlinkInterface *interface, VarlinkSymbol *symbol) { +static int varlink_idl_resolve_symbol_types(sd_varlink_interface *interface, sd_varlink_symbol *symbol) { assert(interface); assert(symbol); - for (VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { - const VarlinkSymbol *found; + for (sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { + const sd_varlink_symbol *found; - if (field->field_type != VARLINK_NAMED_TYPE) + if (field->field_type != SD_VARLINK_NAMED_TYPE) continue; if (field->symbol) /* Already resolved */ @@ -1080,11 +1086,11 @@ static int varlink_idl_resolve_symbol_types(VarlinkInterface *interface, Varlink if (!field->named_type) return varlink_idl_log(SYNTHETIC_ERRNO(ENETUNREACH), "Named type field lacking a type name."); - found = varlink_idl_find_symbol(interface, _VARLINK_SYMBOL_TYPE_INVALID, field->named_type); + found = varlink_idl_find_symbol(interface, _SD_VARLINK_SYMBOL_TYPE_INVALID, field->named_type); if (!found) return varlink_idl_log(SYNTHETIC_ERRNO(ENETUNREACH), "Failed to find type '%s'.", field->named_type); - if (!IN_SET(found->symbol_type, VARLINK_STRUCT_TYPE, VARLINK_ENUM_TYPE)) + if (!IN_SET(found->symbol_type, SD_VARLINK_STRUCT_TYPE, SD_VARLINK_ENUM_TYPE)) return varlink_idl_log(SYNTHETIC_ERRNO(ENETUNREACH), "Symbol '%s' is referenced as type but is not a type.", field->named_type); field->symbol = found; @@ -1093,12 +1099,12 @@ static int varlink_idl_resolve_symbol_types(VarlinkInterface *interface, Varlink return 0; } -static int varlink_idl_resolve_types(VarlinkInterface *interface) { +static int varlink_idl_resolve_types(sd_varlink_interface *interface) { int r; assert(interface); - for (VarlinkSymbol **symbol = (VarlinkSymbol**) interface->symbols; *symbol; symbol++) { + for (sd_varlink_symbol **symbol = (sd_varlink_symbol**) interface->symbols; *symbol; symbol++) { r = varlink_idl_resolve_symbol_types(interface, *symbol); if (r < 0) return r; @@ -1111,10 +1117,10 @@ int varlink_idl_parse( const char *text, unsigned *line, unsigned *column, - VarlinkInterface **ret) { + sd_varlink_interface **ret) { - _cleanup_(varlink_interface_freep) VarlinkInterface *interface = NULL; - _cleanup_(varlink_symbol_freep) VarlinkSymbol *symbol = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *interface = NULL; + _cleanup_(varlink_symbol_freep) sd_varlink_symbol *symbol = NULL; enum { STATE_PRE_INTERFACE, STATE_INTERFACE, @@ -1172,7 +1178,7 @@ int varlink_idl_parse( if (r < 0) return r; - symbol->symbol_type = _VARLINK_INTERFACE_COMMENT; + symbol->symbol_type = _SD_VARLINK_INTERFACE_COMMENT; symbol->name = TAKE_PTR(comment); interface->symbols[n_symbols++] = TAKE_PTR(symbol); @@ -1222,7 +1228,7 @@ int varlink_idl_parse( if (r < 0) return r; - symbol->symbol_type = _VARLINK_SYMBOL_COMMENT; + symbol->symbol_type = _SD_VARLINK_SYMBOL_COMMENT; symbol->name = TAKE_PTR(comment); interface->symbols[n_symbols++] = TAKE_PTR(symbol); @@ -1251,10 +1257,10 @@ int varlink_idl_parse( if (r < 0) return r; - symbol->symbol_type = VARLINK_METHOD; + symbol->symbol_type = SD_VARLINK_METHOD; symbol->name = TAKE_PTR(token); - r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, VARLINK_INPUT, 0); + r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, SD_VARLINK_INPUT, 0); if (r < 0) return r; @@ -1271,7 +1277,7 @@ int varlink_idl_parse( if (!streq(token, "->")) return varlink_idl_log(SYNTHETIC_ERRNO(EBADMSG), "%u:%u: Unexpected token '%s'.", *line, *column, token); - r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, VARLINK_OUTPUT, 0); + r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, SD_VARLINK_OUTPUT, 0); if (r < 0) return r; @@ -1296,10 +1302,10 @@ int varlink_idl_parse( if (r < 0) return r; - symbol->symbol_type = _VARLINK_SYMBOL_TYPE_INVALID; /* don't know yet if enum or struct, will be field in by varlink_idl_subparse_struct_or_enum() */ + symbol->symbol_type = _SD_VARLINK_SYMBOL_TYPE_INVALID; /* don't know yet if enum or struct, will be field in by varlink_idl_subparse_struct_or_enum() */ symbol->name = TAKE_PTR(token); - r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, VARLINK_REGULAR, 0); + r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, SD_VARLINK_REGULAR, 0); if (r < 0) return r; @@ -1324,10 +1330,10 @@ int varlink_idl_parse( if (r < 0) return r; - symbol->symbol_type = VARLINK_ERROR; + symbol->symbol_type = SD_VARLINK_ERROR; symbol->name = TAKE_PTR(token); - r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, VARLINK_REGULAR, 0); + r = varlink_idl_subparse_struct_or_enum(&text, line, column, &symbol, &n_fields, SD_VARLINK_REGULAR, 0); if (r < 0) return r; @@ -1474,12 +1480,12 @@ int varlink_idl_qualified_symbol_name_is_valid(const char *name) { return varlink_idl_interface_name_is_valid(iface); } -static int varlink_idl_symbol_consistent(const VarlinkInterface *interface, const VarlinkSymbol *symbol, int level); +static int varlink_idl_symbol_consistent(const sd_varlink_interface *interface, const sd_varlink_symbol *symbol, int level); static int varlink_idl_field_consistent( - const VarlinkInterface *interface, - const VarlinkSymbol *symbol, - const VarlinkField *field, + const sd_varlink_interface *interface, + const sd_varlink_symbol *symbol, + const sd_varlink_field *field, int level) { const char *symbol_name; @@ -1492,48 +1498,48 @@ static int varlink_idl_field_consistent( symbol_name = symbol->name ?: "<anonymous>"; - if (field->field_type <= 0 || field->field_type >= _VARLINK_FIELD_TYPE_MAX) + if (field->field_type <= 0 || field->field_type >= _SD_VARLINK_FIELD_TYPE_MAX) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Field type for '%s' in symbol '%s' is not valid, refusing.", field->name, symbol_name); - if (field->field_type == VARLINK_ENUM_VALUE) { + if (field->field_type == SD_VARLINK_ENUM_VALUE) { - if (symbol->symbol_type != VARLINK_ENUM_TYPE) + if (symbol->symbol_type != SD_VARLINK_ENUM_TYPE) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Enum field type for '%s' in non-enum symbol '%s', refusing.", field->name, symbol_name); if (field->field_flags != 0) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Enum field '%s' in symbol '%s' has non-zero flags set, refusing.", field->name, symbol_name); } else { - if (symbol->symbol_type == VARLINK_ENUM_TYPE) + if (symbol->symbol_type == SD_VARLINK_ENUM_TYPE) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Non-enum field type for '%s' in enum symbol '%s', refusing.", field->name, symbol_name); - if (!IN_SET(field->field_flags & ~VARLINK_NULLABLE, 0, VARLINK_ARRAY, VARLINK_MAP)) + if (!IN_SET(field->field_flags & ~SD_VARLINK_NULLABLE, 0, SD_VARLINK_ARRAY, SD_VARLINK_MAP)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Flags of field '%s' in symbol '%s' is invalid, refusing.", field->name, symbol_name); } - if (symbol->symbol_type != VARLINK_METHOD) { - if (field->field_direction != VARLINK_REGULAR) + if (symbol->symbol_type != SD_VARLINK_METHOD) { + if (field->field_direction != SD_VARLINK_REGULAR) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Direction of '%s' in non-method symbol '%s' not regular, refusing.", field->name, symbol_name); } else { - if (!IN_SET(field->field_direction, VARLINK_INPUT, VARLINK_OUTPUT)) + if (!IN_SET(field->field_direction, SD_VARLINK_INPUT, SD_VARLINK_OUTPUT)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Direction of '%s' in method symbol '%s' is not input or output, refusing.", field->name, symbol_name); } if (field->symbol) { - if (!IN_SET(field->field_type, VARLINK_STRUCT, VARLINK_ENUM, VARLINK_NAMED_TYPE)) + if (!IN_SET(field->field_type, SD_VARLINK_STRUCT, SD_VARLINK_ENUM, SD_VARLINK_NAMED_TYPE)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Target symbol for field '%s' in symbol '%s' defined for elemental field, refusing.", field->name, symbol_name); - if (field->field_type == VARLINK_NAMED_TYPE) { - const VarlinkSymbol *found; + if (field->field_type == SD_VARLINK_NAMED_TYPE) { + const sd_varlink_symbol *found; if (!field->symbol->name || !field->named_type || !streq(field->symbol->name, field->named_type)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Resolved symbol name and named type of field '%s' in symbol '%s' do not match, refusing.", field->name, symbol_name); /* If this is a named type, then check if it's properly part of the interface */ - found = varlink_idl_find_symbol(interface, _VARLINK_SYMBOL_TYPE_INVALID, field->symbol->name); + found = varlink_idl_find_symbol(interface, _SD_VARLINK_SYMBOL_TYPE_INVALID, field->symbol->name); if (!found) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Resolved symbol of named type of field '%s' in symbol '%s' is not part of the interface, refusing.", field->name, symbol_name); - if (!IN_SET(found->symbol_type, VARLINK_ENUM_TYPE, VARLINK_STRUCT_TYPE)) + if (!IN_SET(found->symbol_type, SD_VARLINK_ENUM_TYPE, SD_VARLINK_STRUCT_TYPE)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Resolved symbol of named type of field '%s' in symbol '%s' is not a type, refusing.", field->name, symbol_name); } else { /* If this is an anonymous type, then we recursively check if it's consistent, since @@ -1545,7 +1551,7 @@ static int varlink_idl_field_consistent( } } else { - if (IN_SET(field->field_type, VARLINK_STRUCT, VARLINK_ENUM, VARLINK_NAMED_TYPE)) + if (IN_SET(field->field_type, SD_VARLINK_STRUCT, SD_VARLINK_ENUM, SD_VARLINK_NAMED_TYPE)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "No target symbol for field '%s' in symbol '%s' defined for elemental field, refusing.", field->name, symbol_name); if (field->named_type) @@ -1553,28 +1559,28 @@ static int varlink_idl_field_consistent( } if (field->named_type) { - if (field->field_type != VARLINK_NAMED_TYPE) + if (field->field_type != SD_VARLINK_NAMED_TYPE) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Named type set for field '%s' in symbol '%s' but not a named type field, refusing.", field->name, symbol_name); } else { - if (field->field_type == VARLINK_NAMED_TYPE) + if (field->field_type == SD_VARLINK_NAMED_TYPE) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "No named type set for field '%s' in symbol '%s' but field is a named type field, refusing.", field->name, symbol_name); } return 0; } -static bool varlink_symbol_is_empty(const VarlinkSymbol *symbol) { +static bool varlink_symbol_is_empty(const sd_varlink_symbol *symbol) { assert(symbol); - if (IN_SET(symbol->symbol_type, _VARLINK_SYMBOL_COMMENT, _VARLINK_INTERFACE_COMMENT)) + if (IN_SET(symbol->symbol_type, _SD_VARLINK_SYMBOL_COMMENT, _SD_VARLINK_INTERFACE_COMMENT)) return true; - return symbol->fields[0].field_type == _VARLINK_FIELD_TYPE_END_MARKER; + return symbol->fields[0].field_type == _SD_VARLINK_FIELD_TYPE_END_MARKER; } static int varlink_idl_symbol_consistent( - const VarlinkInterface *interface, - const VarlinkSymbol *symbol, + const sd_varlink_interface *interface, + const sd_varlink_symbol *symbol, int level) { _cleanup_(set_freep) Set *input_set = NULL, *output_set = NULL; @@ -1586,25 +1592,25 @@ static int varlink_idl_symbol_consistent( symbol_name = symbol->name ?: "<anonymous>"; - if (symbol->symbol_type < 0 || symbol->symbol_type >= _VARLINK_SYMBOL_TYPE_MAX) + if (symbol->symbol_type < 0 || symbol->symbol_type >= _SD_VARLINK_SYMBOL_TYPE_MAX) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Symbol type for '%s' is not valid, refusing.", symbol_name); - if (IN_SET(symbol->symbol_type, VARLINK_STRUCT_TYPE, VARLINK_ENUM_TYPE) && varlink_symbol_is_empty(symbol)) + if (IN_SET(symbol->symbol_type, SD_VARLINK_STRUCT_TYPE, SD_VARLINK_ENUM_TYPE) && varlink_symbol_is_empty(symbol)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Symbol '%s' is empty, refusing.", symbol_name); - if (IN_SET(symbol->symbol_type, _VARLINK_SYMBOL_COMMENT, _VARLINK_INTERFACE_COMMENT)) + if (IN_SET(symbol->symbol_type, _SD_VARLINK_SYMBOL_COMMENT, _SD_VARLINK_INTERFACE_COMMENT)) return 0; - for (const VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { + for (const sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { - if (field->field_type == _VARLINK_FIELD_COMMENT) { + if (field->field_type == _SD_VARLINK_FIELD_COMMENT) { if (!varlink_idl_comment_is_valid(field->name)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Comment in symbol '%s' not valid, refusing.", symbol_name); continue; } - Set **name_set = field->field_direction == VARLINK_OUTPUT ? &output_set : &input_set; /* for the method case we need two separate sets, otherwise we use the same */ + Set **name_set = field->field_direction == SD_VARLINK_OUTPUT ? &output_set : &input_set; /* for the method case we need two separate sets, otherwise we use the same */ if (!varlink_idl_field_name_is_valid(field->name)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Field name '%s' in symbol '%s' not valid, refusing.", field->name, symbol_name); @@ -1623,7 +1629,7 @@ static int varlink_idl_symbol_consistent( return 0; } -int varlink_idl_consistent(const VarlinkInterface *interface, int level) { +int varlink_idl_consistent(const sd_varlink_interface *interface, int level) { _cleanup_(set_freep) Set *name_set = NULL; int r; @@ -1632,9 +1638,9 @@ int varlink_idl_consistent(const VarlinkInterface *interface, int level) { if (!varlink_idl_interface_name_is_valid(interface->name)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Interface name '%s' is not valid, refusing.", interface->name); - for (const VarlinkSymbol *const *symbol = interface->symbols; *symbol; symbol++) { + for (const sd_varlink_symbol *const *symbol = interface->symbols; *symbol; symbol++) { - if (IN_SET((*symbol)->symbol_type, _VARLINK_SYMBOL_COMMENT, _VARLINK_INTERFACE_COMMENT)) { + if (IN_SET((*symbol)->symbol_type, _SD_VARLINK_SYMBOL_COMMENT, _SD_VARLINK_INTERFACE_COMMENT)) { if (!varlink_idl_comment_is_valid((*symbol)->name)) return varlink_idl_log_full(level, SYNTHETIC_ERRNO(EUCLEAN), "Comment in interface '%s' not valid, refusing.", interface->name); continue; @@ -1657,50 +1663,50 @@ int varlink_idl_consistent(const VarlinkInterface *interface, int level) { return 0; } -static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_variant *v, VarlinkFieldDirection direction, const char **bad_field); +static int varlink_idl_validate_symbol(const sd_varlink_symbol *symbol, sd_json_variant *v, sd_varlink_field_direction_t direction, const char **bad_field); -static int varlink_idl_validate_field_element_type(const VarlinkField *field, sd_json_variant *v) { +static int varlink_idl_validate_field_element_type(const sd_varlink_field *field, sd_json_variant *v) { assert(field); switch (field->field_type) { - case VARLINK_STRUCT: - case VARLINK_ENUM: - case VARLINK_NAMED_TYPE: - return varlink_idl_validate_symbol(field->symbol, v, VARLINK_REGULAR, NULL); + case SD_VARLINK_STRUCT: + case SD_VARLINK_ENUM: + case SD_VARLINK_NAMED_TYPE: + return varlink_idl_validate_symbol(field->symbol, v, SD_VARLINK_REGULAR, NULL); - case VARLINK_BOOL: + case SD_VARLINK_BOOL: if (!sd_json_variant_is_boolean(v)) return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Field '%s' should be a bool, but it is not, refusing.", strna(field->name)); break; - case VARLINK_INT: + case SD_VARLINK_INT: /* Allow strings here too, since integers with > 53 bits are often passed in as strings */ if (!sd_json_variant_is_integer(v) && !sd_json_variant_is_unsigned(v) && !sd_json_variant_is_string(v)) return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Field '%s' should be an int, but it is not, refusing.", strna(field->name)); break; - case VARLINK_FLOAT: + case SD_VARLINK_FLOAT: if (!sd_json_variant_is_number(v)) return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Field '%s' should be a float, but it is not, refusing.", strna(field->name)); break; - case VARLINK_STRING: + case SD_VARLINK_STRING: if (!sd_json_variant_is_string(v)) return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Field '%s' should be a string, but it is not, refusing.", strna(field->name)); break; - case VARLINK_OBJECT: + case SD_VARLINK_OBJECT: if (!sd_json_variant_is_object(v)) return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Field '%s' should be an object, but it is not, refusing.", strna(field->name)); break; - case _VARLINK_FIELD_COMMENT: + case _SD_VARLINK_FIELD_COMMENT: break; default: @@ -1710,18 +1716,18 @@ static int varlink_idl_validate_field_element_type(const VarlinkField *field, sd return 0; } -static int varlink_idl_validate_field(const VarlinkField *field, sd_json_variant *v) { +static int varlink_idl_validate_field(const sd_varlink_field *field, sd_json_variant *v) { int r; assert(field); - assert(field->field_type != _VARLINK_FIELD_COMMENT); + assert(field->field_type != _SD_VARLINK_FIELD_COMMENT); if (!v || sd_json_variant_is_null(v)) { - if (!FLAGS_SET(field->field_flags, VARLINK_NULLABLE)) + if (!FLAGS_SET(field->field_flags, SD_VARLINK_NULLABLE)) return varlink_idl_log(SYNTHETIC_ERRNO(ENOANO), "Mandatory field '%s' is null or missing on object, refusing.", strna(field->name)); - } else if (FLAGS_SET(field->field_flags, VARLINK_ARRAY)) { + } else if (FLAGS_SET(field->field_flags, SD_VARLINK_ARRAY)) { sd_json_variant *i; if (!sd_json_variant_is_array(v)) @@ -1733,7 +1739,7 @@ static int varlink_idl_validate_field(const VarlinkField *field, sd_json_variant return r; } - } else if (FLAGS_SET(field->field_flags, VARLINK_MAP)) { + } else if (FLAGS_SET(field->field_flags, SD_VARLINK_MAP)) { _unused_ const char *k; sd_json_variant *e; @@ -1754,11 +1760,11 @@ static int varlink_idl_validate_field(const VarlinkField *field, sd_json_variant return 0; } -static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_variant *v, VarlinkFieldDirection direction, const char **bad_field) { +static int varlink_idl_validate_symbol(const sd_varlink_symbol *symbol, sd_json_variant *v, sd_varlink_field_direction_t direction, const char **bad_field) { int r; assert(symbol); - assert(!IN_SET(symbol->symbol_type, _VARLINK_SYMBOL_COMMENT, _VARLINK_INTERFACE_COMMENT)); + assert(!IN_SET(symbol->symbol_type, _SD_VARLINK_SYMBOL_COMMENT, _SD_VARLINK_INTERFACE_COMMENT)); if (!v) { if (bad_field) @@ -1768,7 +1774,7 @@ static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_vari switch (symbol->symbol_type) { - case VARLINK_ENUM_TYPE: { + case SD_VARLINK_ENUM_TYPE: { bool found = false; const char *s; @@ -1780,12 +1786,12 @@ static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_vari assert_se(s = sd_json_variant_string(v)); - for (const VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { + for (const sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { - if (field->field_type == _VARLINK_FIELD_COMMENT) + if (field->field_type == _SD_VARLINK_FIELD_COMMENT) continue; - assert(field->field_type == VARLINK_ENUM_VALUE); + assert(field->field_type == SD_VARLINK_ENUM_VALUE); if (streq_ptr(field->name, s)) { found = true; @@ -1802,18 +1808,18 @@ static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_vari break; } - case VARLINK_STRUCT_TYPE: - case VARLINK_METHOD: - case VARLINK_ERROR: { + case SD_VARLINK_STRUCT_TYPE: + case SD_VARLINK_METHOD: + case SD_VARLINK_ERROR: { if (!sd_json_variant_is_object(v)) { if (bad_field) *bad_field = symbol->name; return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Passed non-object to field '%s', refusing.", strna(symbol->name)); } - for (const VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { + for (const sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { - if (field->field_type == _VARLINK_FIELD_COMMENT) + if (field->field_type == _SD_VARLINK_FIELD_COMMENT) continue; if (field->field_direction != direction) @@ -1840,8 +1846,8 @@ static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_vari break; } - case _VARLINK_SYMBOL_COMMENT: - case _VARLINK_INTERFACE_COMMENT: + case _SD_VARLINK_SYMBOL_COMMENT: + case _SD_VARLINK_INTERFACE_COMMENT: break; default: @@ -1851,47 +1857,47 @@ static int varlink_idl_validate_symbol(const VarlinkSymbol *symbol, sd_json_vari return 1; /* validated */ } -static int varlink_idl_validate_method(const VarlinkSymbol *method, sd_json_variant *v, VarlinkFieldDirection direction, const char **bad_field) { - assert(IN_SET(direction, VARLINK_INPUT, VARLINK_OUTPUT)); +static int varlink_idl_validate_method(const sd_varlink_symbol *method, sd_json_variant *v, sd_varlink_field_direction_t direction, const char **bad_field) { + assert(IN_SET(direction, SD_VARLINK_INPUT, SD_VARLINK_OUTPUT)); if (!method) return 0; /* Can't validate */ - if (method->symbol_type != VARLINK_METHOD) + if (method->symbol_type != SD_VARLINK_METHOD) return -EBADMSG; return varlink_idl_validate_symbol(method, v, direction, bad_field); } -int varlink_idl_validate_method_call(const VarlinkSymbol *method, sd_json_variant *v, const char **bad_field) { - return varlink_idl_validate_method(method, v, VARLINK_INPUT, bad_field); +int varlink_idl_validate_method_call(const sd_varlink_symbol *method, sd_json_variant *v, const char **bad_field) { + return varlink_idl_validate_method(method, v, SD_VARLINK_INPUT, bad_field); } -int varlink_idl_validate_method_reply(const VarlinkSymbol *method, sd_json_variant *v, const char **bad_field) { - return varlink_idl_validate_method(method, v, VARLINK_OUTPUT, bad_field); +int varlink_idl_validate_method_reply(const sd_varlink_symbol *method, sd_json_variant *v, const char **bad_field) { + return varlink_idl_validate_method(method, v, SD_VARLINK_OUTPUT, bad_field); } -int varlink_idl_validate_error(const VarlinkSymbol *error, sd_json_variant *v, const char **bad_field) { +int varlink_idl_validate_error(const sd_varlink_symbol *error, sd_json_variant *v, const char **bad_field) { if (!error) return 0; /* Can't validate */ - if (error->symbol_type != VARLINK_ERROR) + if (error->symbol_type != SD_VARLINK_ERROR) return -EBADMSG; - return varlink_idl_validate_symbol(error, v, VARLINK_REGULAR, bad_field); + return varlink_idl_validate_symbol(error, v, SD_VARLINK_REGULAR, bad_field); } -const VarlinkSymbol* varlink_idl_find_symbol( - const VarlinkInterface *interface, - VarlinkSymbolType type, +const sd_varlink_symbol* varlink_idl_find_symbol( + const sd_varlink_interface *interface, + sd_varlink_symbol_type_t type, const char *name) { assert(interface); - assert(type < _VARLINK_SYMBOL_TYPE_MAX); - assert(!IN_SET(type, _VARLINK_SYMBOL_COMMENT, _VARLINK_INTERFACE_COMMENT)); + assert(type < _SD_VARLINK_SYMBOL_TYPE_MAX); + assert(!IN_SET(type, _SD_VARLINK_SYMBOL_COMMENT, _SD_VARLINK_INTERFACE_COMMENT)); if (isempty(name)) return NULL; - for (const VarlinkSymbol *const*symbol = interface->symbols; *symbol; symbol++) { + for (const sd_varlink_symbol *const*symbol = interface->symbols; *symbol; symbol++) { if (type >= 0 && (*symbol)->symbol_type != type) continue; @@ -1902,8 +1908,8 @@ const VarlinkSymbol* varlink_idl_find_symbol( return NULL; } -const VarlinkField* varlink_idl_find_field( - const VarlinkSymbol *symbol, +const sd_varlink_field* varlink_idl_find_field( + const sd_varlink_symbol *symbol, const char *name) { assert(symbol); @@ -1911,8 +1917,8 @@ const VarlinkField* varlink_idl_find_field( if (isempty(name)) return NULL; - for (const VarlinkField *field = symbol->fields; field->field_type != _VARLINK_FIELD_TYPE_END_MARKER; field++) { - if (field->field_type == _VARLINK_FIELD_COMMENT) + for (const sd_varlink_field *field = symbol->fields; field->field_type != _SD_VARLINK_FIELD_TYPE_END_MARKER; field++) { + if (field->field_type == _SD_VARLINK_FIELD_COMMENT) continue; if (streq_ptr(field->name, name)) diff --git a/src/shared/varlink.c b/src/libsystemd/sd-varlink/sd-varlink.c index 35879e3872..7639f72f89 100644 --- a/src/shared/varlink.c +++ b/src/libsystemd/sd-varlink/sd-varlink.c @@ -3,9 +3,11 @@ #include <malloc.h> #include <poll.h> -#include <sd-daemon.h> +#include "sd-daemon.h" +#include "sd-varlink.h" #include "alloc-util.h" +#include "errno-list.h" #include "errno-util.h" #include "escape.h" #include "fd-util.h" @@ -17,8 +19,6 @@ #include "list.h" #include "path-util.h" #include "process-util.h" -#include "selinux-util.h" -#include "serialize.h" #include "set.h" #include "socket-util.h" #include "string-table.h" @@ -27,7 +27,7 @@ #include "time-util.h" #include "umask-util.h" #include "user-util.h" -#include "varlink.h" +#include "varlink-idl-util.h" #include "varlink-internal.h" #include "varlink-io.systemd.h" #include "varlink-org.varlink.service.h" @@ -41,220 +41,6 @@ #define VARLINK_READ_SIZE (64U*1024U) #define VARLINK_COLLECT_MAX 1024U -typedef enum VarlinkState { - /* Client side states */ - VARLINK_IDLE_CLIENT, - VARLINK_AWAITING_REPLY, - VARLINK_AWAITING_REPLY_MORE, - VARLINK_CALLING, - VARLINK_CALLED, - VARLINK_COLLECTING, - VARLINK_COLLECTING_REPLY, - VARLINK_PROCESSING_REPLY, - - /* Server side states */ - VARLINK_IDLE_SERVER, - VARLINK_PROCESSING_METHOD, - VARLINK_PROCESSING_METHOD_MORE, - VARLINK_PROCESSING_METHOD_ONEWAY, - VARLINK_PROCESSED_METHOD, - VARLINK_PENDING_METHOD, - VARLINK_PENDING_METHOD_MORE, - - /* Common states (only during shutdown) */ - VARLINK_PENDING_DISCONNECT, - VARLINK_PENDING_TIMEOUT, - VARLINK_PROCESSING_DISCONNECT, - VARLINK_PROCESSING_TIMEOUT, - VARLINK_PROCESSING_FAILURE, - VARLINK_DISCONNECTED, - - _VARLINK_STATE_MAX, - _VARLINK_STATE_INVALID = -EINVAL, -} VarlinkState; - -/* Tests whether we are not yet disconnected. Note that this is true during all states where the connection - * is still good for something, and false only when it's dead for good. This means: when we are - * asynchronously connecting to a peer and the connect() is still pending, then this will return 'true', as - * the connection is still good, and we are likely to be able to properly operate on it soon. */ -#define VARLINK_STATE_IS_ALIVE(state) \ - IN_SET(state, \ - VARLINK_IDLE_CLIENT, \ - VARLINK_AWAITING_REPLY, \ - VARLINK_AWAITING_REPLY_MORE, \ - VARLINK_CALLING, \ - VARLINK_CALLED, \ - VARLINK_COLLECTING, \ - VARLINK_COLLECTING_REPLY, \ - VARLINK_PROCESSING_REPLY, \ - VARLINK_IDLE_SERVER, \ - VARLINK_PROCESSING_METHOD, \ - VARLINK_PROCESSING_METHOD_MORE, \ - VARLINK_PROCESSING_METHOD_ONEWAY, \ - VARLINK_PROCESSED_METHOD, \ - VARLINK_PENDING_METHOD, \ - VARLINK_PENDING_METHOD_MORE) - -typedef struct VarlinkJsonQueueItem VarlinkJsonQueueItem; - -/* A queued message we shall write into the socket, along with the file descriptors to send at the same - * time. This queue item binds them together so that message/fd boundaries are maintained throughout the - * whole pipeline. */ -struct VarlinkJsonQueueItem { - LIST_FIELDS(VarlinkJsonQueueItem, queue); - sd_json_variant *data; - size_t n_fds; - int fds[]; -}; - -struct Varlink { - unsigned n_ref; - - VarlinkServer *server; - - VarlinkState state; - bool connecting; /* This boolean indicates whether the socket fd we are operating on is currently - * processing an asynchronous connect(). In that state we watch the socket for - * EPOLLOUT, but we refrain from calling read() or write() on the socket as that - * will trigger ENOTCONN. Note that this boolean is kept separate from the - * VarlinkState above on purpose: while the connect() is still not complete we - * already want to allow queuing of messages and similar. Thus it's nice to keep - * these two state concepts separate: the VarlinkState encodes what our own view of - * the connection is, i.e. whether we think it's a server, a client, and has - * something queued already, while 'connecting' tells us a detail about the - * transport used below, that should have no effect on how we otherwise accept and - * process operations from the user. - * - * Or to say this differently: VARLINK_STATE_IS_ALIVE(state) tells you whether the - * connection is good to use, even if it might not be fully connected - * yet. connecting=true then informs you that actually we are still connecting, and - * the connection is actually not established yet and thus any requests you enqueue - * now will still work fine but will be queued only, not sent yet, but that - * shouldn't stop you from using the connection, since eventually whatever you queue - * *will* be sent. - * - * Or to say this even differently: 'state' is a high-level ("application layer" - * high, if you so will) state, while 'conecting' is a low-level ("transport layer" - * low, if you so will) state, and while they are not entirely unrelated and - * sometimes propagate effects to each other they are only asynchronously connected - * at most. */ - unsigned n_pending; - - int input_fd; - int output_fd; - - char *input_buffer; /* valid data starts at input_buffer_index, ends at input_buffer_index+input_buffer_size */ - size_t input_buffer_index; - size_t input_buffer_size; - size_t input_buffer_unscanned; - - void *input_control_buffer; - size_t input_control_buffer_size; - - char *output_buffer; /* valid data starts at output_buffer_index, ends at output_buffer_index+output_buffer_size */ - size_t output_buffer_index; - size_t output_buffer_size; - - int *input_fds; /* file descriptors associated with the data in input_buffer (for fd passing) */ - size_t n_input_fds; - - int *output_fds; /* file descriptors associated with the data in output_buffer (for fd passing) */ - size_t n_output_fds; - - /* Further messages to output not yet formatted into text, and thus not included in output_buffer - * yet. We keep them separate from output_buffer, to not violate fd message boundaries: we want that - * each fd that is sent is associated with its fds, and that fds cannot be accidentally associated - * with preceding or following messages. */ - LIST_HEAD(VarlinkJsonQueueItem, output_queue); - VarlinkJsonQueueItem *output_queue_tail; - - /* The fds to associate with the next message that is about to be enqueued. The user first pushes the - * fds it intends to send via varlink_push_fd() into this queue, and then once the message data is - * submitted we'll combine the fds and the message data into one. */ - int *pushed_fds; - size_t n_pushed_fds; - - VarlinkReply reply_callback; - - sd_json_variant *current; - sd_json_variant *current_collected; - VarlinkReplyFlags current_reply_flags; - VarlinkSymbol *current_method; - - int peer_pidfd; - struct ucred ucred; - bool ucred_acquired:1; - - bool write_disconnected:1; - bool read_disconnected:1; - bool prefer_read:1; - bool prefer_write:1; - bool got_pollhup:1; - - bool allow_fd_passing_input:1; - bool allow_fd_passing_output:1; - - bool output_buffer_sensitive:1; /* whether to erase the output buffer after writing it to the socket */ - bool input_sensitive:1; /* Whether incoming messages might be sensitive */ - - int af; /* address family if socket; AF_UNSPEC if not socket; negative if not known */ - - usec_t timestamp; - usec_t timeout; - - void *userdata; - char *description; - - sd_event *event; - sd_event_source *input_event_source; - sd_event_source *output_event_source; - sd_event_source *time_event_source; - sd_event_source *quit_event_source; - sd_event_source *defer_event_source; - - pid_t exec_pid; -}; - -typedef struct VarlinkServerSocket VarlinkServerSocket; - -struct VarlinkServerSocket { - VarlinkServer *server; - - int fd; - char *address; - - sd_event_source *event_source; - - LIST_FIELDS(VarlinkServerSocket, sockets); -}; - -struct VarlinkServer { - unsigned n_ref; - VarlinkServerFlags flags; - - LIST_HEAD(VarlinkServerSocket, sockets); - - Hashmap *methods; /* Fully qualified symbol name of a method → VarlinkMethod */ - Hashmap *interfaces; /* Fully qualified interface name → VarlinkInterface* */ - Hashmap *symbols; /* Fully qualified symbol name of method/error → VarlinkSymbol* */ - VarlinkConnect connect_callback; - VarlinkDisconnect disconnect_callback; - - sd_event *event; - int64_t event_priority; - - unsigned n_connections; - Hashmap *by_uid; /* UID_TO_PTR(uid) → UINT_TO_PTR(n_connections) */ - - void *userdata; - char *description; - - unsigned connections_max; - unsigned connections_per_uid_max; - - bool exit_on_idle; -}; - static const char* const varlink_state_table[_VARLINK_STATE_MAX] = { [VARLINK_IDLE_CLIENT] = "idle-client", [VARLINK_AWAITING_REPLY] = "awaiting-reply", @@ -281,28 +67,8 @@ static const char* const varlink_state_table[_VARLINK_STATE_MAX] = { DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(varlink_state, VarlinkState); -#define varlink_log_errno(v, error, fmt, ...) \ - log_debug_errno(error, "%s: " fmt, varlink_description(v), ##__VA_ARGS__) - -#define varlink_log(v, fmt, ...) \ - log_debug("%s: " fmt, varlink_description(v), ##__VA_ARGS__) - -#define varlink_server_log_errno(s, error, fmt, ...) \ - log_debug_errno(error, "%s: " fmt, varlink_server_description(s), ##__VA_ARGS__) - -#define varlink_server_log(s, fmt, ...) \ - log_debug("%s: " fmt, varlink_server_description(s), ##__VA_ARGS__) - -static int varlink_format_queue(Varlink *v); -static void varlink_server_test_exit_on_idle(VarlinkServer *s); - -static const char *varlink_description(Varlink *v) { - return (v ? v->description : NULL) ?: "varlink"; -} - -static const char *varlink_server_description(VarlinkServer *s) { - return (s ? s->description : NULL) ?: "varlink"; -} +static int varlink_format_queue(sd_varlink *v); +static void varlink_server_test_exit_on_idle(sd_varlink_server *s); static VarlinkJsonQueueItem *varlink_json_queue_item_free(VarlinkJsonQueueItem *q) { if (!q) @@ -334,7 +100,7 @@ static VarlinkJsonQueueItem *varlink_json_queue_item_new(sd_json_variant *m, con return TAKE_PTR(q); } -static void varlink_set_state(Varlink *v, VarlinkState state) { +static void varlink_set_state(sd_varlink *v, VarlinkState state) { assert(v); assert(state >= 0 && state < _VARLINK_STATE_MAX); @@ -350,16 +116,16 @@ static void varlink_set_state(Varlink *v, VarlinkState state) { v->state = state; } -static int varlink_new(Varlink **ret) { - Varlink *v; +static int varlink_new(sd_varlink **ret) { + sd_varlink *v; assert(ret); - v = new(Varlink, 1); + v = new(sd_varlink, 1); if (!v) return -ENOMEM; - *v = (Varlink) { + *v = (sd_varlink) { .n_ref = 1, .input_fd = -EBADF, .output_fd = -EBADF, @@ -380,8 +146,8 @@ static int varlink_new(Varlink **ret) { return 0; } -int varlink_connect_address(Varlink **ret, const char *address) { - _cleanup_(varlink_unrefp) Varlink *v = NULL; +_public_ int sd_varlink_connect_address(sd_varlink **ret, const char *address) { + _cleanup_(sd_varlink_unrefp) sd_varlink *v = NULL; union sockaddr_union sockaddr; int r; @@ -432,7 +198,7 @@ int varlink_connect_address(Varlink **ret, const char *address) { return 0; } -int varlink_connect_exec(Varlink **ret, const char *_command, char **_argv) { +_public_ int sd_varlink_connect_exec(sd_varlink **ret, const char *_command, char **_argv) { _cleanup_close_pair_ int pair[2] = EBADF_PAIR; _cleanup_(sigkill_waitp) pid_t pid = 0; _cleanup_free_ char *command = NULL; @@ -507,7 +273,7 @@ int varlink_connect_exec(Varlink **ret, const char *_command, char **_argv) { pair[1] = safe_close(pair[1]); - Varlink *v; + sd_varlink *v; r = varlink_new(&v); if (r < 0) return log_debug_errno(r, "Failed to create varlink object: %m"); @@ -532,7 +298,7 @@ static int ssh_path(const char **ret) { return 0; } -static int varlink_connect_ssh_unix(Varlink **ret, const char *where) { +static int varlink_connect_ssh_unix(sd_varlink **ret, const char *where) { _cleanup_close_pair_ int pair[2] = EBADF_PAIR; _cleanup_(sigkill_waitp) pid_t pid = 0; int r; @@ -595,7 +361,7 @@ static int varlink_connect_ssh_unix(Varlink **ret, const char *where) { pair[1] = safe_close(pair[1]); - Varlink *v; + sd_varlink *v; r = varlink_new(&v); if (r < 0) return log_debug_errno(r, "Failed to create varlink object: %m"); @@ -609,7 +375,7 @@ static int varlink_connect_ssh_unix(Varlink **ret, const char *where) { return 0; } -static int varlink_connect_ssh_exec(Varlink **ret, const char *where) { +static int varlink_connect_ssh_exec(sd_varlink **ret, const char *where) { _cleanup_close_pair_ int input_pipe[2] = EBADF_PAIR, output_pipe[2] = EBADF_PAIR; _cleanup_(sigkill_waitp) pid_t pid = 0; int r; @@ -687,7 +453,7 @@ static int varlink_connect_ssh_exec(Varlink **ret, const char *where) { if (r < 0) return log_debug_errno(r, "Failed to make output pipe non-blocking: %m"); - Varlink *v; + sd_varlink *v; r = varlink_new(&v); if (r < 0) return log_debug_errno(r, "Failed to create varlink object: %m"); @@ -702,7 +468,7 @@ static int varlink_connect_ssh_exec(Varlink **ret, const char *where) { return 0; } -int varlink_connect_url(Varlink **ret, const char *url) { +_public_ int sd_varlink_connect_url(sd_varlink **ret, const char *url) { _cleanup_free_ char *c = NULL; const char *p; enum { @@ -758,13 +524,13 @@ int varlink_connect_url(Varlink **ret, const char *url) { } if (scheme == SCHEME_EXEC) - return varlink_connect_exec(ret, c, NULL); + return sd_varlink_connect_exec(ret, c, NULL); - return varlink_connect_address(ret, c ?: p); + return sd_varlink_connect_address(ret, c ?: p); } -int varlink_connect_fd_pair(Varlink **ret, int input_fd, int output_fd, const struct ucred *override_ucred) { - Varlink *v; +_public_ int sd_varlink_connect_fd_pair(sd_varlink **ret, int input_fd, int output_fd, const struct ucred *override_ucred) { + sd_varlink *v; int r; assert_return(ret, -EINVAL); @@ -807,11 +573,11 @@ int varlink_connect_fd_pair(Varlink **ret, int input_fd, int output_fd, const st return 0; } -int varlink_connect_fd(Varlink **ret, int fd) { - return varlink_connect_fd_pair(ret, fd, fd, /* override_ucred= */ NULL); +_public_ int sd_varlink_connect_fd(sd_varlink **ret, int fd) { + return sd_varlink_connect_fd_pair(ret, fd, fd, /* override_ucred= */ NULL); } -static void varlink_detach_event_sources(Varlink *v) { +static void varlink_detach_event_sources(sd_varlink *v) { assert(v); v->input_event_source = sd_event_source_disable_unref(v->input_event_source); @@ -821,7 +587,7 @@ static void varlink_detach_event_sources(Varlink *v) { v->defer_event_source = sd_event_source_disable_unref(v->defer_event_source); } -static void varlink_clear_current(Varlink *v) { +static void varlink_clear_current(sd_varlink *v) { assert(v); /* Clears the currently processed incoming message */ @@ -835,7 +601,7 @@ static void varlink_clear_current(Varlink *v) { v->n_input_fds = 0; } -static void varlink_clear(Varlink *v) { +static void varlink_clear(sd_varlink *v) { assert(v); varlink_detach_event_sources(v); @@ -875,7 +641,7 @@ static void varlink_clear(Varlink *v) { v->peer_pidfd = safe_close(v->peer_pidfd); } -static Varlink* varlink_destroy(Varlink *v) { +static sd_varlink* varlink_destroy(sd_varlink *v) { if (!v) return NULL; @@ -889,9 +655,9 @@ static Varlink* varlink_destroy(Varlink *v) { return mfree(v); } -DEFINE_TRIVIAL_REF_UNREF_FUNC(Varlink, varlink, varlink_destroy); +DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_varlink, sd_varlink, varlink_destroy); -static int varlink_test_disconnect(Varlink *v) { +static int varlink_test_disconnect(sd_varlink *v) { assert(v); /* Tests whether we the connection has been terminated. We are careful to not stop processing it @@ -937,7 +703,7 @@ disconnect: return 1; } -static int varlink_write(Varlink *v) { +static int varlink_write(sd_varlink *v) { ssize_t n; int r; @@ -1029,7 +795,7 @@ static int varlink_write(Varlink *v) { #define VARLINK_FDS_MAX (16U*1024U) -static int varlink_read(Varlink *v) { +static int varlink_read(sd_varlink *v) { struct iovec iov; struct msghdr mh; size_t rs; @@ -1166,7 +932,7 @@ static int varlink_read(Varlink *v) { return 1; } -static int varlink_parse_message(Varlink *v) { +static int varlink_parse_message(sd_varlink *v) { const char *e; char *begin; size_t sz; @@ -1231,7 +997,7 @@ static int varlink_parse_message(Varlink *v) { return 1; } -static int varlink_test_timeout(Varlink *v) { +static int varlink_test_timeout(sd_varlink *v) { assert(v); if (!IN_SET(v->state, VARLINK_AWAITING_REPLY, VARLINK_AWAITING_REPLY_MORE, VARLINK_CALLING, VARLINK_COLLECTING)) @@ -1247,7 +1013,7 @@ static int varlink_test_timeout(Varlink *v) { return 1; } -static int varlink_dispatch_local_error(Varlink *v, const char *error) { +static int varlink_dispatch_local_error(sd_varlink *v, const char *error) { int r; assert(v); @@ -1256,35 +1022,35 @@ static int varlink_dispatch_local_error(Varlink *v, const char *error) { if (!v->reply_callback) return 0; - r = v->reply_callback(v, NULL, error, VARLINK_REPLY_ERROR|VARLINK_REPLY_LOCAL, v->userdata); + r = v->reply_callback(v, NULL, error, SD_VARLINK_REPLY_ERROR|SD_VARLINK_REPLY_LOCAL, v->userdata); if (r < 0) varlink_log_errno(v, r, "Reply callback returned error, ignoring: %m"); return 1; } -static int varlink_dispatch_timeout(Varlink *v) { +static int varlink_dispatch_timeout(sd_varlink *v) { assert(v); if (v->state != VARLINK_PENDING_TIMEOUT) return 0; varlink_set_state(v, VARLINK_PROCESSING_TIMEOUT); - varlink_dispatch_local_error(v, VARLINK_ERROR_TIMEOUT); - varlink_close(v); + varlink_dispatch_local_error(v, SD_VARLINK_ERROR_TIMEOUT); + sd_varlink_close(v); return 1; } -static int varlink_dispatch_disconnect(Varlink *v) { +static int varlink_dispatch_disconnect(sd_varlink *v) { assert(v); if (v->state != VARLINK_PENDING_DISCONNECT) return 0; varlink_set_state(v, VARLINK_PROCESSING_DISCONNECT); - varlink_dispatch_local_error(v, VARLINK_ERROR_DISCONNECTED); - varlink_close(v); + varlink_dispatch_local_error(v, SD_VARLINK_ERROR_DISCONNECTED); + sd_varlink_close(v); return 1; } @@ -1314,9 +1080,9 @@ static int varlink_sanitize_parameters(sd_json_variant **v) { return 0; } -static int varlink_dispatch_reply(Varlink *v) { +static int varlink_dispatch_reply(sd_varlink *v) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; - VarlinkReplyFlags flags = 0; + sd_varlink_reply_flags_t flags = 0; const char *error = NULL; sd_json_variant *e; const char *k; @@ -1343,7 +1109,7 @@ static int varlink_dispatch_reply(Varlink *v) { goto invalid; error = sd_json_variant_string(e); - flags |= VARLINK_REPLY_ERROR; + flags |= SD_VARLINK_REPLY_ERROR; } else if (streq(k, "parameters")) { if (parameters) @@ -1354,24 +1120,24 @@ static int varlink_dispatch_reply(Varlink *v) { parameters = sd_json_variant_ref(e); } else if (streq(k, "continues")) { - if (FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) goto invalid; if (!sd_json_variant_is_boolean(e)) goto invalid; if (sd_json_variant_boolean(e)) - flags |= VARLINK_REPLY_CONTINUES; + flags |= SD_VARLINK_REPLY_CONTINUES; } else goto invalid; } /* Replies with 'continue' set are only OK if we set 'more' when the method call was initiated */ - if (!IN_SET(v->state, VARLINK_AWAITING_REPLY_MORE, VARLINK_COLLECTING) && FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (!IN_SET(v->state, VARLINK_AWAITING_REPLY_MORE, VARLINK_COLLECTING) && FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) goto invalid; /* An error is final */ - if (error && FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (error && FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) goto invalid; r = varlink_sanitize_parameters(¶meters); @@ -1394,11 +1160,11 @@ static int varlink_dispatch_reply(Varlink *v) { if (v->state == VARLINK_PROCESSING_REPLY) { assert(v->n_pending > 0); - if (!FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (!FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) v->n_pending--; varlink_set_state(v, - FLAGS_SET(flags, VARLINK_REPLY_CONTINUES) ? VARLINK_AWAITING_REPLY_MORE : + FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES) ? VARLINK_AWAITING_REPLY_MORE : v->n_pending == 0 ? VARLINK_IDLE_CLIENT : VARLINK_AWAITING_REPLY); } } else if (v->state == VARLINK_COLLECTING) @@ -1412,16 +1178,16 @@ static int varlink_dispatch_reply(Varlink *v) { invalid: varlink_set_state(v, VARLINK_PROCESSING_FAILURE); - varlink_dispatch_local_error(v, VARLINK_ERROR_PROTOCOL); - varlink_close(v); + varlink_dispatch_local_error(v, SD_VARLINK_ERROR_PROTOCOL); + sd_varlink_close(v); return 1; } static int generic_method_get_info( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, - VarlinkMethodFlags flags, + sd_varlink_method_flags_t flags, void *userdata) { _cleanup_strv_free_ char **interfaces = NULL; @@ -1431,13 +1197,13 @@ static int generic_method_get_info( assert(link); if (sd_json_variant_elements(parameters) != 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); product = strjoin("systemd (", program_invocation_short_name, ")"); if (!product) return -ENOMEM; - VarlinkInterface *interface; + sd_varlink_interface *interface; HASHMAP_FOREACH(interface, ASSERT_PTR(link->server)->interfaces) { r = strv_extend(&interfaces, interface->name); if (r < 0) @@ -1446,7 +1212,7 @@ static int generic_method_get_info( strv_sort(interfaces); - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR_STRING("vendor", "The systemd Project"), SD_JSON_BUILD_PAIR_STRING("product", product), @@ -1456,9 +1222,9 @@ static int generic_method_get_info( } static int generic_method_get_interface_description( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, - VarlinkMethodFlags flags, + sd_varlink_method_flags_t flags, void *userdata) { static const struct sd_json_dispatch_field dispatch_table[] = { @@ -1466,7 +1232,7 @@ static int generic_method_get_interface_description( {} }; _cleanup_free_ char *text = NULL; - const VarlinkInterface *interface; + const sd_varlink_interface *interface; const char *name = NULL; int r; @@ -1478,26 +1244,26 @@ static int generic_method_get_interface_description( interface = hashmap_get(ASSERT_PTR(link->server)->interfaces, name); if (!interface) - return varlink_errorbo( + return sd_varlink_errorbo( link, - VARLINK_ERROR_INTERFACE_NOT_FOUND, + SD_VARLINK_ERROR_INTERFACE_NOT_FOUND, SD_JSON_BUILD_PAIR_STRING("interface", name)); - r = varlink_idl_format(interface, &text); + r = sd_varlink_idl_format(interface, &text); if (r < 0) return r; - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR_STRING("description", text)); } -static int varlink_dispatch_method(Varlink *v) { +static int varlink_dispatch_method(sd_varlink *v) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; - VarlinkMethodFlags flags = 0; + sd_varlink_method_flags_t flags = 0; const char *method = NULL; sd_json_variant *e; - VarlinkMethod callback; + sd_varlink_method_t callback; const char *k; int r; @@ -1531,25 +1297,25 @@ static int varlink_dispatch_method(Varlink *v) { } else if (streq(k, "oneway")) { - if ((flags & (VARLINK_METHOD_ONEWAY|VARLINK_METHOD_MORE)) != 0) + if ((flags & (SD_VARLINK_METHOD_ONEWAY|SD_VARLINK_METHOD_MORE)) != 0) goto invalid; if (!sd_json_variant_is_boolean(e)) goto invalid; if (sd_json_variant_boolean(e)) - flags |= VARLINK_METHOD_ONEWAY; + flags |= SD_VARLINK_METHOD_ONEWAY; } else if (streq(k, "more")) { - if ((flags & (VARLINK_METHOD_ONEWAY|VARLINK_METHOD_MORE)) != 0) + if ((flags & (SD_VARLINK_METHOD_ONEWAY|SD_VARLINK_METHOD_MORE)) != 0) goto invalid; if (!sd_json_variant_is_boolean(e)) goto invalid; if (sd_json_variant_boolean(e)) - flags |= VARLINK_METHOD_MORE; + flags |= SD_VARLINK_METHOD_MORE; } else goto invalid; @@ -1562,9 +1328,9 @@ static int varlink_dispatch_method(Varlink *v) { if (r < 0) goto fail; - varlink_set_state(v, (flags & VARLINK_METHOD_MORE) ? VARLINK_PROCESSING_METHOD_MORE : - (flags & VARLINK_METHOD_ONEWAY) ? VARLINK_PROCESSING_METHOD_ONEWAY : - VARLINK_PROCESSING_METHOD); + varlink_set_state(v, (flags & SD_VARLINK_METHOD_MORE) ? VARLINK_PROCESSING_METHOD_MORE : + (flags & SD_VARLINK_METHOD_ONEWAY) ? VARLINK_PROCESSING_METHOD_ONEWAY : + VARLINK_PROCESSING_METHOD); assert(v->server); @@ -1593,7 +1359,7 @@ static int varlink_dispatch_method(Varlink *v) { method, strna(bad_field)); if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PROCESSING_METHOD_MORE)) { - r = varlink_error_invalid_parameter_name(v, bad_field); + r = sd_varlink_error_invalid_parameter_name(v, bad_field); if (r < 0) return r; } @@ -1608,14 +1374,14 @@ static int varlink_dispatch_method(Varlink *v) { /* We got an error back from the callback. Propagate it to the client if the method call remains unanswered. */ if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PROCESSING_METHOD_MORE)) { - r = varlink_error_errno(v, r); + r = sd_varlink_error_errno(v, r); if (r < 0) return r; } } } } else if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PROCESSING_METHOD_MORE)) { - r = varlink_errorbo(v, VARLINK_ERROR_METHOD_NOT_FOUND, SD_JSON_BUILD_PAIR("method", SD_JSON_BUILD_STRING(method))); + r = sd_varlink_errorbo(v, SD_VARLINK_ERROR_METHOD_NOT_FOUND, SD_JSON_BUILD_PAIR("method", SD_JSON_BUILD_STRING(method))); if (r < 0) return r; } @@ -1647,13 +1413,13 @@ invalid: fail: varlink_set_state(v, VARLINK_PROCESSING_FAILURE); - varlink_dispatch_local_error(v, VARLINK_ERROR_PROTOCOL); - varlink_close(v); + varlink_dispatch_local_error(v, SD_VARLINK_ERROR_PROTOCOL); + sd_varlink_close(v); return r; } -int varlink_process(Varlink *v) { +_public_ int sd_varlink_process(sd_varlink *v) { int r; assert_return(v, -EINVAL); @@ -1661,7 +1427,7 @@ int varlink_process(Varlink *v) { if (v->state == VARLINK_DISCONNECTED) return varlink_log_errno(v, SYNTHETIC_ERRNO(ENOTCONN), "Not connected."); - varlink_ref(v); + sd_varlink_ref(v); r = varlink_write(v); if (r < 0) @@ -1729,14 +1495,14 @@ finish: varlink_set_state(v, VARLINK_PENDING_DISCONNECT); else /* We failed while disconnecting, in that case close right away */ - varlink_close(v); + sd_varlink_close(v); } - varlink_unref(v); + sd_varlink_unref(v); return r; } -int varlink_dispatch_again(Varlink *v) { +_public_ int sd_varlink_dispatch_again(sd_varlink *v) { int r; assert_return(v, -EINVAL); @@ -1760,7 +1526,7 @@ int varlink_dispatch_again(Varlink *v) { return 0; } -int varlink_get_current_parameters(Varlink *v, sd_json_variant **ret) { +_public_ int sd_varlink_get_current_parameters(sd_varlink *v, sd_json_variant **ret) { sd_json_variant *p; assert_return(v, -EINVAL); @@ -1778,7 +1544,7 @@ int varlink_get_current_parameters(Varlink *v, sd_json_variant **ret) { return 0; } -static void handle_revents(Varlink *v, int revents) { +static void handle_revents(sd_varlink *v, int revents) { assert(v); if (v->connecting) { @@ -1803,7 +1569,7 @@ static void handle_revents(Varlink *v, int revents) { } } -int varlink_wait(Varlink *v, usec_t timeout) { +_public_ int sd_varlink_wait(sd_varlink *v, usec_t timeout) { int r, events; usec_t t; @@ -1812,7 +1578,7 @@ int varlink_wait(Varlink *v, usec_t timeout) { if (v->state == VARLINK_DISCONNECTED) return varlink_log_errno(v, SYNTHETIC_ERRNO(ENOTCONN), "Not connected."); - r = varlink_get_timeout(v, &t); + r = sd_varlink_get_timeout(v, &t); if (r < 0) return r; if (t != USEC_INFINITY) { @@ -1829,7 +1595,7 @@ int varlink_wait(Varlink *v, usec_t timeout) { (t == USEC_INFINITY || timeout < t)) t = timeout; - events = varlink_get_events(v); + events = sd_varlink_get_events(v); if (events < 0) return events; @@ -1868,7 +1634,7 @@ int varlink_wait(Varlink *v, usec_t timeout) { return 1; } -int varlink_is_idle(Varlink *v) { +_public_ int sd_varlink_is_idle(sd_varlink *v) { assert_return(v, -EINVAL); /* Returns true if there's nothing pending on the connection anymore, i.e. we processed all incoming @@ -1877,7 +1643,7 @@ int varlink_is_idle(Varlink *v) { return IN_SET(v->state, VARLINK_DISCONNECTED, VARLINK_IDLE_CLIENT, VARLINK_IDLE_SERVER); } -int varlink_get_fd(Varlink *v) { +_public_ int sd_varlink_get_fd(sd_varlink *v) { assert_return(v, -EINVAL); @@ -1891,7 +1657,7 @@ int varlink_get_fd(Varlink *v) { return v->input_fd; } -int varlink_get_events(Varlink *v) { +_public_ int sd_varlink_get_events(sd_varlink *v) { int ret = 0; assert_return(v, -EINVAL); @@ -1917,7 +1683,7 @@ int varlink_get_events(Varlink *v) { return ret; } -int varlink_get_timeout(Varlink *v, usec_t *ret) { +_public_ int sd_varlink_get_timeout(sd_varlink *v, usec_t *ret) { assert_return(v, -EINVAL); if (v->state == VARLINK_DISCONNECTED) @@ -1935,7 +1701,7 @@ int varlink_get_timeout(Varlink *v, usec_t *ret) { } } -int varlink_flush(Varlink *v) { +_public_ int sd_varlink_flush(sd_varlink *v) { int ret = 0, r; assert_return(v, -EINVAL); @@ -1970,8 +1736,8 @@ int varlink_flush(Varlink *v) { return ret; } -static void varlink_detach_server(Varlink *v) { - VarlinkServer *saved_server; +static void varlink_detach_server(sd_varlink *v) { + sd_varlink_server *saved_server; assert(v); if (!v->server) @@ -2004,11 +1770,11 @@ static void varlink_detach_server(Varlink *v) { saved_server->disconnect_callback(saved_server, v, saved_server->userdata); varlink_server_test_exit_on_idle(saved_server); - varlink_server_unref(saved_server); - varlink_unref(v); + sd_varlink_server_unref(saved_server); + sd_varlink_unref(v); } -int varlink_close(Varlink *v) { +_public_ int sd_varlink_close(sd_varlink *v) { assert_return(v, -EINVAL); if (v->state == VARLINK_DISCONNECTED) @@ -2018,31 +1784,31 @@ int varlink_close(Varlink *v) { /* Let's take a reference first, since varlink_detach_server() might drop the final (dangling) ref * which would destroy us before we can call varlink_clear() */ - varlink_ref(v); + sd_varlink_ref(v); varlink_detach_server(v); varlink_clear(v); - varlink_unref(v); + sd_varlink_unref(v); return 1; } -Varlink* varlink_close_unref(Varlink *v) { +_public_ sd_varlink* sd_varlink_close_unref(sd_varlink *v) { if (!v) return NULL; - (void) varlink_close(v); - return varlink_unref(v); + (void) sd_varlink_close(v); + return sd_varlink_unref(v); } -Varlink* varlink_flush_close_unref(Varlink *v) { +_public_ sd_varlink* sd_varlink_flush_close_unref(sd_varlink *v) { if (!v) return NULL; - (void) varlink_flush(v); - return varlink_close_unref(v); + (void) sd_varlink_flush(v); + return sd_varlink_close_unref(v); } -static int varlink_format_json(Varlink *v, sd_json_variant *m) { +static int varlink_format_json(sd_varlink *v, sd_json_variant *m) { _cleanup_(erase_and_freep) char *text = NULL; int sz, r; @@ -2105,7 +1871,7 @@ static int varlink_format_json(Varlink *v, sd_json_variant *m) { return 0; } -static int varlink_enqueue_json(Varlink *v, sd_json_variant *m) { +static int varlink_enqueue_json(sd_varlink *v, sd_json_variant *m) { VarlinkJsonQueueItem *q; assert(v); @@ -2128,7 +1894,7 @@ static int varlink_enqueue_json(Varlink *v, sd_json_variant *m) { return 0; } -static int varlink_format_queue(Varlink *v) { +static int varlink_format_queue(sd_varlink *v) { int r; assert(v); @@ -2169,7 +1935,7 @@ static int varlink_format_queue(Varlink *v) { return 0; } -int varlink_send(Varlink *v, const char *method, sd_json_variant *parameters) { +_public_ int sd_varlink_send(sd_varlink *v, const char *method, sd_json_variant *parameters) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2204,7 +1970,7 @@ int varlink_send(Varlink *v, const char *method, sd_json_variant *parameters) { return 0; } -int varlink_sendb(Varlink *v, const char *method, ...) { +_public_ int sd_varlink_sendb(sd_varlink *v, const char *method, ...) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; @@ -2218,10 +1984,10 @@ int varlink_sendb(Varlink *v, const char *method, ...) { if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_send(v, method, parameters); + return sd_varlink_send(v, method, parameters); } -int varlink_invoke(Varlink *v, const char *method, sd_json_variant *parameters) { +_public_ int sd_varlink_invoke(sd_varlink *v, const char *method, sd_json_variant *parameters) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2257,7 +2023,7 @@ int varlink_invoke(Varlink *v, const char *method, sd_json_variant *parameters) return 0; } -int varlink_invokeb(Varlink *v, const char *method, ...) { +_public_ int sd_varlink_invokeb(sd_varlink *v, const char *method, ...) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; @@ -2271,10 +2037,10 @@ int varlink_invokeb(Varlink *v, const char *method, ...) { if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_invoke(v, method, parameters); + return sd_varlink_invoke(v, method, parameters); } -int varlink_observe(Varlink *v, const char *method, sd_json_variant *parameters) { +_public_ int sd_varlink_observe(sd_varlink *v, const char *method, sd_json_variant *parameters) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2312,7 +2078,7 @@ int varlink_observe(Varlink *v, const char *method, sd_json_variant *parameters) return 0; } -int varlink_observeb(Varlink *v, const char *method, ...) { +_public_ int sd_varlink_observeb(sd_varlink *v, const char *method, ...) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; @@ -2326,16 +2092,16 @@ int varlink_observeb(Varlink *v, const char *method, ...) { if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_observe(v, method, parameters); + return sd_varlink_observe(v, method, parameters); } -int varlink_call_full( - Varlink *v, +_public_ int sd_varlink_call_full( + sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id, - VarlinkReplyFlags *ret_flags) { + sd_varlink_reply_flags_t *ret_flags) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2374,13 +2140,13 @@ int varlink_call_full( v->timestamp = now(CLOCK_MONOTONIC); while (v->state == VARLINK_CALLING) { - r = varlink_process(v); + r = sd_varlink_process(v); if (r < 0) return r; if (r > 0) continue; - r = varlink_wait(v, USEC_INFINITY); + r = sd_varlink_wait(v, USEC_INFINITY); if (r < 0) return r; } @@ -2399,7 +2165,7 @@ int varlink_call_full( /* If caller doesn't ask for the error string, then let's return an error code in case of failure */ if (!ret_error_id && e) - return varlink_error_to_errno(sd_json_variant_string(e), p); + return sd_varlink_error_to_errno(sd_json_variant_string(e), p); if (ret_parameters) *ret_parameters = p; @@ -2423,12 +2189,22 @@ int varlink_call_full( } } -int varlink_callb_ap( - Varlink *v, +_public_ int sd_varlink_call( + sd_varlink *v, + const char *method, + sd_json_variant *parameters, + sd_json_variant **ret_parameters, + const char **ret_error_id) { + + return sd_varlink_call_full(v, method, parameters, ret_parameters, ret_error_id, NULL); +} + +_public_ int sd_varlink_callb_ap( + sd_varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, - VarlinkReplyFlags *ret_flags, + sd_varlink_reply_flags_t *ret_flags, va_list ap) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; @@ -2441,64 +2217,49 @@ int varlink_callb_ap( if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_call_full(v, method, parameters, ret_parameters, ret_error_id, ret_flags); + return sd_varlink_call_full(v, method, parameters, ret_parameters, ret_error_id, ret_flags); } -int varlink_call_and_log( - Varlink *v, +_public_ int sd_varlink_callb( + sd_varlink *v, const char *method, - sd_json_variant *parameters, - sd_json_variant **ret_parameters) { + sd_json_variant **ret_parameters, + const char **ret_error_id, + ...) { - sd_json_variant *reply = NULL; - const char *error_id = NULL; + va_list ap; int r; - assert_return(v, -EINVAL); - assert_return(method, -EINVAL); - - r = varlink_call(v, method, parameters, &reply, &error_id); - if (r < 0) - return log_error_errno(r, "Failed to issue %s() varlink call: %m", method); - if (error_id) - return log_error_errno(varlink_error_to_errno(error_id, reply), - "Failed to issue %s() varlink call: %s", method, error_id); - - if (ret_parameters) - *ret_parameters = TAKE_PTR(reply); - - return 0; + va_start(ap, ret_error_id); + r = sd_varlink_callb_ap(v, method, ret_parameters, ret_error_id, NULL, ap); + va_end(ap); + return r; } -int varlink_callb_and_log( - Varlink *v, +_public_ int sd_varlink_callb_full( + sd_varlink *v, const char *method, sd_json_variant **ret_parameters, + const char **ret_error_id, + sd_varlink_reply_flags_t *ret_flags, ...) { - _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; - assert_return(v, -EINVAL); - assert_return(method, -EINVAL); - - va_start(ap, ret_parameters); - r = sd_json_buildv(¶meters, ap); + va_start(ap, ret_flags); + r = sd_varlink_callb_ap(v, method, ret_parameters, ret_error_id, ret_flags, ap); va_end(ap); - if (r < 0) - return log_error_errno(r, "Failed to build JSON message: %m"); - - return varlink_call_and_log(v, method, parameters, ret_parameters); + return r; } -int varlink_collect_full( - Varlink *v, +_public_ int sd_varlink_collect_full( + sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id, - VarlinkReplyFlags *ret_flags) { + sd_varlink_reply_flags_t *ret_flags) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL, *collected = NULL; int r; @@ -2539,13 +2300,13 @@ int varlink_collect_full( for (;;) { while (v->state == VARLINK_COLLECTING) { - r = varlink_process(v); + r = sd_varlink_process(v); if (r < 0) return r; if (r > 0) continue; - r = varlink_wait(v, USEC_INFINITY); + r = sd_varlink_wait(v, USEC_INFINITY); if (r < 0) return r; } @@ -2559,7 +2320,7 @@ int varlink_collect_full( *p = sd_json_variant_by_key(v->current, "parameters"); /* Unless there is more to collect we reset state to idle */ - if (!FLAGS_SET(v->current_reply_flags, VARLINK_REPLY_CONTINUES)) { + if (!FLAGS_SET(v->current_reply_flags, SD_VARLINK_REPLY_CONTINUES)) { varlink_set_state(v, VARLINK_IDLE_CLIENT); assert(v->n_pending == 1); v->n_pending--; @@ -2567,7 +2328,7 @@ int varlink_collect_full( if (e) { if (!ret_error_id) - return varlink_error_to_errno(sd_json_variant_string(e), p); + return sd_varlink_error_to_errno(sd_json_variant_string(e), p); if (ret_parameters) *ret_parameters = p; @@ -2586,7 +2347,7 @@ int varlink_collect_full( if (r < 0) return varlink_log_errno(v, r, "Failed to append JSON object to array: %m"); - if (FLAGS_SET(v->current_reply_flags, VARLINK_REPLY_CONTINUES)) { + if (FLAGS_SET(v->current_reply_flags, SD_VARLINK_REPLY_CONTINUES)) { /* There's more to collect, continue */ varlink_clear_current(v); varlink_set_state(v, VARLINK_COLLECTING); @@ -2619,8 +2380,18 @@ int varlink_collect_full( } } -int varlink_collectb( - Varlink *v, +_public_ int sd_varlink_collect( + sd_varlink *v, + const char *method, + sd_json_variant *parameters, + sd_json_variant **ret_parameters, + const char **ret_error_id) { + + return sd_varlink_collect_full(v, method, parameters, ret_parameters, ret_error_id, NULL); +} + +_public_ int sd_varlink_collectb( + sd_varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, @@ -2639,10 +2410,10 @@ int varlink_collectb( if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_collect_full(v, method, parameters, ret_parameters, ret_error_id, NULL); + return sd_varlink_collect_full(v, method, parameters, ret_parameters, ret_error_id, NULL); } -int varlink_reply(Varlink *v, sd_json_variant *parameters) { +_public_ int sd_varlink_reply(sd_varlink *v, sd_json_variant *parameters) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2691,7 +2462,7 @@ int varlink_reply(Varlink *v, sd_json_variant *parameters) { return 1; } -int varlink_replyb(Varlink *v, ...) { +_public_ int sd_varlink_replyb(sd_varlink *v, ...) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; @@ -2705,10 +2476,22 @@ int varlink_replyb(Varlink *v, ...) { if (r < 0) return r; - return varlink_reply(v, parameters); + return sd_varlink_reply(v, parameters); } -int varlink_error(Varlink *v, const char *error_id, sd_json_variant *parameters) { +static int varlink_reset_fds(sd_varlink *v) { + assert_return(v, -EINVAL); + + /* Closes all currently pending fds to send. This may be used whenever the caller is in the process + * of putting together a message with fds, and then eventually something fails and they need to + * rollback the fds. Note that this is implicitly called whenever an error reply is sent, see above. */ + + close_many(v->output_fds, v->n_output_fds); + v->n_output_fds = 0; + return 0; +} + +_public_ int sd_varlink_error(sd_varlink *v, const char *error_id, sd_json_variant *parameters) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2740,7 +2523,7 @@ int varlink_error(Varlink *v, const char *error_id, sd_json_variant *parameters) if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - VarlinkSymbol *symbol = hashmap_get(v->server->symbols, error_id); + sd_varlink_symbol *symbol = hashmap_get(v->server->symbols, error_id); if (!symbol) varlink_log(v, "No interface description defined for error '%s', not validating.", error_id); else { @@ -2766,7 +2549,7 @@ int varlink_error(Varlink *v, const char *error_id, sd_json_variant *parameters) return 1; } -int varlink_errorb(Varlink *v, const char *error_id, ...) { +_public_ int sd_varlink_errorb(sd_varlink *v, const char *error_id, ...) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; @@ -2781,10 +2564,10 @@ int varlink_errorb(Varlink *v, const char *error_id, ...) { if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_error(v, error_id, parameters); + return sd_varlink_error(v, error_id, parameters); } -int varlink_error_invalid_parameter(Varlink *v, sd_json_variant *parameters) { +_public_ int sd_varlink_error_invalid_parameter(sd_varlink *v, sd_json_variant *parameters) { int r; assert_return(v, -EINVAL); @@ -2805,7 +2588,7 @@ int varlink_error_invalid_parameter(Varlink *v, sd_json_variant *parameters) { if (r < 0) return r; - return varlink_error(v, VARLINK_ERROR_INVALID_PARAMETER, parameters_obj); + return sd_varlink_error(v, SD_VARLINK_ERROR_INVALID_PARAMETER, parameters_obj); } if (sd_json_variant_is_object(parameters) && @@ -2816,27 +2599,27 @@ int varlink_error_invalid_parameter(Varlink *v, sd_json_variant *parameters) { if (r < 0) return r; - return varlink_error(v, VARLINK_ERROR_INVALID_PARAMETER, parameters_obj); + return sd_varlink_error(v, SD_VARLINK_ERROR_INVALID_PARAMETER, parameters_obj); } return -EINVAL; } -int varlink_error_invalid_parameter_name(Varlink *v, const char *name) { - return varlink_errorbo( +_public_ int sd_varlink_error_invalid_parameter_name(sd_varlink *v, const char *name) { + return sd_varlink_errorbo( v, - VARLINK_ERROR_INVALID_PARAMETER, + SD_VARLINK_ERROR_INVALID_PARAMETER, SD_JSON_BUILD_PAIR("parameter", SD_JSON_BUILD_STRING(name))); } -int varlink_error_errno(Varlink *v, int error) { - return varlink_errorbo( +_public_ int sd_varlink_error_errno(sd_varlink *v, int error) { + return sd_varlink_errorbo( v, - VARLINK_ERROR_SYSTEM, + SD_VARLINK_ERROR_SYSTEM, SD_JSON_BUILD_PAIR("errno", SD_JSON_BUILD_INTEGER(abs(error)))); } -int varlink_notify(Varlink *v, sd_json_variant *parameters) { +_public_ int sd_varlink_notify(sd_varlink *v, sd_json_variant *parameters) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *m = NULL; int r; @@ -2848,7 +2631,7 @@ int varlink_notify(Varlink *v, sd_json_variant *parameters) { /* If we want to reply with a notify connection but the caller didn't set "more", then return an * error indicating that we expected to be called with "more" set */ if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PENDING_METHOD)) - return varlink_error(v, VARLINK_ERROR_EXPECTED_MORE, NULL); + return sd_varlink_error(v, SD_VARLINK_ERROR_EXPECTED_MORE, NULL); if (!IN_SET(v->state, VARLINK_PROCESSING_METHOD_MORE, VARLINK_PENDING_METHOD_MORE)) return varlink_log_errno(v, SYNTHETIC_ERRNO(EBUSY), "Connection busy."); @@ -2882,7 +2665,7 @@ int varlink_notify(Varlink *v, sd_json_variant *parameters) { return 1; } -int varlink_notifyb(Varlink *v, ...) { +_public_ int sd_varlink_notifyb(sd_varlink *v, ...) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; va_list ap; int r; @@ -2896,10 +2679,10 @@ int varlink_notifyb(Varlink *v, ...) { if (r < 0) return varlink_log_errno(v, r, "Failed to build json message: %m"); - return varlink_notify(v, parameters); + return sd_varlink_notify(v, parameters); } -int varlink_dispatch(Varlink *v, sd_json_variant *parameters, const sd_json_dispatch_field table[], void *userdata) { +_public_ int sd_varlink_dispatch(sd_varlink *v, sd_json_variant *parameters, const sd_json_dispatch_field table[], void *userdata) { const char *bad_field = NULL; int r; @@ -2911,14 +2694,14 @@ int varlink_dispatch(Varlink *v, sd_json_variant *parameters, const sd_json_disp r = sd_json_dispatch_full(parameters, table, /* bad= */ NULL, /* flags= */ 0, userdata, &bad_field); if (r < 0) { if (bad_field) - return varlink_error_invalid_parameter_name(v, bad_field); + return sd_varlink_error_invalid_parameter_name(v, bad_field); return r; } return 0; } -int varlink_bind_reply(Varlink *v, VarlinkReply callback) { +_public_ int sd_varlink_bind_reply(sd_varlink *v, sd_varlink_reply_t callback) { assert_return(v, -EINVAL); if (callback && v->reply_callback && callback != v->reply_callback) @@ -2929,7 +2712,7 @@ int varlink_bind_reply(Varlink *v, VarlinkReply callback) { return 0; } -void* varlink_set_userdata(Varlink *v, void *userdata) { +_public_ void* sd_varlink_set_userdata(sd_varlink *v, void *userdata) { void *old; assert_return(v, NULL); @@ -2940,13 +2723,13 @@ void* varlink_set_userdata(Varlink *v, void *userdata) { return old; } -void* varlink_get_userdata(Varlink *v) { +_public_ void* sd_varlink_get_userdata(sd_varlink *v) { assert_return(v, NULL); return v->userdata; } -static int varlink_acquire_ucred(Varlink *v) { +static int varlink_acquire_ucred(sd_varlink *v) { int r; assert(v); @@ -2967,7 +2750,7 @@ static int varlink_acquire_ucred(Varlink *v) { return 0; } -int varlink_get_peer_uid(Varlink *v, uid_t *ret) { +_public_ int sd_varlink_get_peer_uid(sd_varlink *v, uid_t *ret) { int r; assert_return(v, -EINVAL); @@ -2984,7 +2767,7 @@ int varlink_get_peer_uid(Varlink *v, uid_t *ret) { return 0; } -int varlink_get_peer_gid(Varlink *v, gid_t *ret) { +_public_ int sd_varlink_get_peer_gid(sd_varlink *v, gid_t *ret) { int r; assert_return(v, -EINVAL); @@ -3001,7 +2784,7 @@ int varlink_get_peer_gid(Varlink *v, gid_t *ret) { return 0; } -int varlink_get_peer_pid(Varlink *v, pid_t *ret) { +_public_ int sd_varlink_get_peer_pid(sd_varlink *v, pid_t *ret) { int r; assert_return(v, -EINVAL); @@ -3018,58 +2801,23 @@ int varlink_get_peer_pid(Varlink *v, pid_t *ret) { return 0; } -static int varlink_acquire_pidfd(Varlink *v) { - assert(v); +_public_ int sd_varlink_get_peer_pidfd(sd_varlink *v) { + assert_return(v, -EINVAL); if (v->peer_pidfd >= 0) - return 0; + return v->peer_pidfd; if (v->input_fd != v->output_fd) return -EBADF; v->peer_pidfd = getpeerpidfd(v->input_fd); if (v->peer_pidfd < 0) - return v->peer_pidfd; + return varlink_log_errno(v, v->peer_pidfd, "Failed to acquire pidfd of peer: %m"); - return 0; + return v->peer_pidfd; } -int varlink_get_peer_pidref(Varlink *v, PidRef *ret) { - int r; - - assert_return(v, -EINVAL); - assert_return(ret, -EINVAL); - - /* Returns r > 0 if we acquired the pidref via SO_PEERPIDFD (i.e. if we can use it for - * authentication). Returns == 0 if we didn't, and the pidref should not be used for - * authentication. */ - - r = varlink_acquire_pidfd(v); - if (r < 0 && !ERRNO_IS_NEG_NOT_SUPPORTED(r)) - return r; - - if (v->peer_pidfd < 0) { - pid_t pid; - - r = varlink_get_peer_pid(v, &pid); - if (r < 0) - return r; - - r = pidref_set_pid(ret, pid); - if (r < 0) - return r; - - return 0; /* didn't get pidfd securely */ - } - - r = pidref_set_pidfd(ret, v->peer_pidfd); - if (r < 0) - return r; - - return 1; /* got pidfd securely */ -} - -int varlink_set_relative_timeout(Varlink *v, usec_t timeout) { +_public_ int sd_varlink_set_relative_timeout(sd_varlink *v, usec_t timeout) { assert_return(v, -EINVAL); assert_return(timeout > 0, -EINVAL); @@ -3077,56 +2825,56 @@ int varlink_set_relative_timeout(Varlink *v, usec_t timeout) { return 0; } -VarlinkServer *varlink_get_server(Varlink *v) { +_public_ sd_varlink_server *sd_varlink_get_server(sd_varlink *v) { assert_return(v, NULL); return v->server; } -int varlink_set_description(Varlink *v, const char *description) { +_public_ int sd_varlink_set_description(sd_varlink *v, const char *description) { assert_return(v, -EINVAL); return free_and_strdup(&v->description, description); } static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - Varlink *v = ASSERT_PTR(userdata); + sd_varlink *v = ASSERT_PTR(userdata); assert(s); handle_revents(v, revents); - (void) varlink_process(v); + (void) sd_varlink_process(v); return 1; } static int time_callback(sd_event_source *s, uint64_t usec, void *userdata) { - Varlink *v = ASSERT_PTR(userdata); + sd_varlink *v = ASSERT_PTR(userdata); assert(s); - (void) varlink_process(v); + (void) sd_varlink_process(v); return 1; } static int defer_callback(sd_event_source *s, void *userdata) { - Varlink *v = ASSERT_PTR(userdata); + sd_varlink *v = ASSERT_PTR(userdata); assert(s); - (void) varlink_process(v); + (void) sd_varlink_process(v); return 1; } static int prepare_callback(sd_event_source *s, void *userdata) { - Varlink *v = ASSERT_PTR(userdata); + sd_varlink *v = ASSERT_PTR(userdata); int r, e; usec_t until; bool have_timeout; assert(s); - e = varlink_get_events(v); + e = sd_varlink_get_events(v); if (e < 0) return e; @@ -3141,7 +2889,7 @@ static int prepare_callback(sd_event_source *s, void *userdata) { if (r < 0) return varlink_log_errno(v, r, "Failed to set source events: %m"); - r = varlink_get_timeout(v, &until); + r = sd_varlink_get_timeout(v, &until); if (r < 0) return r; have_timeout = r > 0; @@ -3160,17 +2908,17 @@ static int prepare_callback(sd_event_source *s, void *userdata) { } static int quit_callback(sd_event_source *event, void *userdata) { - Varlink *v = ASSERT_PTR(userdata); + sd_varlink *v = ASSERT_PTR(userdata); assert(event); - varlink_flush(v); - varlink_close(v); + sd_varlink_flush(v); + sd_varlink_close(v); return 1; } -int varlink_attach_event(Varlink *v, sd_event *e, int64_t priority) { +_public_ int sd_varlink_attach_event(sd_varlink *v, sd_event *e, int64_t priority) { int r; assert_return(v, -EINVAL); @@ -3246,11 +2994,11 @@ int varlink_attach_event(Varlink *v, sd_event *e, int64_t priority) { fail: varlink_log_errno(v, r, "Failed to setup event source: %m"); - varlink_detach_event(v); + sd_varlink_detach_event(v); return r; } -void varlink_detach_event(Varlink *v) { +_public_ void sd_varlink_detach_event(sd_varlink *v) { if (!v) return; @@ -3259,13 +3007,13 @@ void varlink_detach_event(Varlink *v) { v->event = sd_event_unref(v->event); } -sd_event *varlink_get_event(Varlink *v) { +_public_ sd_event *sd_varlink_get_event(sd_varlink *v) { assert_return(v, NULL); return v->event; } -int varlink_push_fd(Varlink *v, int fd) { +_public_ int sd_varlink_push_fd(sd_varlink *v, int fd) { int i; assert_return(v, -EINVAL); @@ -3288,7 +3036,7 @@ int varlink_push_fd(Varlink *v, int fd) { return i; } -int varlink_push_dup_fd(Varlink *v, int fd) { +_public_ int sd_varlink_push_dup_fd(sd_varlink *v, int fd) { _cleanup_close_ int dp = -1; int r; @@ -3301,7 +3049,7 @@ int varlink_push_dup_fd(Varlink *v, int fd) { if (dp < 0) return -errno; - r = varlink_push_fd(v, dp); + r = sd_varlink_push_fd(v, dp); if (r < 0) return r; @@ -3309,19 +3057,7 @@ int varlink_push_dup_fd(Varlink *v, int fd) { return r; } -int varlink_reset_fds(Varlink *v) { - assert_return(v, -EINVAL); - - /* Closes all currently pending fds to send. This may be used whenever the caller is in the process - * of putting together a message with fds, and then eventually something fails and they need to - * rollback the fds. Note that this is implicitly called whenever an error reply is sent, see above. */ - - close_many(v->output_fds, v->n_output_fds); - v->n_output_fds = 0; - return 0; -} - -int varlink_peek_fd(Varlink *v, size_t i) { +_public_ int sd_varlink_peek_fd(sd_varlink *v, size_t i) { assert_return(v, -EINVAL); /* Returns one of the file descriptors that were received along with the current message. This does @@ -3336,17 +3072,17 @@ int varlink_peek_fd(Varlink *v, size_t i) { return v->input_fds[i]; } -int varlink_peek_dup_fd(Varlink *v, size_t i) { +_public_ int sd_varlink_peek_dup_fd(sd_varlink *v, size_t i) { int fd; - fd = varlink_peek_fd(v, i); + fd = sd_varlink_peek_fd(v, i); if (fd < 0) return fd; return RET_NERRNO(fcntl(fd, F_DUPFD_CLOEXEC, 3)); } -int varlink_take_fd(Varlink *v, size_t i) { +_public_ int sd_varlink_take_fd(sd_varlink *v, size_t i) { assert_return(v, -EINVAL); /* Similar to varlink_peek_fd() but the file descriptor's ownership is passed to the caller, and @@ -3362,7 +3098,7 @@ int varlink_take_fd(Varlink *v, size_t i) { return TAKE_FD(v->input_fds[i]); } -static int verify_unix_socket(Varlink *v) { +static int verify_unix_socket(sd_varlink *v) { assert(v); /* Returns: @@ -3401,12 +3137,12 @@ static int verify_unix_socket(Varlink *v) { v->af == AF_UNSPEC ? -ENOTSOCK : -ENOMEDIUM; } -int varlink_set_allow_fd_passing_input(Varlink *v, bool b) { +_public_ int sd_varlink_set_allow_fd_passing_input(sd_varlink *v, int b) { int r; assert_return(v, -EINVAL); - if (v->allow_fd_passing_input == b) + if (v->allow_fd_passing_input == !!b) return 0; if (!b) { @@ -3422,12 +3158,12 @@ int varlink_set_allow_fd_passing_input(Varlink *v, bool b) { return 0; } -int varlink_set_allow_fd_passing_output(Varlink *v, bool b) { +_public_ int sd_varlink_set_allow_fd_passing_output(sd_varlink *v, int b) { int r; assert_return(v, -EINVAL); - if (v->allow_fd_passing_output == b) + if (v->allow_fd_passing_output == !!b) return 0; if (!b) { @@ -3443,32 +3179,32 @@ int varlink_set_allow_fd_passing_output(Varlink *v, bool b) { return 0; } -int varlink_set_input_sensitive(Varlink *v) { +_public_ int sd_varlink_set_input_sensitive(sd_varlink *v) { assert_return(v, -EINVAL); v->input_sensitive = true; return 0; } -int varlink_server_new(VarlinkServer **ret, VarlinkServerFlags flags) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; +_public_ int sd_varlink_server_new(sd_varlink_server **ret, sd_varlink_server_flags_t flags) { + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert_return(ret, -EINVAL); - assert_return((flags & ~_VARLINK_SERVER_FLAGS_ALL) == 0, -EINVAL); + assert_return((flags & ~(SD_VARLINK_SERVER_ROOT_ONLY|SD_VARLINK_SERVER_MYSELF_ONLY|SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA|SD_VARLINK_SERVER_INPUT_SENSITIVE)) == 0, -EINVAL); - s = new(VarlinkServer, 1); + s = new(sd_varlink_server, 1); if (!s) return log_oom_debug(); - *s = (VarlinkServer) { + *s = (sd_varlink_server) { .n_ref = 1, .flags = flags, - .connections_max = varlink_server_connections_max(NULL), - .connections_per_uid_max = varlink_server_connections_per_uid_max(NULL), + .connections_max = sd_varlink_server_connections_max(NULL), + .connections_per_uid_max = sd_varlink_server_connections_per_uid_max(NULL), }; - r = varlink_server_add_interface_many( + r = sd_varlink_server_add_interface_many( s, &vl_interface_io_systemd, &vl_interface_org_varlink_service); @@ -3479,13 +3215,13 @@ int varlink_server_new(VarlinkServer **ret, VarlinkServerFlags flags) { return 0; } -static VarlinkServer* varlink_server_destroy(VarlinkServer *s) { +static sd_varlink_server* varlink_server_destroy(sd_varlink_server *s) { char *m; if (!s) return NULL; - varlink_server_shutdown(s); + sd_varlink_server_shutdown(s); while ((m = hashmap_steal_first_key(s->methods))) free(m); @@ -3502,18 +3238,18 @@ static VarlinkServer* varlink_server_destroy(VarlinkServer *s) { return mfree(s); } -DEFINE_TRIVIAL_REF_UNREF_FUNC(VarlinkServer, varlink_server, varlink_server_destroy); +DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_varlink_server, sd_varlink_server, varlink_server_destroy); -static int validate_connection(VarlinkServer *server, const struct ucred *ucred) { +static int validate_connection(sd_varlink_server *server, const struct ucred *ucred) { int allowed = -1; assert(server); assert(ucred); - if (FLAGS_SET(server->flags, VARLINK_SERVER_ROOT_ONLY)) + if (FLAGS_SET(server->flags, SD_VARLINK_SERVER_ROOT_ONLY)) allowed = ucred->uid == 0; - if (FLAGS_SET(server->flags, VARLINK_SERVER_MYSELF_ONLY)) + if (FLAGS_SET(server->flags, SD_VARLINK_SERVER_MYSELF_ONLY)) allowed = allowed > 0 || ucred->uid == getuid(); if (allowed == 0) { /* Allow access when it is explicitly allowed or when neither @@ -3527,7 +3263,7 @@ static int validate_connection(VarlinkServer *server, const struct ucred *ucred) return 0; } - if (FLAGS_SET(server->flags, VARLINK_SERVER_ACCOUNT_UID)) { + if (FLAGS_SET(server->flags, SD_VARLINK_SERVER_ACCOUNT_UID)) { unsigned c; if (!uid_is_valid(ucred->uid)) { @@ -3546,7 +3282,7 @@ static int validate_connection(VarlinkServer *server, const struct ucred *ucred) return 1; } -static int count_connection(VarlinkServer *server, const struct ucred *ucred) { +static int count_connection(sd_varlink_server *server, const struct ucred *ucred) { unsigned c; int r; @@ -3555,7 +3291,7 @@ static int count_connection(VarlinkServer *server, const struct ucred *ucred) { server->n_connections++; - if (FLAGS_SET(server->flags, VARLINK_SERVER_ACCOUNT_UID)) { + if (FLAGS_SET(server->flags, SD_VARLINK_SERVER_ACCOUNT_UID)) { assert(uid_is_valid(ucred->uid)); r = hashmap_ensure_allocated(&server->by_uid, NULL); @@ -3575,14 +3311,14 @@ static int count_connection(VarlinkServer *server, const struct ucred *ucred) { return 0; } -int varlink_server_add_connection_pair( - VarlinkServer *server, +_public_ int sd_varlink_server_add_connection_pair( + sd_varlink_server *server, int input_fd, int output_fd, const struct ucred *override_ucred, - Varlink **ret) { + sd_varlink **ret) { - _cleanup_(varlink_unrefp) Varlink *v = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *v = NULL; struct ucred ucred = UCRED_INVALID; bool ucred_acquired; int r; @@ -3591,7 +3327,7 @@ int varlink_server_add_connection_pair( assert_return(input_fd >= 0, -EBADF); assert_return(output_fd >= 0, -EBADF); - if ((server->flags & (VARLINK_SERVER_ROOT_ONLY|VARLINK_SERVER_ACCOUNT_UID)) != 0) { + if ((server->flags & (SD_VARLINK_SERVER_ROOT_ONLY|SD_VARLINK_SERVER_ACCOUNT_UID)) != 0) { if (override_ucred) ucred = *override_ucred; @@ -3624,7 +3360,7 @@ int varlink_server_add_connection_pair( v->input_fd = input_fd; v->output_fd = output_fd; - if (server->flags & VARLINK_SERVER_INHERIT_USERDATA) + if (server->flags & SD_VARLINK_SERVER_INHERIT_USERDATA) v->userdata = server->userdata; if (ucred_acquired) { @@ -3639,18 +3375,18 @@ int varlink_server_add_connection_pair( /* Link up the server and the connection, and take reference in both directions. Note that the * reference on the connection is left dangling. It will be dropped when the connection is closed, * which happens in varlink_close(), including in the event loop quit callback. */ - v->server = varlink_server_ref(server); - varlink_ref(v); + v->server = sd_varlink_server_ref(server); + sd_varlink_ref(v); varlink_set_state(v, VARLINK_IDLE_SERVER); if (server->event) { - r = varlink_attach_event(v, server->event, server->event_priority); + r = sd_varlink_attach_event(v, server->event, server->event_priority); if (r < 0) { varlink_log_errno(v, r, "Failed to attach new connection: %m"); TAKE_FD(v->input_fd); /* take the fd out of the connection again */ TAKE_FD(v->output_fd); - varlink_close(v); + sd_varlink_close(v); return r; } } @@ -3661,11 +3397,11 @@ int varlink_server_add_connection_pair( return 0; } -int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret) { - return varlink_server_add_connection_pair(server, fd, fd, /* override_ucred= */ NULL, ret); +_public_ int sd_varlink_server_add_connection(sd_varlink_server *server, int fd, sd_varlink **ret) { + return sd_varlink_server_add_connection_pair(server, fd, fd, /* override_ucred= */ NULL, ret); } -static VarlinkServerSocket *varlink_server_socket_free(VarlinkServerSocket *ss) { +VarlinkServerSocket *varlink_server_socket_free(VarlinkServerSocket *ss) { if (!ss) return NULL; @@ -3673,12 +3409,10 @@ static VarlinkServerSocket *varlink_server_socket_free(VarlinkServerSocket *ss) return mfree(ss); } -DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServerSocket *, varlink_server_socket_free); - static int connect_callback(sd_event_source *source, int fd, uint32_t revents, void *userdata) { VarlinkServerSocket *ss = ASSERT_PTR(userdata); _cleanup_close_ int cfd = -EBADF; - Varlink *v = NULL; + sd_varlink *v = NULL; int r; assert(source); @@ -3693,20 +3427,20 @@ static int connect_callback(sd_event_source *source, int fd, uint32_t revents, v return varlink_server_log_errno(ss->server, errno, "Failed to accept incoming socket: %m"); } - r = varlink_server_add_connection(ss->server, cfd, &v); + r = sd_varlink_server_add_connection(ss->server, cfd, &v); if (r < 0) return 0; TAKE_FD(cfd); - if (FLAGS_SET(ss->server->flags, VARLINK_SERVER_INPUT_SENSITIVE)) - varlink_set_input_sensitive(v); + if (FLAGS_SET(ss->server->flags, SD_VARLINK_SERVER_INPUT_SENSITIVE)) + sd_varlink_set_input_sensitive(v); if (ss->server->connect_callback) { r = ss->server->connect_callback(ss->server, v, ss->server->userdata); if (r < 0) { varlink_log_errno(v, r, "Connection callback returned error, disconnecting client: %m"); - varlink_close(v); + sd_varlink_close(v); return 0; } } @@ -3714,7 +3448,7 @@ static int connect_callback(sd_event_source *source, int fd, uint32_t revents, v return 0; } -static int varlink_server_create_listen_fd_socket(VarlinkServer *s, int fd, VarlinkServerSocket **ret_ss) { +static int varlink_server_create_listen_fd_socket(sd_varlink_server *s, int fd, VarlinkServerSocket **ret_ss) { _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL; int r; @@ -3745,7 +3479,7 @@ static int varlink_server_create_listen_fd_socket(VarlinkServer *s, int fd, Varl return 0; } -int varlink_server_listen_fd(VarlinkServer *s, int fd) { +_public_ int sd_varlink_server_listen_fd(sd_varlink_server *s, int fd) { _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL; int r; @@ -3768,7 +3502,7 @@ int varlink_server_listen_fd(VarlinkServer *s, int fd) { return 0; } -int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t m) { +_public_ int sd_varlink_server_listen_address(sd_varlink_server *s, const char *address, mode_t m) { _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL; union sockaddr_union sockaddr; socklen_t sockaddr_len; @@ -3792,11 +3526,10 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t (void) sockaddr_un_unlink(&sockaddr.un); - WITH_UMASK(~m & 0777) { - r = mac_selinux_bind(fd, &sockaddr.sa, sockaddr_len); - if (r < 0) - return r; - } + WITH_UMASK(~m & 0777) + r = RET_NERRNO(bind(fd, &sockaddr.sa, sockaddr_len)); + if (r < 0) + return r; if (listen(fd, SOMAXCONN_DELUXE) < 0) return -errno; @@ -3814,7 +3547,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t return 0; } -int varlink_server_add_connection_stdio(VarlinkServer *s, Varlink **ret) { +_public_ int sd_varlink_server_add_connection_stdio(sd_varlink_server *s, sd_varlink **ret) { _cleanup_close_ int input_fd = -EBADF, output_fd = -EBADF; int r; @@ -3864,7 +3597,7 @@ int varlink_server_add_connection_stdio(VarlinkServer *s, Varlink **ret) { } else pucred = NULL; - r = varlink_server_add_connection_pair(s, input_fd, output_fd, pucred, ret); + r = sd_varlink_server_add_connection_pair(s, input_fd, output_fd, pucred, ret); if (r < 0) return r; @@ -3874,7 +3607,7 @@ int varlink_server_add_connection_stdio(VarlinkServer *s, Varlink **ret) { return 0; } -int varlink_server_listen_auto(VarlinkServer *s) { +_public_ int sd_varlink_server_listen_auto(sd_varlink_server *s) { _cleanup_strv_free_ char **names = NULL; int r, n = 0; @@ -3905,9 +3638,9 @@ int varlink_server_listen_auto(VarlinkServer *s) { assert(l == sizeof(b)); if (b) /* Listening socket? */ - r = varlink_server_listen_fd(s, fd); + r = sd_varlink_server_listen_fd(s, fd); else /* Otherwise assume connection socket */ - r = varlink_server_add_connection(s, fd, NULL); + r = sd_varlink_server_add_connection(s, fd, NULL); if (r < 0) return r; @@ -3918,9 +3651,9 @@ int varlink_server_listen_auto(VarlinkServer *s) { const char *e = secure_getenv("SYSTEMD_VARLINK_LISTEN"); if (e) { if (streq(e, "-")) - r = varlink_server_add_connection_stdio(s, /* ret= */ NULL); + r = sd_varlink_server_add_connection_stdio(s, /* ret= */ NULL); else - r = varlink_server_listen_address(s, e, FLAGS_SET(s->flags, VARLINK_SERVER_ROOT_ONLY) ? 0600 : 0666); + r = sd_varlink_server_listen_address(s, e, FLAGS_SET(s->flags, SD_VARLINK_SERVER_ROOT_ONLY) ? 0600 : 0666); if (r < 0) return r; @@ -3930,7 +3663,7 @@ int varlink_server_listen_auto(VarlinkServer *s) { return n; } -void* varlink_server_set_userdata(VarlinkServer *s, void *userdata) { +_public_ void* sd_varlink_server_set_userdata(sd_varlink_server *s, void *userdata) { void *ret; assert_return(s, NULL); @@ -3941,34 +3674,34 @@ void* varlink_server_set_userdata(VarlinkServer *s, void *userdata) { return ret; } -void* varlink_server_get_userdata(VarlinkServer *s) { +_public_ void* sd_varlink_server_get_userdata(sd_varlink_server *s) { assert_return(s, NULL); return s->userdata; } -int varlink_server_loop_auto(VarlinkServer *server) { +_public_ int sd_varlink_server_loop_auto(sd_varlink_server *server) { _cleanup_(sd_event_unrefp) sd_event *event = NULL; int r; assert_return(server, -EINVAL); assert_return(!server->event, -EBUSY); - /* Runs a Varlink service event loop populated with a passed fd. Exits on the last connection. */ + /* Runs a sd_varlink service event loop populated with a passed fd. Exits on the last connection. */ r = sd_event_new(&event); if (r < 0) return r; - r = varlink_server_set_exit_on_idle(server, true); + r = sd_varlink_server_set_exit_on_idle(server, true); if (r < 0) return r; - r = varlink_server_attach_event(server, event, 0); + r = sd_varlink_server_attach_event(server, event, 0); if (r < 0) return r; - r = varlink_server_listen_auto(server); + r = sd_varlink_server_listen_auto(server); if (r < 0) return r; @@ -3990,7 +3723,7 @@ static VarlinkServerSocket* varlink_server_socket_destroy(VarlinkServerSocket *s return mfree(ss); } -int varlink_server_shutdown(VarlinkServer *s) { +_public_ int sd_varlink_server_shutdown(sd_varlink_server *s) { assert_return(s, -EINVAL); while (s->sockets) @@ -3999,14 +3732,14 @@ int varlink_server_shutdown(VarlinkServer *s) { return 0; } -static void varlink_server_test_exit_on_idle(VarlinkServer *s) { +static void varlink_server_test_exit_on_idle(sd_varlink_server *s) { assert(s); if (s->exit_on_idle && s->event && s->n_connections == 0) (void) sd_event_exit(s->event, 0); } -int varlink_server_set_exit_on_idle(VarlinkServer *s, bool b) { +_public_ int sd_varlink_server_set_exit_on_idle(sd_varlink_server *s, int b) { assert_return(s, -EINVAL); s->exit_on_idle = b; @@ -4014,7 +3747,7 @@ int varlink_server_set_exit_on_idle(VarlinkServer *s, bool b) { return 0; } -static int varlink_server_add_socket_event_source(VarlinkServer *s, VarlinkServerSocket *ss, int64_t priority) { +int varlink_server_add_socket_event_source(sd_varlink_server *s, VarlinkServerSocket *ss, int64_t priority) { _cleanup_(sd_event_source_unrefp) sd_event_source *es = NULL; int r; @@ -4036,7 +3769,7 @@ static int varlink_server_add_socket_event_source(VarlinkServer *s, VarlinkServe return 0; } -int varlink_server_attach_event(VarlinkServer *s, sd_event *e, int64_t priority) { +_public_ int sd_varlink_server_attach_event(sd_varlink_server *s, sd_event *e, int64_t priority) { int r; assert_return(s, -EINVAL); @@ -4060,11 +3793,11 @@ int varlink_server_attach_event(VarlinkServer *s, sd_event *e, int64_t priority) return 0; fail: - varlink_server_detach_event(s); + sd_varlink_server_detach_event(s); return r; } -int varlink_server_detach_event(VarlinkServer *s) { +_public_ int sd_varlink_server_detach_event(sd_varlink_server *s) { assert_return(s, -EINVAL); LIST_FOREACH(sockets, ss, s->sockets) @@ -4074,7 +3807,7 @@ int varlink_server_detach_event(VarlinkServer *s) { return 0; } -sd_event *varlink_server_get_event(VarlinkServer *s) { +_public_ sd_event *sd_varlink_server_get_event(sd_varlink_server *s) { assert_return(s, NULL); return s->event; @@ -4096,7 +3829,7 @@ static bool varlink_symbol_in_interface(const char *method, const char *interfac return !strchr(p+1, '.'); } -int varlink_server_bind_method(VarlinkServer *s, const char *method, VarlinkMethod callback) { +_public_ int sd_varlink_server_bind_method(sd_varlink_server *s, const char *method, sd_varlink_method_t callback) { _cleanup_free_ char *m = NULL; int r; @@ -4123,7 +3856,7 @@ int varlink_server_bind_method(VarlinkServer *s, const char *method, VarlinkMeth return 0; } -int varlink_server_bind_method_many_internal(VarlinkServer *s, ...) { +_public_ int sd_varlink_server_bind_method_many_internal(sd_varlink_server *s, ...) { va_list ap; int r = 0; @@ -4131,16 +3864,16 @@ int varlink_server_bind_method_many_internal(VarlinkServer *s, ...) { va_start(ap, s); for (;;) { - VarlinkMethod callback; + sd_varlink_method_t callback; const char *method; method = va_arg(ap, const char *); if (!method) break; - callback = va_arg(ap, VarlinkMethod); + callback = va_arg(ap, sd_varlink_method_t); - r = varlink_server_bind_method(s, method, callback); + r = sd_varlink_server_bind_method(s, method, callback); if (r < 0) break; } @@ -4149,7 +3882,7 @@ int varlink_server_bind_method_many_internal(VarlinkServer *s, ...) { return r; } -int varlink_server_bind_connect(VarlinkServer *s, VarlinkConnect callback) { +_public_ int sd_varlink_server_bind_connect(sd_varlink_server *s, sd_varlink_connect_t callback) { assert_return(s, -EINVAL); if (callback && s->connect_callback && callback != s->connect_callback) @@ -4159,7 +3892,7 @@ int varlink_server_bind_connect(VarlinkServer *s, VarlinkConnect callback) { return 0; } -int varlink_server_bind_disconnect(VarlinkServer *s, VarlinkDisconnect callback) { +_public_ int sd_varlink_server_bind_disconnect(sd_varlink_server *s, sd_varlink_disconnect_t callback) { assert_return(s, -EINVAL); if (callback && s->disconnect_callback && callback != s->disconnect_callback) @@ -4169,7 +3902,7 @@ int varlink_server_bind_disconnect(VarlinkServer *s, VarlinkDisconnect callback) return 0; } -int varlink_server_add_interface(VarlinkServer *s, const VarlinkInterface *interface) { +_public_ int sd_varlink_server_add_interface(sd_varlink_server *s, const sd_varlink_interface *interface) { int r; assert_return(s, -EINVAL); @@ -4183,12 +3916,12 @@ int varlink_server_add_interface(VarlinkServer *s, const VarlinkInterface *inter if (r < 0) return r; - for (const VarlinkSymbol *const*symbol = interface->symbols; *symbol; symbol++) { + for (const sd_varlink_symbol *const*symbol = interface->symbols; *symbol; symbol++) { _cleanup_free_ char *j = NULL; /* We only ever want to validate method calls/replies and errors against the interface * definitions, hence don't bother with the type symbols */ - if (!IN_SET((*symbol)->symbol_type, VARLINK_METHOD, VARLINK_ERROR)) + if (!IN_SET((*symbol)->symbol_type, SD_VARLINK_METHOD, SD_VARLINK_ERROR)) continue; j = strjoin(interface->name, ".", (*symbol)->name); @@ -4205,7 +3938,7 @@ int varlink_server_add_interface(VarlinkServer *s, const VarlinkInterface *inter return 0; } -int varlink_server_add_interface_many_internal(VarlinkServer *s, ...) { +_public_ int sd_varlink_server_add_interface_many_internal(sd_varlink_server *s, ...) { va_list ap; int r = 0; @@ -4213,11 +3946,11 @@ int varlink_server_add_interface_many_internal(VarlinkServer *s, ...) { va_start(ap, s); for (;;) { - const VarlinkInterface *interface = va_arg(ap, const VarlinkInterface*); + const sd_varlink_interface *interface = va_arg(ap, const sd_varlink_interface*); if (!interface) break; - r = varlink_server_add_interface(s, interface); + r = sd_varlink_server_add_interface(s, interface); if (r < 0) break; } @@ -4226,7 +3959,7 @@ int varlink_server_add_interface_many_internal(VarlinkServer *s, ...) { return r; } -unsigned varlink_server_connections_max(VarlinkServer *s) { +_public_ unsigned sd_varlink_server_connections_max(sd_varlink_server *s) { int dts; /* If a server is specified, return the setting for that server, otherwise the default value */ @@ -4243,21 +3976,21 @@ unsigned varlink_server_connections_max(VarlinkServer *s) { return VARLINK_DEFAULT_CONNECTIONS_MAX; } -unsigned varlink_server_connections_per_uid_max(VarlinkServer *s) { +_public_ unsigned sd_varlink_server_connections_per_uid_max(sd_varlink_server *s) { unsigned m; if (s) return s->connections_per_uid_max; /* Make sure to never use up more than ¾th of available connections for a single user */ - m = varlink_server_connections_max(NULL); + m = sd_varlink_server_connections_max(NULL); if (VARLINK_DEFAULT_CONNECTIONS_PER_UID_MAX > m) return m / 4 * 3; return VARLINK_DEFAULT_CONNECTIONS_PER_UID_MAX; } -int varlink_server_set_connections_per_uid_max(VarlinkServer *s, unsigned m) { +_public_ int sd_varlink_server_set_connections_per_uid_max(sd_varlink_server *s, unsigned m) { assert_return(s, -EINVAL); assert_return(m > 0, -EINVAL); @@ -4265,7 +3998,7 @@ int varlink_server_set_connections_per_uid_max(VarlinkServer *s, unsigned m) { return 0; } -int varlink_server_set_connections_max(VarlinkServer *s, unsigned m) { +_public_ int sd_varlink_server_set_connections_max(sd_varlink_server *s, unsigned m) { assert_return(s, -EINVAL); assert_return(m > 0, -EINVAL); @@ -4273,7 +4006,7 @@ int varlink_server_set_connections_max(VarlinkServer *s, unsigned m) { return 0; } -unsigned varlink_server_current_connections(VarlinkServer *s) { +_public_ unsigned sd_varlink_server_current_connections(sd_varlink_server *s) { if (!s) /* Unallocated servers have zero connections */ return 0; @@ -4281,93 +4014,13 @@ unsigned varlink_server_current_connections(VarlinkServer *s) { return s->n_connections; } -int varlink_server_set_description(VarlinkServer *s, const char *description) { +_public_ int sd_varlink_server_set_description(sd_varlink_server *s, const char *description) { assert_return(s, -EINVAL); return free_and_strdup(&s->description, description); } -int varlink_server_serialize(VarlinkServer *s, FILE *f, FDSet *fds) { - assert(f); - assert(fds); - - if (!s) - return 0; - - LIST_FOREACH(sockets, ss, s->sockets) { - int copy; - - assert(ss->address); - assert(ss->fd >= 0); - - fprintf(f, "varlink-server-socket-address=%s", ss->address); - - /* If we fail to serialize the fd, it will be considered an error during deserialization */ - copy = fdset_put_dup(fds, ss->fd); - if (copy < 0) - return copy; - - fprintf(f, " varlink-server-socket-fd=%i", copy); - - fputc('\n', f); - } - - return 0; -} - -int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *fds) { - _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL; - _cleanup_free_ char *address = NULL; - const char *v = ASSERT_PTR(value); - int r, fd = -EBADF; - char *buf; - size_t n; - - assert(s); - assert(fds); - - n = strcspn(v, " "); - address = strndup(v, n); - if (!address) - return log_oom_debug(); - - if (v[n] != ' ') - return varlink_server_log_errno(s, SYNTHETIC_ERRNO(EINVAL), - "Failed to deserialize VarlinkServerSocket: %s: %m", value); - v = startswith(v + n + 1, "varlink-server-socket-fd="); - if (!v) - return varlink_server_log_errno(s, SYNTHETIC_ERRNO(EINVAL), - "Failed to deserialize VarlinkServerSocket fd %s: %m", value); - - n = strcspn(v, " "); - buf = strndupa_safe(v, n); - - fd = parse_fd(buf); - if (fd < 0) - return varlink_server_log_errno(s, fd, "Unable to parse VarlinkServerSocket varlink-server-socket-fd=%s: %m", buf); - if (!fdset_contains(fds, fd)) - return varlink_server_log_errno(s, SYNTHETIC_ERRNO(EBADF), - "VarlinkServerSocket varlink-server-socket-fd= has unknown fd %d: %m", fd); - - ss = new(VarlinkServerSocket, 1); - if (!ss) - return log_oom_debug(); - - *ss = (VarlinkServerSocket) { - .server = s, - .address = TAKE_PTR(address), - .fd = fdset_remove(fds, fd), - }; - - r = varlink_server_add_socket_event_source(s, ss, SD_EVENT_PRIORITY_NORMAL); - if (r < 0) - return varlink_server_log_errno(s, r, "Failed to add VarlinkServerSocket event source to the event loop: %m"); - - LIST_PREPEND(sockets, s->sockets, TAKE_PTR(ss)); - return 0; -} - -int varlink_invocation(VarlinkInvocationFlags flags) { +_public_ int sd_varlink_invocation(sd_varlink_invocation_flags_t flags) { _cleanup_strv_free_ char **names = NULL; int r, b; socklen_t l = sizeof(b); @@ -4389,10 +4042,10 @@ int varlink_invocation(VarlinkInvocationFlags flags) { if (!strv_equal(names, STRV_MAKE("varlink"))) return false; - if (FLAGS_SET(flags, VARLINK_ALLOW_LISTEN|VARLINK_ALLOW_ACCEPT)) /* Both flags set? Then allow everything */ + if (FLAGS_SET(flags, SD_VARLINK_ALLOW_LISTEN|SD_VARLINK_ALLOW_ACCEPT)) /* Both flags set? Then allow everything */ return true; - if ((flags & (VARLINK_ALLOW_LISTEN|VARLINK_ALLOW_ACCEPT)) == 0) /* Neither is set, then fail */ + if ((flags & (SD_VARLINK_ALLOW_LISTEN|SD_VARLINK_ALLOW_ACCEPT)) == 0) /* Neither is set, then fail */ return -EISCONN; if (getsockopt(SD_LISTEN_FDS_START, SOL_SOCKET, SO_ACCEPTCONN, &b, &l) < 0) @@ -4400,26 +4053,26 @@ int varlink_invocation(VarlinkInvocationFlags flags) { assert(l == sizeof(b)); - if (!FLAGS_SET(flags, b ? VARLINK_ALLOW_LISTEN : VARLINK_ALLOW_ACCEPT)) + if (!FLAGS_SET(flags, b ? SD_VARLINK_ALLOW_LISTEN : SD_VARLINK_ALLOW_ACCEPT)) return -EISCONN; return true; } -int varlink_error_to_errno(const char *error, sd_json_variant *parameters) { +_public_ int sd_varlink_error_to_errno(const char *error, sd_json_variant *parameters) { static const struct { const char *error; int value; } table[] = { - { VARLINK_ERROR_DISCONNECTED, -ECONNRESET }, - { VARLINK_ERROR_TIMEOUT, -ETIMEDOUT }, - { VARLINK_ERROR_PROTOCOL, -EPROTO }, - { VARLINK_ERROR_INTERFACE_NOT_FOUND, -EADDRNOTAVAIL }, - { VARLINK_ERROR_METHOD_NOT_FOUND, -ENXIO }, - { VARLINK_ERROR_METHOD_NOT_IMPLEMENTED, -ENOTTY }, - { VARLINK_ERROR_INVALID_PARAMETER, -EINVAL }, - { VARLINK_ERROR_PERMISSION_DENIED, -EACCES }, - { VARLINK_ERROR_EXPECTED_MORE, -EBADE }, + { SD_VARLINK_ERROR_DISCONNECTED, -ECONNRESET }, + { SD_VARLINK_ERROR_TIMEOUT, -ETIMEDOUT }, + { SD_VARLINK_ERROR_PROTOCOL, -EPROTO }, + { SD_VARLINK_ERROR_INTERFACE_NOT_FOUND, -EADDRNOTAVAIL }, + { SD_VARLINK_ERROR_METHOD_NOT_FOUND, -ENXIO }, + { SD_VARLINK_ERROR_METHOD_NOT_IMPLEMENTED, -ENOTTY }, + { SD_VARLINK_ERROR_INVALID_PARAMETER, -EINVAL }, + { SD_VARLINK_ERROR_PERMISSION_DENIED, -EACCES }, + { SD_VARLINK_ERROR_EXPECTED_MORE, -EBADE }, }; if (!error) @@ -4429,7 +4082,7 @@ int varlink_error_to_errno(const char *error, sd_json_variant *parameters) { if (streq(error, t->error)) return t->value; - if (streq(error, VARLINK_ERROR_SYSTEM) && parameters) { + if (streq(error, SD_VARLINK_ERROR_SYSTEM) && parameters) { sd_json_variant *e; e = sd_json_variant_by_key(parameters, "errno"); @@ -4444,51 +4097,3 @@ int varlink_error_to_errno(const char *error, sd_json_variant *parameters) { return -EBADR; /* Catch-all */ } - -int varlink_many_notifyb(Set *s, ...) { - int r; - - /* Equivalent to varlink_notifyb(), but does this for each entry of the supplied set of Varlink connections */ - - if (set_isempty(s)) - return 0; - - _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; - va_list ap; - va_start(ap, s); - r = sd_json_buildv(¶meters, ap); - va_end(ap); - if (r < 0) - return r; - - int ret = 1; - Varlink *link; - SET_FOREACH(link, s) - RET_GATHER(ret, varlink_notify(link, parameters)); - - return ret; -} - -int varlink_many_reply(Set *s, sd_json_variant *parameters) { - if (set_isempty(s)) - return 0; - - int ret = 1; - Varlink *link; - SET_FOREACH(link, s) - RET_GATHER(ret, varlink_reply(link, parameters)); - - return ret; -} - -int varlink_many_error(Set *s, const char *error_id, sd_json_variant *parameters) { - if (set_isempty(s)) - return 0; - - int ret = 1; - Varlink *link; - SET_FOREACH(link, s) - RET_GATHER(ret, varlink_error(link, error_id, parameters)); - - return ret; -} diff --git a/src/libsystemd/sd-varlink/varlink-idl-util.h b/src/libsystemd/sd-varlink/varlink-idl-util.h new file mode 100644 index 0000000000..fab836a723 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-idl-util.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "sd-varlink-idl.h" + +#include "macro.h" + +int varlink_idl_parse(const char *text, unsigned *ret_line, unsigned *ret_column, sd_varlink_interface **ret); +sd_varlink_interface* varlink_interface_free(sd_varlink_interface *interface); +DEFINE_TRIVIAL_CLEANUP_FUNC(sd_varlink_interface*, varlink_interface_free); + +bool varlink_idl_field_name_is_valid(const char *name); +bool varlink_idl_symbol_name_is_valid(const char *name); +bool varlink_idl_interface_name_is_valid(const char *name); + +int varlink_idl_qualified_symbol_name_is_valid(const char *name); + +int varlink_idl_consistent(const sd_varlink_interface *interface, int level); + +const sd_varlink_symbol* varlink_idl_find_symbol(const sd_varlink_interface *interface, sd_varlink_symbol_type_t type, const char *name); +const sd_varlink_field* varlink_idl_find_field(const sd_varlink_symbol *symbol, const char *name); + +int varlink_idl_validate_method_call(const sd_varlink_symbol *method, sd_json_variant *v, const char **bad_field); +int varlink_idl_validate_method_reply(const sd_varlink_symbol *method, sd_json_variant *v, const char **bad_field); +int varlink_idl_validate_error(const sd_varlink_symbol *error, sd_json_variant *v, const char **bad_field); diff --git a/src/libsystemd/sd-varlink/varlink-internal.h b/src/libsystemd/sd-varlink/varlink-internal.h new file mode 100644 index 0000000000..5469d9e345 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-internal.h @@ -0,0 +1,249 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include <sys/socket.h> + +#include "sd-event.h" +#include "sd-varlink.h" + +#include "hashmap.h" +#include "list.h" + +typedef enum VarlinkState { + /* Client side states */ + VARLINK_IDLE_CLIENT, + VARLINK_AWAITING_REPLY, + VARLINK_AWAITING_REPLY_MORE, + VARLINK_CALLING, + VARLINK_CALLED, + VARLINK_COLLECTING, + VARLINK_COLLECTING_REPLY, + VARLINK_PROCESSING_REPLY, + + /* Server side states */ + VARLINK_IDLE_SERVER, + VARLINK_PROCESSING_METHOD, + VARLINK_PROCESSING_METHOD_MORE, + VARLINK_PROCESSING_METHOD_ONEWAY, + VARLINK_PROCESSED_METHOD, + VARLINK_PENDING_METHOD, + VARLINK_PENDING_METHOD_MORE, + + /* Common states (only during shutdown) */ + VARLINK_PENDING_DISCONNECT, + VARLINK_PENDING_TIMEOUT, + VARLINK_PROCESSING_DISCONNECT, + VARLINK_PROCESSING_TIMEOUT, + VARLINK_PROCESSING_FAILURE, + VARLINK_DISCONNECTED, + + _VARLINK_STATE_MAX, + _VARLINK_STATE_INVALID = -EINVAL, +} VarlinkState; + +/* Tests whether we are not yet disconnected. Note that this is true during all states where the connection + * is still good for something, and false only when it's dead for good. This means: when we are + * asynchronously connecting to a peer and the connect() is still pending, then this will return 'true', as + * the connection is still good, and we are likely to be able to properly operate on it soon. */ +#define VARLINK_STATE_IS_ALIVE(state) \ + IN_SET(state, \ + VARLINK_IDLE_CLIENT, \ + VARLINK_AWAITING_REPLY, \ + VARLINK_AWAITING_REPLY_MORE, \ + VARLINK_CALLING, \ + VARLINK_CALLED, \ + VARLINK_COLLECTING, \ + VARLINK_COLLECTING_REPLY, \ + VARLINK_PROCESSING_REPLY, \ + VARLINK_IDLE_SERVER, \ + VARLINK_PROCESSING_METHOD, \ + VARLINK_PROCESSING_METHOD_MORE, \ + VARLINK_PROCESSING_METHOD_ONEWAY, \ + VARLINK_PROCESSED_METHOD, \ + VARLINK_PENDING_METHOD, \ + VARLINK_PENDING_METHOD_MORE) + +typedef struct VarlinkJsonQueueItem VarlinkJsonQueueItem; + +/* A queued message we shall write into the socket, along with the file descriptors to send at the same + * time. This queue item binds them together so that message/fd boundaries are maintained throughout the + * whole pipeline. */ +struct VarlinkJsonQueueItem { + LIST_FIELDS(VarlinkJsonQueueItem, queue); + sd_json_variant *data; + size_t n_fds; + int fds[]; +}; + +struct sd_varlink { + unsigned n_ref; + + sd_varlink_server *server; + + VarlinkState state; + bool connecting; /* This boolean indicates whether the socket fd we are operating on is currently + * processing an asynchronous connect(). In that state we watch the socket for + * EPOLLOUT, but we refrain from calling read() or write() on the socket as that + * will trigger ENOTCONN. Note that this boolean is kept separate from the + * VarlinkState above on purpose: while the connect() is still not complete we + * already want to allow queuing of messages and similar. Thus it's nice to keep + * these two state concepts separate: the VarlinkState encodes what our own view of + * the connection is, i.e. whether we think it's a server, a client, and has + * something queued already, while 'connecting' tells us a detail about the + * transport used below, that should have no effect on how we otherwise accept and + * process operations from the user. + * + * Or to say this differently: VARLINK_STATE_IS_ALIVE(state) tells you whether the + * connection is good to use, even if it might not be fully connected + * yet. connecting=true then informs you that actually we are still connecting, and + * the connection is actually not established yet and thus any requests you enqueue + * now will still work fine but will be queued only, not sent yet, but that + * shouldn't stop you from using the connection, since eventually whatever you queue + * *will* be sent. + * + * Or to say this even differently: 'state' is a high-level ("application layer" + * high, if you so will) state, while 'conecting' is a low-level ("transport layer" + * low, if you so will) state, and while they are not entirely unrelated and + * sometimes propagate effects to each other they are only asynchronously connected + * at most. */ + unsigned n_pending; + + int input_fd; + int output_fd; + + char *input_buffer; /* valid data starts at input_buffer_index, ends at input_buffer_index+input_buffer_size */ + size_t input_buffer_index; + size_t input_buffer_size; + size_t input_buffer_unscanned; + + void *input_control_buffer; + size_t input_control_buffer_size; + + char *output_buffer; /* valid data starts at output_buffer_index, ends at output_buffer_index+output_buffer_size */ + size_t output_buffer_index; + size_t output_buffer_size; + + int *input_fds; /* file descriptors associated with the data in input_buffer (for fd passing) */ + size_t n_input_fds; + + int *output_fds; /* file descriptors associated with the data in output_buffer (for fd passing) */ + size_t n_output_fds; + + /* Further messages to output not yet formatted into text, and thus not included in output_buffer + * yet. We keep them separate from output_buffer, to not violate fd message boundaries: we want that + * each fd that is sent is associated with its fds, and that fds cannot be accidentally associated + * with preceding or following messages. */ + LIST_HEAD(VarlinkJsonQueueItem, output_queue); + VarlinkJsonQueueItem *output_queue_tail; + + /* The fds to associate with the next message that is about to be enqueued. The user first pushes the + * fds it intends to send via varlink_push_fd() into this queue, and then once the message data is + * submitted we'll combine the fds and the message data into one. */ + int *pushed_fds; + size_t n_pushed_fds; + + sd_varlink_reply_t reply_callback; + + sd_json_variant *current; + sd_json_variant *current_collected; + sd_varlink_reply_flags_t current_reply_flags; + sd_varlink_symbol *current_method; + + int peer_pidfd; + struct ucred ucred; + bool ucred_acquired:1; + + bool write_disconnected:1; + bool read_disconnected:1; + bool prefer_read:1; + bool prefer_write:1; + bool got_pollhup:1; + + bool allow_fd_passing_input:1; + bool allow_fd_passing_output:1; + + bool output_buffer_sensitive:1; /* whether to erase the output buffer after writing it to the socket */ + bool input_sensitive:1; /* Whether incoming messages might be sensitive */ + + int af; /* address family if socket; AF_UNSPEC if not socket; negative if not known */ + + usec_t timestamp; + usec_t timeout; + + void *userdata; + char *description; + + sd_event *event; + sd_event_source *input_event_source; + sd_event_source *output_event_source; + sd_event_source *time_event_source; + sd_event_source *quit_event_source; + sd_event_source *defer_event_source; + + pid_t exec_pid; +}; + +typedef struct VarlinkServerSocket VarlinkServerSocket; + +struct VarlinkServerSocket { + sd_varlink_server *server; + + int fd; + char *address; + + sd_event_source *event_source; + + LIST_FIELDS(VarlinkServerSocket, sockets); +}; + +struct sd_varlink_server { + unsigned n_ref; + sd_varlink_server_flags_t flags; + + LIST_HEAD(VarlinkServerSocket, sockets); + + Hashmap *methods; /* Fully qualified symbol name of a method → VarlinkMethod */ + Hashmap *interfaces; /* Fully qualified interface name → VarlinkInterface* */ + Hashmap *symbols; /* Fully qualified symbol name of method/error → VarlinkSymbol* */ + sd_varlink_connect_t connect_callback; + sd_varlink_disconnect_t disconnect_callback; + + sd_event *event; + int64_t event_priority; + + unsigned n_connections; + Hashmap *by_uid; /* UID_TO_PTR(uid) → UINT_TO_PTR(n_connections) */ + + void *userdata; + char *description; + + unsigned connections_max; + unsigned connections_per_uid_max; + + bool exit_on_idle; +}; + +#define varlink_log_errno(v, error, fmt, ...) \ + log_debug_errno(error, "%s: " fmt, varlink_description(v), ##__VA_ARGS__) + +#define varlink_log(v, fmt, ...) \ + log_debug("%s: " fmt, varlink_description(v), ##__VA_ARGS__) + +#define varlink_server_log_errno(s, error, fmt, ...) \ + log_debug_errno(error, "%s: " fmt, varlink_server_description(s), ##__VA_ARGS__) + +#define varlink_server_log(s, fmt, ...) \ + log_debug("%s: " fmt, varlink_server_description(s), ##__VA_ARGS__) + +static inline const char* varlink_description(sd_varlink *v) { + return (v ? v->description : NULL) ?: "varlink"; +} + +static inline const char* varlink_server_description(sd_varlink_server *s) { + return (s ? s->description : NULL) ?: "varlink"; +} + +VarlinkServerSocket* varlink_server_socket_free(VarlinkServerSocket *ss); +DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServerSocket *, varlink_server_socket_free); + +int varlink_server_add_socket_event_source(sd_varlink_server *s, VarlinkServerSocket *ss, int64_t priority); diff --git a/src/shared/varlink-io.systemd.c b/src/libsystemd/sd-varlink/varlink-io.systemd.c index cdfe9ac263..e2511265a3 100644 --- a/src/shared/varlink-io.systemd.c +++ b/src/libsystemd/sd-varlink/varlink-io.systemd.c @@ -3,16 +3,16 @@ #include "varlink-io.systemd.h" /* These are local errors that never cross the wire, and are our own invention */ -static VARLINK_DEFINE_ERROR(Disconnected); -static VARLINK_DEFINE_ERROR(TimedOut); -static VARLINK_DEFINE_ERROR(Protocol); +static SD_VARLINK_DEFINE_ERROR(Disconnected); +static SD_VARLINK_DEFINE_ERROR(TimedOut); +static SD_VARLINK_DEFINE_ERROR(Protocol); /* This one we invented, and use for generically propagating system errors (errno) to clients */ -static VARLINK_DEFINE_ERROR( +static SD_VARLINK_DEFINE_ERROR( System, - VARLINK_DEFINE_FIELD(errno, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_FIELD(errno, SD_VARLINK_INT, 0)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd, "io.systemd", &vl_error_Disconnected, diff --git a/src/libsystemd/sd-varlink/varlink-io.systemd.h b/src/libsystemd/sd-varlink/varlink-io.systemd.h new file mode 100644 index 0000000000..6525e590a0 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-io.systemd.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "sd-varlink-idl.h" + +extern const sd_varlink_interface vl_interface_io_systemd; diff --git a/src/libsystemd/sd-varlink/varlink-org.varlink.service.c b/src/libsystemd/sd-varlink/varlink-org.varlink.service.c new file mode 100644 index 0000000000..7b7121eb41 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-org.varlink.service.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "varlink-org.varlink.service.h" + +static SD_VARLINK_DEFINE_METHOD( + GetInfo, + SD_VARLINK_DEFINE_OUTPUT(vendor, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(product, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(version, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(url, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(interfaces, SD_VARLINK_STRING, SD_VARLINK_ARRAY)); + +static SD_VARLINK_DEFINE_METHOD( + GetInterfaceDescription, + SD_VARLINK_DEFINE_INPUT(interface, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(description, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_ERROR( + InterfaceNotFound, + SD_VARLINK_DEFINE_FIELD(interface, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_ERROR( + MethodNotFound, + SD_VARLINK_DEFINE_FIELD(method, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_ERROR( + MethodNotImplemented, + SD_VARLINK_DEFINE_FIELD(method, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_ERROR( + InvalidParameter, + SD_VARLINK_DEFINE_FIELD(parameter, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_ERROR(PermissionDenied); + +static SD_VARLINK_DEFINE_ERROR(ExpectedMore); + +/* As per https://varlink.org/Service */ +SD_VARLINK_DEFINE_INTERFACE( + org_varlink_service, + "org.varlink.service", + &vl_method_GetInfo, + &vl_method_GetInterfaceDescription, + &vl_error_InterfaceNotFound, + &vl_error_MethodNotFound, + &vl_error_MethodNotImplemented, + &vl_error_InvalidParameter, + &vl_error_PermissionDenied, + &vl_error_ExpectedMore); diff --git a/src/libsystemd/sd-varlink/varlink-org.varlink.service.h b/src/libsystemd/sd-varlink/varlink-org.varlink.service.h new file mode 100644 index 0000000000..26907eee55 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-org.varlink.service.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "sd-varlink-idl.h" + +extern const sd_varlink_interface vl_interface_org_varlink_service; diff --git a/src/libsystemd/sd-varlink/varlink-util.c b/src/libsystemd/sd-varlink/varlink-util.c new file mode 100644 index 0000000000..cfaab22700 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-util.c @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "errno-util.h" +#include "varlink-internal.h" +#include "varlink-util.h" + +int varlink_get_peer_pidref(sd_varlink *v, PidRef *ret) { + int r; + + assert_return(v, -EINVAL); + assert_return(ret, -EINVAL); + + /* Returns r > 0 if we acquired the pidref via SO_PEERPIDFD (i.e. if we can use it for + * authentication). Returns == 0 if we didn't, and the pidref should not be used for + * authentication. */ + + int pidfd = sd_varlink_get_peer_pidfd(v); + if (pidfd < 0) { + if (!ERRNO_IS_NEG_NOT_SUPPORTED(pidfd)) + return pidfd; + + pid_t pid; + r = sd_varlink_get_peer_pid(v, &pid); + if (r < 0) + return r; + + r = pidref_set_pid(ret, pid); + if (r < 0) + return r; + + return 0; /* didn't get pidfd securely */ + } + + r = pidref_set_pidfd(ret, pidfd); + if (r < 0) + return r; + + return 1; /* got pidfd securely */ +} + +int varlink_call_and_log( + sd_varlink *v, + const char *method, + sd_json_variant *parameters, + sd_json_variant **ret_parameters) { + + sd_json_variant *reply = NULL; + const char *error_id = NULL; + int r; + + assert_return(v, -EINVAL); + assert_return(method, -EINVAL); + + r = sd_varlink_call(v, method, parameters, &reply, &error_id); + if (r < 0) + return log_error_errno(r, "Failed to issue %s() varlink call: %m", method); + if (error_id) + return log_error_errno(sd_varlink_error_to_errno(error_id, reply), + "Failed to issue %s() varlink call: %s", method, error_id); + + if (ret_parameters) + *ret_parameters = TAKE_PTR(reply); + + return 0; +} + +int varlink_callb_and_log( + sd_varlink *v, + const char *method, + sd_json_variant **ret_parameters, + ...) { + + _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; + va_list ap; + int r; + + assert_return(v, -EINVAL); + assert_return(method, -EINVAL); + + va_start(ap, ret_parameters); + r = sd_json_buildv(¶meters, ap); + va_end(ap); + if (r < 0) + return log_error_errno(r, "Failed to build JSON message: %m"); + + return varlink_call_and_log(v, method, parameters, ret_parameters); +} + + +int varlink_many_notifyb(Set *s, ...) { + int r; + + /* Equivalent to varlink_notifyb(), but does this for each entry of the supplied set of Varlink connections */ + + if (set_isempty(s)) + return 0; + + _cleanup_(sd_json_variant_unrefp) sd_json_variant *parameters = NULL; + va_list ap; + va_start(ap, s); + r = sd_json_buildv(¶meters, ap); + va_end(ap); + if (r < 0) + return r; + + int ret = 1; + sd_varlink *link; + SET_FOREACH(link, s) + RET_GATHER(ret, sd_varlink_notify(link, parameters)); + + return ret; +} + +int varlink_many_reply(Set *s, sd_json_variant *parameters) { + if (set_isempty(s)) + return 0; + + int r = 1; + sd_varlink *link; + SET_FOREACH(link, s) + RET_GATHER(r, sd_varlink_reply(link, parameters)); + + return r; +} + +int varlink_many_error(Set *s, const char *error_id, sd_json_variant *parameters) { + if (set_isempty(s)) + return 0; + + int r = 1; + sd_varlink *link; + SET_FOREACH(link, s) + RET_GATHER(r, sd_varlink_error(link, error_id, parameters)); + + return r; +} diff --git a/src/libsystemd/sd-varlink/varlink-util.h b/src/libsystemd/sd-varlink/varlink-util.h new file mode 100644 index 0000000000..3f532bf140 --- /dev/null +++ b/src/libsystemd/sd-varlink/varlink-util.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "sd-varlink.h" + +#include "pidref.h" +#include "set.h" + +int varlink_get_peer_pidref(sd_varlink *v, PidRef *ret); + +int varlink_call_and_log(sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters); +int varlink_callb_and_log(sd_varlink *v, const char *method, sd_json_variant **ret_parameters, ...); +#define varlink_callbo_and_log(v, method, ret_parameters, ...) \ + varlink_callb_and_log((v), (method), (ret_parameters), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +int varlink_many_notifyb(Set *s, ...); +#define varlink_many_notifybo(s, ...) \ + varlink_many_notifyb((s), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) +int varlink_many_reply(Set *s, sd_json_variant *parameters); +int varlink_many_error(Set *s, const char *error_id, sd_json_variant *parameters); diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c index 5b3538d416..fb64bde920 100644 --- a/src/machine/machine-varlink.c +++ b/src/machine/machine-varlink.c @@ -4,6 +4,7 @@ #include "sd-id128.h" #include "sd-json.h" +#include "sd-varlink.h" #include "bus-polkit.h" #include "hostname-util.h" @@ -15,7 +16,7 @@ #include "process-util.h" #include "socket-util.h" #include "string-util.h" -#include "varlink.h" +#include "varlink-util.h" static JSON_DISPATCH_ENUM_DEFINE(dispatch_machine_class, MachineClass, machine_class_from_string); @@ -121,7 +122,7 @@ static int machine_cid(const char *name, sd_json_variant *variant, sd_json_dispa return 0; } -int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Manager *manager = ASSERT_PTR(userdata); _cleanup_(machine_freep) Machine *machine = NULL; int r; @@ -146,7 +147,7 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod if (r < 0) return r; - r = varlink_dispatch(link, parameters, dispatch_table, machine); + r = sd_varlink_dispatch(link, parameters, dispatch_table, machine); if (r != 0) return r; @@ -168,7 +169,7 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod r = machine_link(manager, machine); if (r == -EEXIST) - return varlink_error(link, "io.systemd.Machine.MachineExists", NULL); + return sd_varlink_error(link, "io.systemd.Machine.MachineExists", NULL); if (r < 0) return r; @@ -185,5 +186,5 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod /* the manager will free this machine */ TAKE_PTR(machine); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } diff --git a/src/machine/machine-varlink.h b/src/machine/machine-varlink.h index f9df0ed2a9..3b5eb2c8f7 100644 --- a/src/machine/machine-varlink.h +++ b/src/machine/machine-varlink.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink.h" +#include "sd-varlink.h" -int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); +int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c index 7c74c0b1a2..8e7ade9aec 100644 --- a/src/machine/machined-varlink.c +++ b/src/machine/machined-varlink.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-varlink.h" + #include "format-util.h" #include "hostname-util.h" #include "json-util.h" @@ -8,7 +10,6 @@ #include "mkdir.h" #include "socket-util.h" #include "user-util.h" -#include "varlink.h" #include "varlink-io.systemd.Machine.h" #include "varlink-io.systemd.UserDatabase.h" @@ -142,7 +143,7 @@ static int user_lookup_name(Manager *m, const char *name, uid_t *ret_uid, char * return 0; } -static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, @@ -163,21 +164,21 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.Machine")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (uid_is_valid(p.uid)) r = user_lookup_uid(m, p.uid, &found_name, &found_real_name); else if (p.user_name) r = user_lookup_name(m, p.user_name, &found_uid, &found_real_name); else - return varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); if (r == -ESRCH) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -185,13 +186,13 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, un = found_name ?: p.user_name; if (!user_match_lookup_parameters(&p, un, uid)) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_user_json(un, uid, found_real_name, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } static int build_group_json(const char *group_name, gid_t gid, const char *description, sd_json_variant **ret) { @@ -308,7 +309,7 @@ static int group_lookup_name(Manager *m, const char *name, gid_t *ret_gid, char return 0; } -static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, @@ -329,21 +330,21 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.Machine")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (gid_is_valid(p.gid)) r = group_lookup_gid(m, p.gid, &found_name, &found_description); else if (p.group_name) r = group_lookup_name(m, p.group_name, (uid_t*) &found_gid, &found_description); else - return varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); if (r == -ESRCH) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -351,16 +352,16 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters gn = found_name ?: p.group_name; if (!group_match_lookup_parameters(&p, gn, gid)) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_group_json(gn, gid, found_description, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } -static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_memberships(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_STRICT }, @@ -374,18 +375,18 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.Machine")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); /* We don't support auxiliary groups for machines. */ - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } -static int list_machine_one(Varlink *link, Machine *m, bool more) { +static int list_machine_one(sd_varlink *link, Machine *m, bool more) { int r; assert(link); @@ -409,12 +410,12 @@ static int list_machine_one(Varlink *link, Machine *m, bool more) { return r; if (more) - return varlink_notify(link, v); + return sd_varlink_notify(link, v); - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } -static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +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; @@ -427,23 +428,23 @@ static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMet assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, 0); + r = sd_varlink_dispatch(link, parameters, dispatch_table, 0); if (r != 0) return r; if (mn) { if (!hostname_is_valid(mn, /* flags= */ VALID_HOSTNAME_DOT_HOST)) - return varlink_error_invalid_parameter_name(link, "name"); + return sd_varlink_error_invalid_parameter_name(link, "name"); Machine *machine = hashmap_get(m->machines, mn); if (!machine) - return varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL); + return sd_varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL); return list_machine_one(link, machine, /* more= */ false); } - if (!FLAGS_SET(flags, VARLINK_METHOD_MORE)) - return varlink_error(link, VARLINK_ERROR_EXPECTED_MORE, NULL); + if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE)) + return sd_varlink_error(link, SD_VARLINK_ERROR_EXPECTED_MORE, NULL); Machine *previous = NULL, *i; HASHMAP_FOREACH(i, m->machines) { @@ -459,11 +460,11 @@ static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMet if (previous) return list_machine_one(link, previous, /* more= */ false); - return varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL); + return sd_varlink_error(link, "io.systemd.Machine.NoSuchMachine", NULL); } static int manager_varlink_init_userdb(Manager *m) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); @@ -471,17 +472,17 @@ static int manager_varlink_init_userdb(Manager *m) { if (m->varlink_userdb_server) return 0; - r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(s, m); + sd_varlink_server_set_userdata(s, m); - r = varlink_server_add_interface(s, &vl_interface_io_systemd_UserDatabase); + r = sd_varlink_server_add_interface(s, &vl_interface_io_systemd_UserDatabase); if (r < 0) return log_error_errno(r, "Failed to add UserDatabase interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( s, "io.systemd.UserDatabase.GetUserRecord", vl_method_get_user_record, "io.systemd.UserDatabase.GetGroupRecord", vl_method_get_group_record, @@ -491,11 +492,11 @@ static int manager_varlink_init_userdb(Manager *m) { (void) mkdir_p("/run/systemd/userdb", 0755); - r = varlink_server_listen_address(s, "/run/systemd/userdb/io.systemd.Machine", 0666); + r = sd_varlink_server_listen_address(s, "/run/systemd/userdb/io.systemd.Machine", 0666); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); @@ -504,7 +505,7 @@ static int manager_varlink_init_userdb(Manager *m) { } static int manager_varlink_init_machine(Manager *m) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); @@ -512,17 +513,17 @@ static int manager_varlink_init_machine(Manager *m) { if (m->varlink_machine_server) return 0; - r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(s, m); + sd_varlink_server_set_userdata(s, m); - r = varlink_server_add_interface(s, &vl_interface_io_systemd_Machine); + r = sd_varlink_server_add_interface(s, &vl_interface_io_systemd_Machine); if (r < 0) return log_error_errno(r, "Failed to add UserDatabase interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( s, "io.systemd.Machine.Register", vl_method_register, "io.systemd.Machine.List", vl_method_list); @@ -531,11 +532,11 @@ static int manager_varlink_init_machine(Manager *m) { (void) mkdir_p("/run/systemd/machine", 0755); - r = varlink_server_listen_address(s, "/run/systemd/machine/io.systemd.Machine", 0666); + r = sd_varlink_server_listen_address(s, "/run/systemd/machine/io.systemd.Machine", 0666); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); @@ -560,6 +561,6 @@ int manager_varlink_init(Manager *m) { void manager_varlink_done(Manager *m) { assert(m); - m->varlink_userdb_server = varlink_server_unref(m->varlink_userdb_server); - m->varlink_machine_server = varlink_server_unref(m->varlink_machine_server); + m->varlink_userdb_server = sd_varlink_server_unref(m->varlink_userdb_server); + m->varlink_machine_server = sd_varlink_server_unref(m->varlink_machine_server); } diff --git a/src/machine/machined.c b/src/machine/machined.c index 80621058a5..b2acc3f0f0 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -298,10 +298,10 @@ static bool check_idle(void *userdata) { if (m->operations) return false; - if (varlink_server_current_connections(m->varlink_userdb_server) > 0) + if (sd_varlink_server_current_connections(m->varlink_userdb_server) > 0) return false; - if (varlink_server_current_connections(m->varlink_machine_server) > 0) + if (sd_varlink_server_current_connections(m->varlink_machine_server) > 0) return false; if (!hashmap_isempty(m->polkit_registry)) diff --git a/src/machine/machined.h b/src/machine/machined.h index 9dbb76e8b6..4dbb083e8a 100644 --- a/src/machine/machined.h +++ b/src/machine/machined.h @@ -5,6 +5,7 @@ #include "sd-bus.h" #include "sd-event.h" +#include "sd-varlink.h" typedef struct Manager Manager; @@ -14,7 +15,6 @@ typedef struct Manager Manager; #include "machine-dbus.h" #include "machine.h" #include "operation.h" -#include "varlink.h" struct Manager { sd_event *event; @@ -38,8 +38,8 @@ struct Manager { LIST_HEAD(Operation, operations); unsigned n_operations; - VarlinkServer *varlink_userdb_server; - VarlinkServer *varlink_machine_server; + sd_varlink_server *varlink_userdb_server; + sd_varlink_server *varlink_machine_server; }; int manager_add_machine(Manager *m, const char *name, Machine **_machine); diff --git a/src/mountfsd/mountwork.c b/src/mountfsd/mountwork.c index cfeb8b60e8..e9d3c7a81b 100644 --- a/src/mountfsd/mountwork.c +++ b/src/mountfsd/mountwork.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "sd-daemon.h" +#include "sd-varlink.h" #include "argv-util.h" #include "bus-polkit.h" @@ -21,7 +22,6 @@ #include "process-util.h" #include "stat-util.h" #include "user-util.h" -#include "varlink.h" #include "varlink-io.systemd.MountFileSystem.h" #define ITERATIONS_MAX 64U @@ -213,7 +213,7 @@ static int determine_image_policy( return image_policy_intersect(default_policy, client_policy, ret); } -static int validate_userns(Varlink *link, int *userns_fd) { +static int validate_userns(sd_varlink *link, int *userns_fd) { int r; assert(link); @@ -230,7 +230,7 @@ static int validate_userns(Varlink *link, int *userns_fd) { if (r < 0) return r; if (r == 0) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); /* Our own host user namespace? Then close the fd, and handle it as if none was specified. */ r = is_our_namespace(*userns_fd, NAMESPACE_USER); @@ -245,9 +245,9 @@ static int validate_userns(Varlink *link, int *userns_fd) { } static int vl_method_mount_image( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, - VarlinkMethodFlags flags, + sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { @@ -284,22 +284,22 @@ static int vl_method_mount_image( sd_json_variant_sensitive(parameters); /* might contain passwords */ - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return log_debug_errno(r, "Failed to get client UID: %m"); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.image_fd_idx != UINT_MAX) { - image_fd = varlink_peek_dup_fd(link, p.image_fd_idx); + image_fd = sd_varlink_peek_dup_fd(link, p.image_fd_idx); if (image_fd < 0) return log_debug_errno(image_fd, "Failed to peek image fd from client: %m"); } if (p.userns_fd_idx != UINT_MAX) { - userns_fd = varlink_peek_dup_fd(link, p.userns_fd_idx); + userns_fd = sd_varlink_peek_dup_fd(link, p.userns_fd_idx); if (userns_fd < 0) return log_debug_errno(userns_fd, "Failed to peek user namespace fd from client: %m"); } @@ -415,11 +415,11 @@ static int vl_method_mount_image( dissect_flags, &di); if (r == -ENOPKG) - return varlink_error(link, "io.systemd.MountFileSystem.IncompatibleImage", NULL); + return sd_varlink_error(link, "io.systemd.MountFileSystem.IncompatibleImage", NULL); if (r == -ENOTUNIQ) - return varlink_error(link, "io.systemd.MountFileSystem.MultipleRootPartitionsFound", NULL); + return sd_varlink_error(link, "io.systemd.MountFileSystem.MultipleRootPartitionsFound", NULL); if (r == -ENXIO) - return varlink_error(link, "io.systemd.MountFileSystem.RootPartitionNotFound", NULL); + return sd_varlink_error(link, "io.systemd.MountFileSystem.RootPartitionNotFound", NULL); if (r == -ERFKILL) { /* The image policy refused this, let's retry after trying to get PolicyKit */ @@ -443,7 +443,7 @@ static int vl_method_mount_image( } } - return varlink_error(link, "io.systemd.MountFileSystem.DeniedByImagePolicy", NULL); + return sd_varlink_error(link, "io.systemd.MountFileSystem.DeniedByImagePolicy", NULL); } if (r < 0) return r; @@ -466,13 +466,13 @@ static int vl_method_mount_image( dissect_flags); if (r == -ENOKEY) /* new dm-verity userspace returns ENOKEY if the dm-verity signature key is not in * key chain. That's great. */ - return varlink_error(link, "io.systemd.MountFileSystem.KeyNotFound", NULL); + return sd_varlink_error(link, "io.systemd.MountFileSystem.KeyNotFound", NULL); if (r == -EBUSY) /* DM kernel subsystem is shit with returning useful errors hence we keep retrying * under the assumption that some errors are transitional. Which the errors might * not actually be. After all retries failed we return EBUSY. Let's turn that into a * generic Verity error. It's not very helpful, could mean anything, but at least it * gives client a clear idea that this has to do with Verity. */ - return varlink_error(link, "io.systemd.MountFileSystem.VerityFailure", NULL); + return sd_varlink_error(link, "io.systemd.MountFileSystem.VerityFailure", NULL); if (r < 0) return r; @@ -502,7 +502,7 @@ static int vl_method_mount_image( return r; } - fd_idx = varlink_push_fd(link, pp->fsmount_fd); + fd_idx = sd_varlink_push_fd(link, pp->fsmount_fd); if (fd_idx < 0) return fd_idx; @@ -527,7 +527,7 @@ static int vl_method_mount_image( loop_device_relinquish(loop); - r = varlink_replybo( + r = sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("partitions", SD_JSON_BUILD_VARIANT(aj)), SD_JSON_BUILD_PAIR("imagePolicy", SD_JSON_BUILD_STRING(ps)), @@ -540,9 +540,9 @@ static int vl_method_mount_image( return r; } -static int process_connection(VarlinkServer *server, int _fd) { +static int process_connection(sd_varlink_server *server, int _fd) { _cleanup_close_ int fd = TAKE_FD(_fd); /* always take possession */ - _cleanup_(varlink_close_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_close_unrefp) sd_varlink *vl = NULL; _cleanup_(sd_event_unrefp) sd_event *event = NULL; int r; @@ -550,22 +550,22 @@ static int process_connection(VarlinkServer *server, int _fd) { if (r < 0) return r; - r = varlink_server_attach_event(server, event, 0); + r = sd_varlink_server_attach_event(server, event, 0); if (r < 0) return log_error_errno(r, "Failed to attach Varlink server to event loop: %m"); - r = varlink_server_add_connection(server, fd, &vl); + r = sd_varlink_server_add_connection(server, fd, &vl); if (r < 0) return log_error_errno(r, "Failed to add connection: %m"); TAKE_FD(fd); - vl = varlink_ref(vl); + vl = sd_varlink_ref(vl); - r = varlink_set_allow_fd_passing_input(vl, true); + r = sd_varlink_set_allow_fd_passing_input(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable fd passing for read: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable fd passing for write: %m"); @@ -573,7 +573,7 @@ static int process_connection(VarlinkServer *server, int _fd) { if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); - r = varlink_server_detach_event(server); + r = sd_varlink_server_detach_event(server); if (r < 0) return log_error_errno(r, "Failed to detach Varlink server from event loop: %m"); @@ -582,7 +582,7 @@ static int process_connection(VarlinkServer *server, int _fd) { static int run(int argc, char *argv[]) { usec_t start_time, listen_idle_usec, last_busy_usec = USEC_INFINITY; - _cleanup_(varlink_server_unrefp) VarlinkServer *server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *server = NULL; _cleanup_(hashmap_freep) Hashmap *polkit_registry = NULL; _cleanup_(pidref_done) PidRef parent = PIDREF_NULL; unsigned n_iterations = 0; @@ -604,23 +604,23 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to turn off non-blocking mode for listening socket: %m"); - r = varlink_server_new(&server, VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&server, SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate server: %m"); - r = varlink_server_add_interface(server, &vl_interface_io_systemd_MountFileSystem); + r = sd_varlink_server_add_interface(server, &vl_interface_io_systemd_MountFileSystem); if (r < 0) return log_error_errno(r, "Failed to add MountFileSystem interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( server, "io.systemd.MountFileSystem.MountImage", vl_method_mount_image); if (r < 0) return log_error_errno(r, "Failed to bind methods: %m"); - varlink_server_set_userdata(server, &polkit_registry); + sd_varlink_server_set_userdata(server, &polkit_registry); - r = varlink_server_set_exit_on_idle(server, true); + r = sd_varlink_server_set_exit_on_idle(server, true); if (r < 0) return log_error_errno(r, "Failed to enable exit-on-idle mode: %m"); diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 792be3c124..69e5ca869d 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -19,6 +19,7 @@ #include "sd-json.h" #include "sd-netlink.h" #include "sd-network.h" +#include "sd-varlink.h" #include "alloc-util.h" #include "bond-util.h" @@ -73,7 +74,7 @@ #include "terminal-util.h" #include "udev-util.h" #include "unit-def.h" -#include "varlink.h" +#include "varlink-util.h" #include "verbs.h" #include "wifi-util.h" @@ -96,19 +97,19 @@ sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF; STATIC_DESTRUCTOR_REGISTER(arg_drop_in, freep); -static int varlink_connect_networkd(Varlink **ret_varlink) { - _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; +static int varlink_connect_networkd(sd_varlink **ret_varlink) { + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL; sd_json_variant *reply; uint64_t id; int r; - r = varlink_connect_address(&vl, "/run/systemd/netif/io.systemd.Network"); + r = sd_varlink_connect_address(&vl, "/run/systemd/netif/io.systemd.Network"); if (r < 0) return log_error_errno(r, "Failed to connect to network service /run/systemd/netif/io.systemd.Network: %m"); - (void) varlink_set_description(vl, "varlink-network"); + (void) sd_varlink_set_description(vl, "varlink-network"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_error_errno(r, "Failed to allow passing file descriptor through varlink: %m"); @@ -1362,7 +1363,7 @@ static const sd_json_dispatch_field lldp_neighbor_dispatch_table[] = { {}, }; -static int dump_lldp_neighbors(Varlink *vl, Table *table, int ifindex) { +static int dump_lldp_neighbors(sd_varlink *vl, Table *table, int ifindex) { _cleanup_strv_free_ char **buf = NULL; sd_json_variant *reply; int r; @@ -1685,7 +1686,7 @@ static int link_status_one( sd_bus *bus, sd_netlink *rtnl, sd_hwdb *hwdb, - Varlink *vl, + sd_varlink *vl, const LinkInfo *info) { _cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, @@ -2428,7 +2429,7 @@ static int link_status(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL; _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL; - _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL; _cleanup_(link_info_array_freep) LinkInfo *links = NULL; int r, c; @@ -2590,7 +2591,7 @@ static int dump_lldp_neighbors_json(sd_json_variant *reply, char * const *patter } static int link_lldp_status(int argc, char *argv[], void *userdata) { - _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL; _cleanup_(table_unrefp) Table *table = NULL; sd_json_variant *reply; uint64_t all = 0; @@ -2931,7 +2932,7 @@ static int verb_reconfigure(int argc, char *argv[], void *userdata) { } static int verb_persistent_storage(int argc, char *argv[], void *userdata) { - _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL; bool ready; int r; @@ -2951,7 +2952,7 @@ static int verb_persistent_storage(int argc, char *argv[], void *userdata) { if (fd < 0) return log_error_errno(errno, "Failed to open /var/lib/systemd/network/: %m"); - r = varlink_push_fd(vl, fd); + r = sd_varlink_push_fd(vl, fd); if (r < 0) return log_error_errno(r, "Failed to push file descriptor of /var/lib/systemd/network/ into varlink: %m"); diff --git a/src/network/networkd-manager-varlink.c b/src/network/networkd-manager-varlink.c index 3ecb450172..ce986e2cdc 100644 --- a/src/network/networkd-manager-varlink.c +++ b/src/network/networkd-manager-varlink.c @@ -2,6 +2,8 @@ #include <unistd.h> +#include "sd-varlink.h" + #include "bus-polkit.h" #include "fd-util.h" #include "json-util.h" @@ -9,18 +11,17 @@ #include "networkd-dhcp-server.h" #include "networkd-manager-varlink.h" #include "stat-util.h" -#include "varlink.h" #include "varlink-io.systemd.Network.h" -static int vl_method_get_states(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_states(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Manager *m = ASSERT_PTR(userdata); assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(m->address_state)), SD_JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(m->ipv4_address_state)), @@ -30,7 +31,7 @@ static int vl_method_get_states(Varlink *link, sd_json_variant *parameters, Varl SD_JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(m->operational_state))); } -static int vl_method_get_namespace_id(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_namespace_id(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { uint64_t inode = 0; uint32_t nsid = UINT32_MAX; int r; @@ -38,7 +39,7 @@ static int vl_method_get_namespace_id(Varlink *link, sd_json_variant *parameters assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); /* Network namespaces have two identifiers: the inode number (which all namespace types have), and * the "nsid" (aka the "cookie"), which only network namespaces know as a concept, and which is not @@ -55,7 +56,7 @@ static int vl_method_get_namespace_id(Varlink *link, sd_json_variant *parameters if (r < 0) log_full_errno(r == -ENODATA ? LOG_DEBUG : LOG_WARNING, r, "Failed to query network nsid, ignoring: %m"); - return varlink_replybo(link, + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR_UNSIGNED("NamespaceId", inode), SD_JSON_BUILD_PAIR_CONDITION(nsid == UINT32_MAX, "NamespaceNSID", SD_JSON_BUILD_NULL), SD_JSON_BUILD_PAIR_CONDITION(nsid != UINT32_MAX, "NamespaceNSID", SD_JSON_BUILD_UNSIGNED(nsid))); @@ -66,7 +67,7 @@ typedef struct InterfaceInfo { const char *ifname; } InterfaceInfo; -static int dispatch_interface(Varlink *vlink, sd_json_variant *parameters, Manager *manager, Link **ret) { +static int dispatch_interface(sd_varlink *vlink, sd_json_variant *parameters, Manager *manager, Link **ret) { static const sd_json_dispatch_field dispatch_table[] = { { "InterfaceIndex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(InterfaceInfo, ifindex), 0 }, { "InterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(InterfaceInfo, ifname), 0 }, @@ -80,23 +81,23 @@ static int dispatch_interface(Varlink *vlink, sd_json_variant *parameters, Manag assert(vlink); assert(manager); - r = varlink_dispatch(vlink, parameters, dispatch_table, &info); + r = sd_varlink_dispatch(vlink, parameters, dispatch_table, &info); if (r != 0) return r; if (info.ifindex < 0) - return varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceIndex")); + return sd_varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceIndex")); if (info.ifindex > 0 && link_get_by_index(manager, info.ifindex, &link) < 0) - return varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceIndex")); + return sd_varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceIndex")); if (info.ifname) { Link *link_by_name; if (link_get_by_name(manager, info.ifname, &link_by_name) < 0) - return varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceName")); + return sd_varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceName")); if (link && link_by_name != link) /* If both arguments are specified, then these must be consistent. */ - return varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceName")); + return sd_varlink_error_invalid_parameter(vlink, JSON_VARIANT_STRING_CONST("InterfaceName")); link = link_by_name; } @@ -119,7 +120,7 @@ static int link_append_lldp_neighbors(Link *link, sd_json_variant *v, sd_json_va SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(v), "Neighbors", SD_JSON_BUILD_VARIANT(v))); } -static int vl_method_get_lldp_neighbors(Varlink *vlink, sd_json_variant *parameters, VarlinkMethodFlags flags, Manager *manager) { +static int vl_method_get_lldp_neighbors(sd_varlink *vlink, sd_json_variant *parameters, sd_varlink_method_flags_t flags, Manager *manager) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; Link *link = NULL; int r; @@ -162,13 +163,13 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, sd_json_variant *paramet return r; } - return varlink_replybo( + return sd_varlink_replybo( vlink, SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY), SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_VARIANT(array))); } -static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_set_persistent_storage(sd_varlink *vlink, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "Ready", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, 0, 0 }, {} @@ -180,7 +181,7 @@ static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *par assert(vlink); - r = varlink_dispatch(vlink, parameters, dispatch_table, &ready); + r = sd_varlink_dispatch(vlink, parameters, dispatch_table, &ready); if (r != 0) return r; @@ -188,7 +189,7 @@ static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *par struct stat st, st_prev; int fd; - fd = varlink_peek_fd(vlink, 0); + fd = sd_varlink_peek_fd(vlink, 0); if (fd < 0) return log_warning_errno(fd, "Failed to peek file descriptor of the persistent storage: %m"); @@ -203,7 +204,7 @@ static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *par return log_warning_errno(r, "Failed to check if the persistent storage is writable: %m"); if (r > 0) { log_warning("The persistent storage is on read-only filesystem."); - return varlink_error(vlink, "io.systemd.Network.StorageReadOnly", NULL); + return sd_varlink_error(vlink, "io.systemd.Network.StorageReadOnly", NULL); } if (fstat(fd, &st) < 0) @@ -216,11 +217,11 @@ static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *par if (manager->persistent_storage_fd >= 0 && fstat(manager->persistent_storage_fd, &st_prev) >= 0 && stat_inode_same(&st, &st_prev)) - return varlink_reply(vlink, NULL); + return sd_varlink_reply(vlink, NULL); } else { if (manager->persistent_storage_fd < 0) - return varlink_reply(vlink, NULL); + return sd_varlink_reply(vlink, NULL); } r = varlink_verify_polkit_async( @@ -235,7 +236,7 @@ static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *par if (ready) { _cleanup_close_ int fd = -EBADF; - fd = varlink_take_fd(vlink, 0); + fd = sd_varlink_take_fd(vlink, 0); if (fd < 0) return log_warning_errno(fd, "Failed to take file descriptor of the persistent storage: %m"); @@ -245,15 +246,15 @@ static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *par manager_toggle_dhcp4_server_state(manager, ready); - return varlink_reply(vlink, NULL); + return sd_varlink_reply(vlink, NULL); } -static int on_connect(VarlinkServer *s, Varlink *vlink, void *userdata) { +static int on_connect(sd_varlink_server *s, sd_varlink *vlink, void *userdata) { int r; assert(vlink); - r = varlink_set_allow_fd_passing_input(vlink, true); + r = sd_varlink_set_allow_fd_passing_input(vlink, true); if (r < 0) return log_warning_errno(r, "Failed to allow receiving file descriptor through varlink: %m"); @@ -261,7 +262,7 @@ static int on_connect(VarlinkServer *s, Varlink *vlink, void *userdata) { } int manager_connect_varlink(Manager *m) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); @@ -269,19 +270,19 @@ int manager_connect_varlink(Manager *m) { if (m->varlink_server) return 0; - r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(s, m); + sd_varlink_server_set_userdata(s, m); - (void) varlink_server_set_description(s, "varlink-api-network"); + (void) sd_varlink_server_set_description(s, "varlink-api-network"); - r = varlink_server_add_interface(s, &vl_interface_io_systemd_Network); + r = sd_varlink_server_add_interface(s, &vl_interface_io_systemd_Network); if (r < 0) return log_error_errno(r, "Failed to add Network interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( s, "io.systemd.Network.GetStates", vl_method_get_states, "io.systemd.Network.GetNamespaceId", vl_method_get_namespace_id, @@ -290,15 +291,15 @@ int manager_connect_varlink(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to register varlink methods: %m"); - r = varlink_server_listen_address(s, "/run/systemd/netif/io.systemd.Network", 0666); + r = sd_varlink_server_listen_address(s, "/run/systemd/netif/io.systemd.Network", 0666); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); - r = varlink_server_bind_connect(s, on_connect); + r = sd_varlink_server_bind_connect(s, on_connect); if (r < 0) return log_error_errno(r, "Failed to set on-connect callback for varlink: %m"); @@ -309,6 +310,6 @@ int manager_connect_varlink(Manager *m) { void manager_varlink_done(Manager *m) { assert(m); - m->varlink_server = varlink_server_unref(m->varlink_server); + m->varlink_server = sd_varlink_server_unref(m->varlink_server); (void) unlink("/run/systemd/netif/io.systemd.Network"); } diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index c14a98fb97..354cc6273e 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -7,6 +7,7 @@ #include "sd-id128.h" #include "sd-netlink.h" #include "sd-resolve.h" +#include "sd-varlink.h" #include "dhcp-duid-internal.h" #include "firewall-util.h" @@ -17,7 +18,6 @@ #include "ordered-set.h" #include "set.h" #include "time-util.h" -#include "varlink.h" struct Manager { sd_netlink *rtnl; @@ -26,7 +26,7 @@ struct Manager { sd_event *event; sd_resolve *resolve; sd_bus *bus; - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; sd_device_monitor *device_monitor; Hashmap *polkit_registry; int ethtool_fd; diff --git a/src/nsresourced/nsresourcework.c b/src/nsresourced/nsresourcework.c index 1c33aebcce..ac088e6c7f 100644 --- a/src/nsresourced/nsresourcework.c +++ b/src/nsresourced/nsresourcework.c @@ -9,6 +9,7 @@ #include "sd-daemon.h" #include "sd-netlink.h" +#include "sd-varlink.h" #include "env-util.h" #include "fd-util.h" @@ -42,7 +43,6 @@ #include "userns-restrict.h" #include "varlink-io.systemd.NamespaceResource.h" #include "varlink-io.systemd.UserDatabase.h" -#include "varlink.h" #define ITERATIONS_MAX 64U #define RUNTIME_MAX_USEC (5 * USEC_PER_MINUTE) @@ -95,7 +95,7 @@ static int build_user_json(UserNamespaceInfo *userns_info, uid_t offset, sd_json SD_JSON_BUILD_PAIR("disposition", SD_JSON_BUILD_STRING(user_disposition_to_string(disposition)))); } -static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, @@ -114,12 +114,12 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.NamespaceResource")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (p.user_name) { _cleanup_free_ char *n = NULL; @@ -153,7 +153,7 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, goto not_found; if (uid_is_valid(p.uid) && p.uid != userns_info->start + offset) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); } else if (uid_is_valid(p.uid)) { uid_t start, uidmask; @@ -180,16 +180,16 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, if (offset >= userns_info->size) /* Outside of range? */ goto not_found; } else - return varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); r = build_user_json(userns_info, offset, &v); if (r < 0) return r; - return varlink_replybo(link, SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_VARIANT(v))); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_VARIANT(v))); not_found: - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } static int build_group_json(UserNamespaceInfo *userns_info, gid_t offset, sd_json_variant **ret) { @@ -222,7 +222,7 @@ static int build_group_json(UserNamespaceInfo *userns_info, gid_t offset, sd_jso SD_JSON_BUILD_PAIR("disposition", SD_JSON_BUILD_STRING(user_disposition_to_string(disposition)))); } -static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, @@ -241,12 +241,12 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.NamespaceResource")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); if (p.group_name) { _cleanup_free_ char *n = NULL; @@ -280,7 +280,7 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters goto not_found; if (gid_is_valid(p.gid) && p.uid != userns_info->start + offset) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); } else if (gid_is_valid(p.gid)) { gid_t start, gidmask; @@ -307,19 +307,19 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters if (offset >= userns_info->size) /* Outside of range? */ goto not_found; } else - return varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.EnumerationNotSupported", NULL); r = build_group_json(userns_info, offset, &v); if (r < 0) return r; - return varlink_replybo(link, SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_VARIANT(v))); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_VARIANT(v))); not_found: - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } -static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_memberships(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), 0 }, { "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), 0 }, @@ -332,15 +332,15 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!streq_ptr(p.service, "io.systemd.NamespaceResource")) - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); /* We don't support auxiliary groups for namespace allocations */ - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } static int uid_is_available( @@ -587,7 +587,7 @@ static int write_userns(int usernsfd, const UserNamespaceInfo *userns_info) { return 0; } -static int test_userns_api_support(Varlink *link) { +static int test_userns_api_support(sd_varlink *link) { int r; assert(link); @@ -601,12 +601,12 @@ static int test_userns_api_support(Varlink *link) { if (r < 0) return log_error_errno(r, "Failed to parse $NSRESOURCE_API: %m"); if (r == 0) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceInterfaceNotSupported", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceInterfaceNotSupported", NULL); return 0; } -static int validate_name(Varlink *link, const char *name, char **ret) { +static int validate_name(sd_varlink *link, const char *name, char **ret) { _cleanup_free_ char *un = NULL; int r; @@ -615,13 +615,13 @@ static int validate_name(Varlink *link, const char *name, char **ret) { assert(ret); uid_t peer_uid; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; if (peer_uid == 0) { if (!userns_name_is_valid(name)) - return varlink_error_invalid_parameter_name(link, "name"); + return sd_varlink_error_invalid_parameter_name(link, "name"); un = strdup(name); if (!un) @@ -634,26 +634,26 @@ static int validate_name(Varlink *link, const char *name, char **ret) { return -ENOMEM; if (!userns_name_is_valid(un)) - return varlink_error_invalid_parameter_name(link, "name"); + return sd_varlink_error_invalid_parameter_name(link, "name"); } *ret = TAKE_PTR(un); return 0; } -static int validate_target_and_size(Varlink *link, unsigned target, unsigned size) { +static int validate_target_and_size(sd_varlink *link, unsigned target, unsigned size) { assert(link); if (!IN_SET(size, 1U, 0x10000)) - return varlink_error_invalid_parameter_name(link, "size"); + return sd_varlink_error_invalid_parameter_name(link, "size"); if (!uid_is_valid(target) || target > UINT32_MAX - size) - return varlink_error_invalid_parameter_name(link, "target"); + return sd_varlink_error_invalid_parameter_name(link, "target"); return 0; } -static int validate_userns(Varlink *link, int userns_fd) { +static int validate_userns(sd_varlink *link, int userns_fd) { int r; assert(link); @@ -668,17 +668,17 @@ static int validate_userns(Varlink *link, int userns_fd) { if (r < 0) return log_debug_errno(r, "Failed to check if user namespace fd is actually a user namespace: %m"); if (r == 0) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); /* And refuse the thing if it is our own */ r = is_our_namespace(userns_fd, NAMESPACE_USER); if (r < 0) return log_debug_errno(r, "Failed to check if user namespace fd refers to our own user namespace: %m"); if (r > 0) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); uid_t peer_uid; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return log_debug_errno(r, "Failed to acquire peer UID: %m"); @@ -689,13 +689,13 @@ static int validate_userns(Varlink *link, int userns_fd) { return log_debug_errno(errno, "Failed to get owner UID of user namespace: %m"); if (owner_uid != peer_uid) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); } return 0; } -static int validate_userns_is_empty(Varlink *link, int userns_fd) { +static int validate_userns_is_empty(sd_varlink *link, int userns_fd) { int r; assert(link); @@ -707,7 +707,7 @@ static int validate_userns_is_empty(Varlink *link, int userns_fd) { return log_debug_errno(r, "Failed to read userns UID range: %m"); if (!uid_range_is_empty(range)) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); range = uid_range_free(range); r = uid_range_load_userns_by_fd(userns_fd, GID_RANGE_USERNS_OUTSIDE, &range); @@ -715,7 +715,7 @@ static int validate_userns_is_empty(Varlink *link, int userns_fd) { return log_debug_errno(r, "Failed to read userns GID range: %m"); if (!uid_range_is_empty(range)) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); return 0; } @@ -727,7 +727,7 @@ typedef struct AllocateParameters { unsigned userns_fd_idx; } AllocateParameters; -static int vl_method_allocate_user_range(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_allocate_user_range(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(AllocateParameters, name), SD_JSON_MANDATORY }, @@ -755,7 +755,7 @@ static int vl_method_allocate_user_range(Varlink *link, sd_json_variant *paramet if (r != 0) return r; - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -767,7 +767,7 @@ static int vl_method_allocate_user_range(Varlink *link, sd_json_variant *paramet if (r != 0) return r; - userns_fd = varlink_take_fd(link, p.userns_fd_idx); + userns_fd = sd_varlink_take_fd(link, p.userns_fd_idx); if (userns_fd < 0) return log_debug_errno(userns_fd, "Failed to take user namespace fd from Varlink connection: %m"); @@ -782,7 +782,7 @@ static int vl_method_allocate_user_range(Varlink *link, sd_json_variant *paramet if (fstat(userns_fd, &userns_st) < 0) return log_debug_errno(errno, "Failed to fstat() user namespace fd: %m"); - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -811,13 +811,13 @@ static int vl_method_allocate_user_range(Varlink *link, sd_json_variant *paramet r = allocate_now(registry_dir_fd, userns_info, &lock_fd); if (r == -EHOSTDOWN) /* The needed UID range is not delegated to us */ - return varlink_error(link, "io.systemd.NamespaceResource.DynamicRangeUnavailable", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.DynamicRangeUnavailable", NULL); if (r == -EBUSY) /* All used up */ - return varlink_error(link, "io.systemd.NamespaceResource.NoDynamicRange", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.NoDynamicRange", NULL); if (r == -EDEADLK) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceExists", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceExists", NULL); if (r == -EEXIST) - return varlink_error(link, "io.systemd.NamespaceResource.NameExists", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.NameExists", NULL); if (r < 0) return r; @@ -854,7 +854,7 @@ static int vl_method_allocate_user_range(Varlink *link, sd_json_variant *paramet /* Note, we'll not return UID values from the host, since the child might not run in the same * user namespace as us. If they want to know the ranges they should read them off the userns fd, so * that they are translated into their PoV */ - return varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); + return sd_varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); fail: /* Note: we don't have to clean-up the BPF maps in the error path: the bpf map type used will @@ -863,7 +863,7 @@ fail: return r; } -static int validate_userns_is_safe(Varlink *link, int userns_fd) { +static int validate_userns_is_safe(sd_varlink *link, int userns_fd) { int r; assert(link); @@ -875,7 +875,7 @@ static int validate_userns_is_safe(Varlink *link, int userns_fd) { if (r < 0) return log_debug_errno(r, "Failed to read userns UID range: %m"); if (uid_range_is_empty(outside_range)) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); /* Read the outside GID range and check it is the same as the UID range */ _cleanup_(uid_range_freep) UIDRange *outside_range_gid = NULL; @@ -883,7 +883,7 @@ static int validate_userns_is_safe(Varlink *link, int userns_fd) { if (r < 0) return log_debug_errno(r, "Failed to read userns GID range: %m"); if (!uid_range_equal(outside_range, outside_range_gid)) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); /* Read the inside UID range, and verify it matches the size of the outside UID range */ _cleanup_(uid_range_freep) UIDRange *inside_range = NULL; @@ -899,26 +899,26 @@ static int validate_userns_is_safe(Varlink *link, int userns_fd) { if (r < 0) return log_debug_errno(r, "Failed to read userns contents: %m"); if (!uid_range_equal(inside_range, inside_range_gid)) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); uid_t peer_uid; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; uid_t peer_gid; - r = varlink_get_peer_gid(link, &peer_gid); + r = sd_varlink_get_peer_gid(link, &peer_gid); if (r < 0) return r; /* Insist that the first UID/GID in the range matches the client's UID/GID */ if (outside_range->entries[0].start != peer_uid || outside_range_gid->entries[0].start != peer_gid) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); /* If there are more than one UID in the range, then also insist that the first UID maps to root inside the userns */ if (uid_range_size(outside_range) > 1 && inside_range->entries[0].start != 0) - return varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "userNamespaceFileDescriptor"); return 0; } @@ -928,7 +928,7 @@ typedef struct RegisterParameters { unsigned userns_fd_idx; } RegisterParameters; -static int vl_method_register_user_namespace(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_register_user_namespace(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(RegisterParameters, name), SD_JSON_MANDATORY }, @@ -953,7 +953,7 @@ static int vl_method_register_user_namespace(Varlink *link, sd_json_variant *par if (r != 0) return r; - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -961,7 +961,7 @@ static int vl_method_register_user_namespace(Varlink *link, sd_json_variant *par if (r != 0) return r; - userns_fd = varlink_take_fd(link, p.userns_fd_idx); + userns_fd = sd_varlink_take_fd(link, p.userns_fd_idx); if (userns_fd < 0) return userns_fd; @@ -976,7 +976,7 @@ static int vl_method_register_user_namespace(Varlink *link, sd_json_variant *par if (fstat(userns_fd, &userns_st) < 0) return log_debug_errno(errno, "Failed to fstat() user namespace fd: %m"); - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -999,13 +999,13 @@ static int vl_method_register_user_namespace(Varlink *link, sd_json_variant *par if (r < 0) return r; if (r > 0) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceExists", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceExists", NULL); r = name_is_available(registry_dir_fd, userns_name); if (r < 0) return r; if (r == 0) - return varlink_error(link, "io.systemd.NamespaceResource.NameExists", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.NameExists", NULL); _cleanup_(userns_info_freep) UserNamespaceInfo *userns_info = userns_info_new(); if (!userns_info) @@ -1042,7 +1042,7 @@ static int vl_method_register_user_namespace(Varlink *link, sd_json_variant *par if (r < 0) goto fail; - return varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); + return sd_varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); fail: userns_registry_remove(registry_dir_fd, userns_info); @@ -1054,7 +1054,7 @@ typedef struct AddMountParameters { unsigned mount_fd_idx; } AddMountParameters; -static int vl_method_add_mount_to_user_namespace(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_add_mount_to_user_namespace(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field parameter_dispatch_table[] = { { "userNamespaceFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, offsetof(AddMountParameters, userns_fd_idx), SD_JSON_MANDATORY }, @@ -1080,17 +1080,17 @@ static int vl_method_add_mount_to_user_namespace(Varlink *link, sd_json_variant return r; /* Allowlisting arbitrary mounts is a privileged operation */ - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; if (peer_uid != 0) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); - r = varlink_dispatch(link, parameters, parameter_dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, parameter_dispatch_table, &p); if (r != 0) return r; - userns_fd = varlink_take_fd(link, p.userns_fd_idx); + userns_fd = sd_varlink_take_fd(link, p.userns_fd_idx); if (userns_fd < 0) return userns_fd; @@ -1101,7 +1101,7 @@ static int vl_method_add_mount_to_user_namespace(Varlink *link, sd_json_variant if (fstat(userns_fd, &userns_st) < 0) return -errno; - mount_fd = varlink_take_fd(link, p.mount_fd_idx); + mount_fd = sd_varlink_take_fd(link, p.mount_fd_idx); if (mount_fd < 0) return mount_fd; @@ -1132,7 +1132,7 @@ static int vl_method_add_mount_to_user_namespace(Varlink *link, sd_json_variant userns_st.st_ino, &userns_info); if (r == -ENOENT) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceNotRegistered", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceNotRegistered", NULL); if (r < 0) return r; @@ -1169,10 +1169,10 @@ static int vl_method_add_mount_to_user_namespace(Varlink *link, sd_json_variant log_debug("Granting access to mount %i to user namespace " INO_FMT " ('%s')", mnt_id, userns_st.st_ino, userns_info->name); - return varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); + return sd_varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); } -static int validate_cgroup(Varlink *link, int fd, uint64_t *ret_cgroup_id) { +static int validate_cgroup(sd_varlink *link, int fd, uint64_t *ret_cgroup_id) { int r; assert(link); @@ -1191,7 +1191,7 @@ static int validate_cgroup(Varlink *link, int fd, uint64_t *ret_cgroup_id) { if (r < 0) return log_debug_errno(r, "Failed to check if cgroup fd actually refers to cgroupfs: %m"); if (r == 0) - return varlink_error_invalid_parameter_name(link, "controlGroupFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "controlGroupFileDescriptor"); r = cg_fd_get_cgroupid(fd, ret_cgroup_id); if (r < 0) @@ -1205,7 +1205,7 @@ typedef struct AddCGroupParameters { unsigned cgroup_fd_idx; } AddCGroupParameters; -static int vl_method_add_cgroup_to_user_namespace(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_add_cgroup_to_user_namespace(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field parameter_dispatch_table[] = { { "userNamespaceFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, offsetof(AddCGroupParameters, userns_fd_idx), SD_JSON_MANDATORY }, { "controlGroupFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, offsetof(AddCGroupParameters, cgroup_fd_idx), SD_JSON_MANDATORY }, @@ -1229,11 +1229,11 @@ static int vl_method_add_cgroup_to_user_namespace(Varlink *link, sd_json_variant if (r != 0) return r; - r = varlink_dispatch(link, parameters, parameter_dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, parameter_dispatch_table, &p); if (r != 0) return r; - userns_fd = varlink_take_fd(link, p.userns_fd_idx); + userns_fd = sd_varlink_take_fd(link, p.userns_fd_idx); if (userns_fd < 0) return log_debug_errno(userns_fd, "Failed to take user namespace fd from Varlink connection: %m"); @@ -1244,7 +1244,7 @@ static int vl_method_add_cgroup_to_user_namespace(Varlink *link, sd_json_variant if (fstat(userns_fd, &userns_st) < 0) return log_debug_errno(errno, "Failed to fstat() user namespace fd: %m"); - cgroup_fd = varlink_take_fd(link, p.cgroup_fd_idx); + cgroup_fd = sd_varlink_take_fd(link, p.cgroup_fd_idx); if (cgroup_fd < 0) return log_debug_errno(cgroup_fd, "Failed to take cgroup fd from Varlink connection: %m"); @@ -1270,29 +1270,29 @@ static int vl_method_add_cgroup_to_user_namespace(Varlink *link, sd_json_variant userns_st.st_ino, &userns_info); if (r == -ENOENT) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceNotRegistered", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceNotRegistered", NULL); if (r < 0) return r; /* The user namespace must have a user assigned */ if (userns_info->size == 0) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceWithoutUserRange", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceWithoutUserRange", NULL); if (userns_info_has_cgroup(userns_info, cgroup_id)) - return varlink_error(link, "io.systemd.NamespaceResource.ControlGroupAlreadyAdded", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.ControlGroupAlreadyAdded", NULL); if (userns_info->n_cgroups > USER_NAMESPACE_CGROUPS_DELEGATE_MAX) - return varlink_error(link, "io.systemd.NamespaceResource.TooManyControlGroups", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.TooManyControlGroups", NULL); /* Registering a cgroup for this client is only allowed for the root or the owner of a userns */ - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return log_debug_errno(r, "Failed to get connection peer: %m"); if (peer_uid != 0) { if (peer_uid != userns_info->owner) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); /* The cgroup must be owned by the owner of the userns */ if (cgroup_st.st_uid != userns_info->owner) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); } r = userns_info_add_cgroup(userns_info, cgroup_id); @@ -1317,7 +1317,7 @@ static int vl_method_add_cgroup_to_user_namespace(Varlink *link, sd_json_variant log_debug("Granting ownership to cgroup %" PRIu64 " to userns " INO_FMT " ('%s' @ UID " UID_FMT ")", cgroup_id, userns_st.st_ino, userns_info->name, userns_info->start); - return varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); + return sd_varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); } static uint64_t hash_ifname_id(UserNamespaceInfo *userns_info, const char *ifname) { @@ -1441,7 +1441,7 @@ static int create_veth( return 0; } -static int validate_netns(Varlink *link, int userns_fd, int netns_fd) { +static int validate_netns(sd_varlink *link, int userns_fd, int netns_fd) { int r; assert(link); @@ -1457,14 +1457,14 @@ static int validate_netns(Varlink *link, int userns_fd, int netns_fd) { if (r < 0) return r; if (r == 0) - return varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); /* And refuse the thing if it is our own */ r = is_our_namespace(netns_fd, NAMESPACE_NET); if (r < 0) return r; if (r > 0) - return varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); /* Check if the netns actually belongs to the userns */ _cleanup_close_ int owner_userns_fd = -EBADF; @@ -1476,10 +1476,10 @@ static int validate_netns(Varlink *link, int userns_fd, int netns_fd) { if (r < 0) return r; if (r == 0) - return varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); uid_t peer_uid; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -1491,7 +1491,7 @@ static int validate_netns(Varlink *link, int userns_fd, int netns_fd) { return -errno; if (owner_uid != peer_uid) - return varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); + return sd_varlink_error_invalid_parameter_name(link, "networkNamespaceFileDescriptor"); } return 0; @@ -1504,7 +1504,7 @@ typedef struct AddNetworkParameters { const char *mode; } AddNetworkParameters; -static int vl_method_add_netif_to_user_namespace(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_add_netif_to_user_namespace(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field parameter_dispatch_table[] = { { "userNamespaceFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, offsetof(AddNetworkParameters, userns_fd_idx), SD_JSON_MANDATORY }, { "networkNamespaceFileDescriptor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, offsetof(AddNetworkParameters, netns_fd_idx), SD_JSON_MANDATORY }, @@ -1529,11 +1529,11 @@ static int vl_method_add_netif_to_user_namespace(Varlink *link, sd_json_variant if (r != 0) return r; - r = varlink_dispatch(link, parameters, parameter_dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, parameter_dispatch_table, &p); if (r != 0) return r; - userns_fd = varlink_take_fd(link, p.userns_fd_idx); + userns_fd = sd_varlink_take_fd(link, p.userns_fd_idx); if (userns_fd < 0) return userns_fd; @@ -1544,7 +1544,7 @@ static int vl_method_add_netif_to_user_namespace(Varlink *link, sd_json_variant if (fstat(userns_fd, &userns_st) < 0) return -errno; - netns_fd = varlink_take_fd(link, p.netns_fd_idx); + netns_fd = sd_varlink_take_fd(link, p.netns_fd_idx); if (netns_fd < 0) return netns_fd; @@ -1553,10 +1553,10 @@ static int vl_method_add_netif_to_user_namespace(Varlink *link, sd_json_variant return r; if (!streq_ptr(p.mode, "veth")) - return varlink_error_invalid_parameter_name(link, "mode"); + return sd_varlink_error_invalid_parameter_name(link, "mode"); if (p.ifname && !ifname_valid(p.ifname)) - return varlink_error_invalid_parameter_name(link, "interfaceName"); + return sd_varlink_error_invalid_parameter_name(link, "interfaceName"); registry_dir_fd = userns_registry_open_fd(); if (registry_dir_fd < 0) @@ -1572,16 +1572,16 @@ static int vl_method_add_netif_to_user_namespace(Varlink *link, sd_json_variant userns_st.st_ino, &userns_info); if (r == -ENOENT) - return varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceNotRegistered", NULL); + return sd_varlink_error(link, "io.systemd.NamespaceResource.UserNamespaceNotRegistered", NULL); if (r < 0) return r; /* Registering a network interface for this client is only allowed for the root or the owner of a userns */ - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; if (peer_uid != 0 && peer_uid != userns_info->owner) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); _cleanup_free_ char *ifname_host = NULL, *altifname_host = NULL; const char *ifname_namespace = p.ifname ?: "host0"; @@ -1614,34 +1614,37 @@ static int vl_method_add_netif_to_user_namespace(Varlink *link, sd_json_variant log_debug("Adding veth tunnel %s from host to userns " INO_FMT " ('%s' @ UID " UID_FMT ", interface %s).", ifname_host, userns_st.st_ino, userns_info->name, userns_info->start, ifname_namespace); - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("hostInterfaceName", SD_JSON_BUILD_STRING(ifname_host)), SD_JSON_BUILD_PAIR("namespaceInterfaceName", SD_JSON_BUILD_STRING(ifname_namespace))); } -static int process_connection(VarlinkServer *server, int _fd) { +static int process_connection(sd_varlink_server *server, int _fd) { _cleanup_close_ int fd = TAKE_FD(_fd); /* always take possession */ - _cleanup_(varlink_close_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_close_unrefp) sd_varlink *vl = NULL; int r; - r = varlink_server_add_connection(server, fd, &vl); + assert(server); + assert(fd >= 0); + + r = sd_varlink_server_add_connection(server, fd, &vl); if (r < 0) return log_error_errno(r, "Failed to add connection: %m"); TAKE_FD(fd); - vl = varlink_ref(vl); + vl = sd_varlink_ref(vl); - r = varlink_set_allow_fd_passing_input(vl, true); + r = sd_varlink_set_allow_fd_passing_input(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable fd passing for read: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable fd passing for write: %m"); for (;;) { - r = varlink_process(vl); + r = sd_varlink_process(vl); if (r == -ENOTCONN) { log_debug("Connection terminated."); break; @@ -1651,7 +1654,7 @@ static int process_connection(VarlinkServer *server, int _fd) { if (r > 0) continue; - r = varlink_wait(vl, CONNECTION_IDLE_USEC); + r = sd_varlink_wait(vl, CONNECTION_IDLE_USEC); if (r < 0) return log_error_errno(r, "Failed to wait for connection events: %m"); if (r == 0) @@ -1664,7 +1667,7 @@ static int process_connection(VarlinkServer *server, int _fd) { static int run(int argc, char *argv[]) { _cleanup_(userns_restrict_bpf_freep) struct userns_restrict_bpf *bpf = NULL; usec_t start_time, listen_idle_usec, last_busy_usec = USEC_INFINITY; - _cleanup_(varlink_server_unrefp) VarlinkServer *server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *server = NULL; _cleanup_(pidref_done) PidRef parent = PIDREF_NULL; unsigned n_iterations = 0; int m, listen_fd, r; @@ -1685,18 +1688,18 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to turn off non-blocking mode for listening socket: %m"); - r = varlink_server_new(&server, VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&server, SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate server: %m"); - r = varlink_server_add_interface_many( + r = sd_varlink_server_add_interface_many( server, &vl_interface_io_systemd_NamespaceResource, &vl_interface_io_systemd_UserDatabase); if (r < 0) return log_error_errno(r, "Failed to add UserDatabase and NamespaceResource interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( server, "io.systemd.NamespaceResource.AllocateUserRange", vl_method_allocate_user_range, "io.systemd.NamespaceResource.RegisterUserNamespace", vl_method_register_user_namespace, @@ -1709,7 +1712,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to bind methods: %m"); - varlink_server_set_userdata(server, &bpf); + sd_varlink_server_set_userdata(server, &bpf); r = getenv_bool("NSRESOURCE_FIXED_WORKER"); if (r < 0) diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c index 537e0f6c17..91c5f11cb2 100644 --- a/src/nss-resolve/nss-resolve.c +++ b/src/nss-resolve/nss-resolve.c @@ -8,6 +8,8 @@ #include <sys/types.h> #include <unistd.h> +#include "sd-varlink.h" + #include "env-util.h" #include "errno-util.h" #include "glyph-util.h" @@ -19,7 +21,6 @@ #include "signal-util.h" #include "string-util.h" #include "strv.h" -#include "varlink.h" static sd_json_dispatch_flags_t json_dispatch_flags = SD_JSON_ALLOW_EXTENSIONS; @@ -47,12 +48,12 @@ static bool error_shall_fallback(const char *error_id) { * fallback module can be loaded. (These are mostly all Varlink-internal errors, as apparently we * then were unable to even do IPC with systemd-resolved.) */ return STR_IN_SET(error_id, - VARLINK_ERROR_DISCONNECTED, - VARLINK_ERROR_TIMEOUT, - VARLINK_ERROR_PROTOCOL, - VARLINK_ERROR_INTERFACE_NOT_FOUND, - VARLINK_ERROR_METHOD_NOT_FOUND, - VARLINK_ERROR_METHOD_NOT_IMPLEMENTED); + SD_VARLINK_ERROR_DISCONNECTED, + SD_VARLINK_ERROR_TIMEOUT, + SD_VARLINK_ERROR_PROTOCOL, + SD_VARLINK_ERROR_INTERFACE_NOT_FOUND, + SD_VARLINK_ERROR_METHOD_NOT_FOUND, + SD_VARLINK_ERROR_METHOD_NOT_IMPLEMENTED); } static bool error_shall_try_again(const char *error_id) { @@ -65,15 +66,15 @@ static bool error_shall_try_again(const char *error_id) { "io.systemd.Resolve.NetworkDown"); } -static int connect_to_resolved(Varlink **ret) { - _cleanup_(varlink_unrefp) Varlink *link = NULL; +static int connect_to_resolved(sd_varlink **ret) { + _cleanup_(sd_varlink_unrefp) sd_varlink *link = NULL; int r; - r = varlink_connect_address(&link, "/run/systemd/resolve/io.systemd.Resolve"); + r = sd_varlink_connect_address(&link, "/run/systemd/resolve/io.systemd.Resolve"); if (r < 0) return r; - r = varlink_set_relative_timeout(link, SD_RESOLVED_QUERY_TIMEOUT_USEC); + r = sd_varlink_set_relative_timeout(link, SD_RESOLVED_QUERY_TIMEOUT_USEC); if (r < 0) return r; @@ -232,7 +233,7 @@ enum nss_status _nss_resolve_gethostbyname4_r( int *errnop, int *h_errnop, int32_t *ttlp) { - _cleanup_(varlink_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *link = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *cparams = NULL; _cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {}; sd_json_variant *rparams, *entry; @@ -264,7 +265,7 @@ enum nss_status _nss_resolve_gethostbyname4_r( * configuration can distinguish such executed but negative replies from complete failure to * talk to resolved). */ const char *error_id; - r = varlink_call(link, "io.systemd.Resolve.ResolveHostname", cparams, &rparams, &error_id); + r = sd_varlink_call(link, "io.systemd.Resolve.ResolveHostname", cparams, &rparams, &error_id); if (r < 0) goto fail; if (!isempty(error_id)) { @@ -392,7 +393,7 @@ enum nss_status _nss_resolve_gethostbyname3_r( int32_t *ttlp, char **canonp) { - _cleanup_(varlink_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *link = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *cparams = NULL; _cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {}; sd_json_variant *rparams, *entry; @@ -428,7 +429,7 @@ enum nss_status _nss_resolve_gethostbyname3_r( goto fail; const char *error_id; - r = varlink_call(link, "io.systemd.Resolve.ResolveHostname", cparams, &rparams, &error_id); + r = sd_varlink_call(link, "io.systemd.Resolve.ResolveHostname", cparams, &rparams, &error_id); if (r < 0) goto fail; if (!isempty(error_id)) { @@ -608,7 +609,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( int *errnop, int *h_errnop, int32_t *ttlp) { - _cleanup_(varlink_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *link = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *cparams = NULL; _cleanup_(resolve_address_reply_destroy) ResolveAddressReply p = {}; sd_json_variant *rparams, *entry; @@ -648,7 +649,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( goto fail; const char* error_id; - r = varlink_call(link, "io.systemd.Resolve.ResolveAddress", cparams, &rparams, &error_id); + r = sd_varlink_call(link, "io.systemd.Resolve.ResolveAddress", cparams, &rparams, &error_id); if (r < 0) goto fail; if (!isempty(error_id)) { diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index 43d2fcb43b..ee57e41b4e 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -127,15 +127,15 @@ static int process_managed_oom_message(Manager *m, uid_t uid, sd_json_variant *p } static int process_managed_oom_request( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, - VarlinkMethodFlags flags, + sd_varlink_method_flags_t flags, void *userdata) { Manager *m = ASSERT_PTR(userdata); uid_t uid; int r; - r = varlink_get_peer_uid(link, &uid); + r = sd_varlink_get_peer_uid(link, &uid); if (r < 0) return log_error_errno(r, "Failed to get varlink peer uid: %m"); @@ -143,10 +143,10 @@ static int process_managed_oom_request( } static int process_managed_oom_reply( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, const char *error_id, - VarlinkReplyFlags flags, + sd_varlink_reply_flags_t flags, void *userdata) { Manager *m = ASSERT_PTR(userdata); uid_t uid; @@ -158,7 +158,7 @@ static int process_managed_oom_reply( goto finish; } - r = varlink_get_peer_uid(link, &uid); + r = sd_varlink_get_peer_uid(link, &uid); if (r < 0) { log_error_errno(r, "Failed to get varlink peer uid: %m"); goto finish; @@ -167,8 +167,8 @@ static int process_managed_oom_reply( r = process_managed_oom_message(m, uid, parameters); finish: - if (!FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) - m->varlink_client = varlink_close_unref(link); + if (!FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) + m->varlink_client = sd_varlink_close_unref(link); return r; } @@ -308,29 +308,29 @@ static int update_monitored_cgroup_contexts_candidates(Hashmap *monitored_cgroup } static int acquire_managed_oom_connect(Manager *m) { - _cleanup_(varlink_close_unrefp) Varlink *link = NULL; + _cleanup_(sd_varlink_close_unrefp) sd_varlink *link = NULL; int r; assert(m); assert(m->event); - r = varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_SYSTEM); + r = sd_varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_SYSTEM); if (r < 0) return log_error_errno(r, "Failed to connect to " VARLINK_ADDR_PATH_MANAGED_OOM_SYSTEM ": %m"); - (void) varlink_set_userdata(link, m); - (void) varlink_set_description(link, "oomd"); - (void) varlink_set_relative_timeout(link, USEC_INFINITY); + (void) sd_varlink_set_userdata(link, m); + (void) sd_varlink_set_description(link, "oomd"); + (void) sd_varlink_set_relative_timeout(link, USEC_INFINITY); - r = varlink_attach_event(link, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_attach_event(link, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); - r = varlink_bind_reply(link, process_managed_oom_reply); + r = sd_varlink_bind_reply(link, process_managed_oom_reply); if (r < 0) return log_error_errno(r, "Failed to bind reply callback: %m"); - r = varlink_observe(link, "io.systemd.ManagedOOM.SubscribeManagedOOMCGroups", NULL); + r = sd_varlink_observe(link, "io.systemd.ManagedOOM.SubscribeManagedOOMCGroups", NULL); if (r < 0) return log_error_errno(r, "Failed to observe varlink call: %m"); @@ -625,8 +625,8 @@ static int monitor_memory_pressure_contexts(Manager *m) { Manager* manager_free(Manager *m) { assert(m); - varlink_server_unref(m->varlink_server); - varlink_close_unref(m->varlink_client); + sd_varlink_server_unref(m->varlink_server); + sd_varlink_close_unref(m->varlink_client); sd_event_source_unref(m->swap_context_event_source); sd_event_source_unref(m->mem_pressure_context_event_source); sd_event_unref(m->event); @@ -711,34 +711,34 @@ static int manager_connect_bus(Manager *m) { } static int manager_varlink_init(Manager *m, int fd) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); assert(!m->varlink_server); - r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); + r = sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(s, m); + sd_varlink_server_set_userdata(s, m); - r = varlink_server_add_interface(s, &vl_interface_io_systemd_oom); + r = sd_varlink_server_add_interface(s, &vl_interface_io_systemd_oom); if (r < 0) return log_error_errno(r, "Failed to add oom interface to varlink server: %m"); - r = varlink_server_bind_method(s, "io.systemd.oom.ReportManagedOOMCGroups", process_managed_oom_request); + r = sd_varlink_server_bind_method(s, "io.systemd.oom.ReportManagedOOMCGroups", process_managed_oom_request); if (r < 0) return log_error_errno(r, "Failed to register varlink method: %m"); if (fd < 0) - r = varlink_server_listen_address(s, VARLINK_ADDR_PATH_MANAGED_OOM_USER, 0666); + r = sd_varlink_server_listen_address(s, VARLINK_ADDR_PATH_MANAGED_OOM_USER, 0666); else - r = varlink_server_listen_fd(s, fd); + r = sd_varlink_server_listen_fd(s, fd); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); diff --git a/src/oom/oomd-manager.h b/src/oom/oomd-manager.h index 8f0dd412da..635e16ddfc 100644 --- a/src/oom/oomd-manager.h +++ b/src/oom/oomd-manager.h @@ -3,10 +3,10 @@ #include "sd-bus.h" #include "sd-event.h" +#include "sd-varlink.h" #include "conf-parser.h" #include "oomd-util.h" -#include "varlink.h" /* Polling interval for monitoring stats */ #define SWAP_INTERVAL_USEC 150000 /* 0.15 seconds */ @@ -55,10 +55,10 @@ struct Manager { /* This varlink object is used to manage the subscription from systemd-oomd to PID1 which it uses to * listen for changes in ManagedOOM settings (oomd client - systemd server). */ - Varlink *varlink_client; + sd_varlink *varlink_client; /* This varlink server object is used to manage systemd-oomd's varlink server which is used by user * managers to report changes in ManagedOOM settings (oomd server - systemd client). */ - VarlinkServer *varlink_server; + sd_varlink_server *varlink_server; }; Manager* manager_free(Manager *m); diff --git a/src/pcrextend/pcrextend.c b/src/pcrextend/pcrextend.c index f1142f445c..92f117c2ce 100644 --- a/src/pcrextend/pcrextend.c +++ b/src/pcrextend/pcrextend.c @@ -4,6 +4,7 @@ #include "sd-json.h" #include "sd-messages.h" +#include "sd-varlink.h" #include "build.h" #include "efi-loader.h" @@ -18,7 +19,6 @@ #include "strv.h" #include "tpm2-pcr.h" #include "tpm2-util.h" -#include "varlink.h" #include "varlink-io.systemd.PCRExtend.h" static bool arg_graceful = false; @@ -167,7 +167,7 @@ static int parse_argv(int argc, char *argv[]) { if (arg_file_system && arg_machine_id) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--file-system= and --machine-id may not be combined."); - r = varlink_invocation(VARLINK_ALLOW_ACCEPT); + r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT); if (r < 0) return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m"); if (r > 0) @@ -258,7 +258,7 @@ static void method_extend_parameters_done(MethodExtendParameters *p) { iovec_done(&p->data); } -static int vl_method_extend(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_extend(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "pcr", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint, offsetof(MethodExtendParameters, pcr), SD_JSON_MANDATORY }, @@ -273,27 +273,27 @@ static int vl_method_extend(Varlink *link, sd_json_variant *parameters, VarlinkM assert(link); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (!TPM2_PCR_INDEX_VALID(p.pcr)) - return varlink_error_invalid_parameter_name(link, "pcr"); + return sd_varlink_error_invalid_parameter_name(link, "pcr"); if (p.text) { /* Specifying both the text string and the binary data is not allowed */ if (p.data.iov_base) - return varlink_error_invalid_parameter_name(link, "data"); + return sd_varlink_error_invalid_parameter_name(link, "data"); r = extend_now(p.pcr, p.text, strlen(p.text), _TPM2_USERSPACE_EVENT_TYPE_INVALID); } else if (p.data.iov_base) r = extend_now(p.pcr, p.data.iov_base, p.data.iov_len, _TPM2_USERSPACE_EVENT_TYPE_INVALID); else - return varlink_error_invalid_parameter_name(link, "text"); + return sd_varlink_error_invalid_parameter_name(link, "text"); if (r < 0) return r; - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } static int run(int argc, char *argv[]) { @@ -308,23 +308,23 @@ static int run(int argc, char *argv[]) { return r; if (arg_varlink) { - _cleanup_(varlink_server_unrefp) VarlinkServer *varlink_server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; /* Invocation as Varlink service */ - r = varlink_server_new(&varlink_server, VARLINK_SERVER_ROOT_ONLY); + r = sd_varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ROOT_ONLY); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - r = varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_PCRExtend); + r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_PCRExtend); if (r < 0) return log_error_errno(r, "Failed to add Varlink interface: %m"); - r = varlink_server_bind_method(varlink_server, "io.systemd.PCRExtend.Extend", vl_method_extend); + r = sd_varlink_server_bind_method(varlink_server, "io.systemd.PCRExtend.Extend", vl_method_extend); if (r < 0) return log_error_errno(r, "Failed to bind Varlink method: %m"); - r = varlink_server_loop_auto(varlink_server); + r = sd_varlink_server_loop_auto(varlink_server); if (r < 0) return log_error_errno(r, "Failed to run Varlink event loop: %m"); diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c index 585a00fc6e..113736b327 100644 --- a/src/pcrlock/pcrlock.c +++ b/src/pcrlock/pcrlock.c @@ -7,6 +7,7 @@ #include "sd-device.h" #include "sd-json.h" +#include "sd-varlink.h" #include "ask-password-api.h" #include "blockdev-util.h" @@ -51,7 +52,6 @@ #include "unaligned.h" #include "unit-name.h" #include "utf8.h" -#include "varlink.h" #include "varlink-io.systemd.PCRLock.h" #include "verbs.h" @@ -5163,7 +5163,7 @@ static int parse_argv(int argc, char *argv[]) { return log_oom(); } - r = varlink_invocation(VARLINK_ALLOW_ACCEPT); + r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT); if (r < 0) return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m"); if (r > 0) { @@ -5213,7 +5213,7 @@ static int pcrlock_main(int argc, char *argv[]) { return dispatch_verb(argc, argv, verbs, NULL); } -static int vl_method_read_event_log(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_read_event_log(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(event_log_freep) EventLog *el = NULL; uint64_t recnum = 0; int r; @@ -5221,7 +5221,7 @@ static int vl_method_read_event_log(Varlink *link, sd_json_variant *parameters, assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); el = event_log_new(); if (!el) @@ -5236,7 +5236,7 @@ static int vl_method_read_event_log(Varlink *link, sd_json_variant *parameters, FOREACH_ARRAY(rr, el->records, el->n_records) { if (rec_cel) { - r = varlink_notifybo(link, SD_JSON_BUILD_PAIR_VARIANT("record", rec_cel)); + r = sd_varlink_notifybo(link, SD_JSON_BUILD_PAIR_VARIANT("record", rec_cel)); if (r < 0) return r; @@ -5248,14 +5248,14 @@ static int vl_method_read_event_log(Varlink *link, sd_json_variant *parameters, return r; } - return varlink_replybo(link, SD_JSON_BUILD_PAIR_CONDITION(!!rec_cel, "record", SD_JSON_BUILD_VARIANT(rec_cel))); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR_CONDITION(!!rec_cel, "record", SD_JSON_BUILD_VARIANT(rec_cel))); } typedef struct MethodMakePolicyParameters { bool force; } MethodMakePolicyParameters; -static int vl_method_make_policy(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_make_policy(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "force", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(MethodMakePolicyParameters, force), 0 }, {} @@ -5265,7 +5265,7 @@ static int vl_method_make_policy(Varlink *link, sd_json_variant *parameters, Var assert(link); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -5273,24 +5273,24 @@ static int vl_method_make_policy(Varlink *link, sd_json_variant *parameters, Var if (r < 0) return r; if (r == 0) - return varlink_error(link, "io.systemd.PCRLock.NoChange", NULL); + return sd_varlink_error(link, "io.systemd.PCRLock.NoChange", NULL); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -static int vl_method_remove_policy(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_remove_policy(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { int r; assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); r = remove_policy(); if (r < 0) return r; - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } static int run(int argc, char *argv[]) { @@ -5303,19 +5303,19 @@ static int run(int argc, char *argv[]) { return r; if (arg_varlink) { - _cleanup_(varlink_server_unrefp) VarlinkServer *varlink_server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; /* Invocation as Varlink service */ - r = varlink_server_new(&varlink_server, VARLINK_SERVER_ROOT_ONLY); + r = sd_varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ROOT_ONLY); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - r = varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_PCRLock); + r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_PCRLock); if (r < 0) return log_error_errno(r, "Failed to add Varlink interface: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( varlink_server, "io.systemd.PCRLock.ReadEventLog", vl_method_read_event_log, "io.systemd.PCRLock.MakePolicy", vl_method_make_policy, @@ -5323,7 +5323,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to bind Varlink methods: %m"); - r = varlink_server_loop_auto(varlink_server); + r = sd_varlink_server_loop_auto(varlink_server); if (r < 0) return log_error_errno(r, "Failed to run Varlink event loop: %m"); diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 63fb7d6d39..e03b724235 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -7,6 +7,7 @@ #include "sd-bus.h" #include "sd-json.h" #include "sd-netlink.h" +#include "sd-varlink.h" #include "af-list.h" #include "alloc-util.h" @@ -46,7 +47,7 @@ #include "strv.h" #include "terminal-util.h" #include "utf8.h" -#include "varlink.h" +#include "varlink-util.h" #include "verb-log-control.h" #include "verbs.h" @@ -1107,10 +1108,10 @@ static int verb_tlsa(int argc, char **argv, void *userdata) { static int show_statistics(int argc, char **argv, void *userdata) { _cleanup_(table_unrefp) Table *table = NULL; sd_json_variant *reply = NULL; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; - r = varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); + r = sd_varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); if (r < 0) return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m"); @@ -1265,10 +1266,10 @@ static int show_statistics(int argc, char **argv, void *userdata) { static int reset_statistics(int argc, char **argv, void *userdata) { sd_json_variant *reply = NULL; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; - r = varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); + r = sd_varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); if (r < 0) return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m"); @@ -2799,10 +2800,10 @@ static void monitor_query_dump(sd_json_variant *v) { } static int monitor_reply( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, const char *error_id, - VarlinkReplyFlags flags, + sd_varlink_reply_flags_t flags, void *userdata) { assert(link); @@ -2810,13 +2811,13 @@ static int monitor_reply( if (error_id) { bool disconnect; - disconnect = streq(error_id, VARLINK_ERROR_DISCONNECTED); + disconnect = streq(error_id, SD_VARLINK_ERROR_DISCONNECTED); if (disconnect) log_info("Disconnected."); else log_error("Varlink error: %s", error_id); - (void) sd_event_exit(ASSERT_PTR(varlink_get_event(link)), disconnect ? EXIT_SUCCESS : EXIT_FAILURE); + (void) sd_event_exit(ASSERT_PTR(sd_varlink_get_event(link)), disconnect ? EXIT_SUCCESS : EXIT_FAILURE); return 0; } @@ -2841,7 +2842,7 @@ static int monitor_reply( static int verb_monitor(int argc, char *argv[], void *userdata) { _cleanup_(sd_event_unrefp) sd_event *event = NULL; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r, c; r = sd_event_default(&event); @@ -2852,23 +2853,23 @@ static int verb_monitor(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to enable exit on SIGINT/SIGTERM: %m"); - r = varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); + r = sd_varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); if (r < 0) return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m"); - r = varlink_set_relative_timeout(vl, USEC_INFINITY); /* We want the monitor to run basically forever */ + r = sd_varlink_set_relative_timeout(vl, USEC_INFINITY); /* We want the monitor to run basically forever */ if (r < 0) return log_error_errno(r, "Failed to set varlink time-out: %m"); - r = varlink_attach_event(vl, event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_attach_event(vl, event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); - r = varlink_bind_reply(vl, monitor_reply); + r = sd_varlink_bind_reply(vl, monitor_reply); if (r < 0) return log_error_errno(r, "Failed to bind reply callback to varlink connection: %m"); - r = varlink_observe(vl, "io.systemd.Resolve.Monitor.SubscribeQueryResults", NULL); + r = sd_varlink_observe(vl, "io.systemd.Resolve.Monitor.SubscribeQueryResults", NULL); if (r < 0) return log_error_errno(r, "Failed to issue SubscribeQueryResults() varlink call: %m"); @@ -2999,10 +3000,10 @@ static int dump_cache_scope(sd_json_variant *scope) { static int verb_show_cache(int argc, char *argv[], void *userdata) { sd_json_variant *reply = NULL, *d = NULL; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; - r = varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); + r = sd_varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); if (r < 0) return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m"); @@ -3173,10 +3174,10 @@ static int dump_server_state(sd_json_variant *server) { static int verb_show_server_state(int argc, char *argv[], void *userdata) { sd_json_variant *reply = NULL, *d = NULL; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; - r = varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); + r = sd_varlink_connect_address(&vl, "/run/systemd/resolve/io.systemd.Resolve.Monitor"); if (r < 0) return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m"); diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index ac60ee2798..47788e3216 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -432,8 +432,8 @@ DnsQuery *dns_query_free(DnsQuery *q) { sd_bus_track_unref(q->bus_track); if (q->varlink_request) { - varlink_set_userdata(q->varlink_request, NULL); - varlink_unref(q->varlink_request); + sd_varlink_set_userdata(q->varlink_request, NULL); + sd_varlink_unref(q->varlink_request); } if (q->request_packet) diff --git a/src/resolve/resolved-dns-query.h b/src/resolve/resolved-dns-query.h index d3ec3d4d8d..6bbebcac93 100644 --- a/src/resolve/resolved-dns-query.h +++ b/src/resolve/resolved-dns-query.h @@ -2,9 +2,9 @@ #pragma once #include "sd-bus.h" +#include "sd-varlink.h" #include "set.h" -#include "varlink.h" typedef struct DnsQueryCandidate DnsQueryCandidate; typedef struct DnsQuery DnsQuery; @@ -97,7 +97,7 @@ struct DnsQuery { /* Bus + Varlink client information */ sd_bus_message *bus_request; - Varlink *varlink_request; + sd_varlink *varlink_request; int request_family; union in_addr_union request_address; unsigned block_all_complete; diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 9bbdc648fc..046f8dd1ce 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -43,6 +43,7 @@ #include "string-table.h" #include "string-util.h" #include "utf8.h" +#include "varlink-util.h" #define SEND_TIMEOUT_USEC (200 * USEC_PER_MSEC) diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h index b4a2954b03..eda3e19a98 100644 --- a/src/resolve/resolved-manager.h +++ b/src/resolve/resolved-manager.h @@ -6,13 +6,13 @@ #include "sd-event.h" #include "sd-netlink.h" #include "sd-network.h" +#include "sd-varlink.h" #include "common-signal.h" #include "hashmap.h" #include "list.h" #include "ordered-set.h" #include "resolve-util.h" -#include "varlink.h" typedef struct Manager Manager; @@ -153,8 +153,8 @@ struct Manager { Hashmap *polkit_registry; - VarlinkServer *varlink_server; - VarlinkServer *varlink_monitor_server; + sd_varlink_server *varlink_server; + sd_varlink_server *varlink_monitor_server; Set *varlink_subscription; diff --git a/src/resolve/resolved-varlink.c b/src/resolve/resolved-varlink.c index 3d109026d2..b34d035d96 100644 --- a/src/resolve/resolved-varlink.c +++ b/src/resolve/resolved-varlink.c @@ -42,25 +42,25 @@ static int reply_query_state(DnsQuery *q) { switch (q->state) { case DNS_TRANSACTION_NO_SERVERS: - return varlink_error(q->varlink_request, "io.systemd.Resolve.NoNameServers", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoNameServers", NULL); case DNS_TRANSACTION_TIMEOUT: - return varlink_error(q->varlink_request, "io.systemd.Resolve.QueryTimedOut", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.QueryTimedOut", NULL); case DNS_TRANSACTION_ATTEMPTS_MAX_REACHED: - return varlink_error(q->varlink_request, "io.systemd.Resolve.MaxAttemptsReached", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.MaxAttemptsReached", NULL); case DNS_TRANSACTION_INVALID_REPLY: - return varlink_error(q->varlink_request, "io.systemd.Resolve.InvalidReply", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.InvalidReply", NULL); case DNS_TRANSACTION_ERRNO: - return varlink_error_errno(q->varlink_request, q->answer_errno); + return sd_varlink_error_errno(q->varlink_request, q->answer_errno); case DNS_TRANSACTION_ABORTED: - return varlink_error(q->varlink_request, "io.systemd.Resolve.QueryAborted", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.QueryAborted", NULL); case DNS_TRANSACTION_DNSSEC_FAILED: - return varlink_errorbo(q->varlink_request, "io.systemd.Resolve.DNSSECValidationFailed", + return sd_varlink_errorbo(q->varlink_request, "io.systemd.Resolve.DNSSECValidationFailed", SD_JSON_BUILD_PAIR("result", SD_JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))), SD_JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0, "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)), @@ -68,28 +68,28 @@ static int reply_query_state(DnsQuery *q) { "extendedDNSErrorMessage", SD_JSON_BUILD_STRING(q->answer_ede_msg))); case DNS_TRANSACTION_NO_TRUST_ANCHOR: - return varlink_error(q->varlink_request, "io.systemd.Resolve.NoTrustAnchor", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoTrustAnchor", NULL); case DNS_TRANSACTION_RR_TYPE_UNSUPPORTED: - return varlink_error(q->varlink_request, "io.systemd.Resolve.ResourceRecordTypeUnsupported", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.ResourceRecordTypeUnsupported", NULL); case DNS_TRANSACTION_NETWORK_DOWN: - return varlink_error(q->varlink_request, "io.systemd.Resolve.NetworkDown", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NetworkDown", NULL); case DNS_TRANSACTION_NO_SOURCE: - return varlink_error(q->varlink_request, "io.systemd.Resolve.NoSource", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoSource", NULL); case DNS_TRANSACTION_STUB_LOOP: - return varlink_error(q->varlink_request, "io.systemd.Resolve.StubLoop", NULL); + return sd_varlink_error(q->varlink_request, "io.systemd.Resolve.StubLoop", NULL); case DNS_TRANSACTION_NOT_FOUND: /* We return this as NXDOMAIN. This is only generated when a host doesn't implement LLMNR/TCP, and we * thus quickly know that we cannot resolve an in-addr.arpa or ip6.arpa address. */ - return varlink_errorbo(q->varlink_request, "io.systemd.Resolve.DNSError", + return sd_varlink_errorbo(q->varlink_request, "io.systemd.Resolve.DNSError", SD_JSON_BUILD_PAIR("rcode", SD_JSON_BUILD_INTEGER(DNS_RCODE_NXDOMAIN))); case DNS_TRANSACTION_RCODE_FAILURE: - return varlink_errorbo(q->varlink_request, "io.systemd.Resolve.DNSError", + return sd_varlink_errorbo(q->varlink_request, "io.systemd.Resolve.DNSError", SD_JSON_BUILD_PAIR("rcode", SD_JSON_BUILD_INTEGER(q->answer_rcode)), SD_JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0, "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)), @@ -105,13 +105,13 @@ static int reply_query_state(DnsQuery *q) { } } -static void vl_on_disconnect(VarlinkServer *s, Varlink *link, void *userdata) { +static void vl_on_disconnect(sd_varlink_server *s, sd_varlink *link, void *userdata) { DnsQuery *q; assert(s); assert(link); - q = varlink_get_userdata(link); + q = sd_varlink_get_userdata(link); if (!q) return; @@ -122,15 +122,15 @@ static void vl_on_disconnect(VarlinkServer *s, Varlink *link, void *userdata) { dns_query_complete(q, DNS_TRANSACTION_ABORTED); } -static void vl_on_notification_disconnect(VarlinkServer *s, Varlink *link, void *userdata) { +static void vl_on_notification_disconnect(sd_varlink_server *s, sd_varlink *link, void *userdata) { Manager *m = ASSERT_PTR(userdata); assert(s); assert(link); - Varlink *removed_link = set_remove(m->varlink_subscription, link); + sd_varlink *removed_link = set_remove(m->varlink_subscription, link); if (removed_link) { - varlink_unref(removed_link); + sd_varlink_unref(removed_link); log_debug("%u monitor clients remain active", set_size(m->varlink_subscription)); } } @@ -247,7 +247,7 @@ static void vl_method_resolve_hostname_complete(DnsQuery *query) { r = dns_query_process_cname_many(q); if (r == -ELOOP) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); goto finish; } if (r < 0) @@ -265,7 +265,7 @@ static void vl_method_resolve_hostname_complete(DnsQuery *query) { goto finish; if (sd_json_variant_is_blank_object(array)) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); goto finish; } @@ -274,7 +274,7 @@ static void vl_method_resolve_hostname_complete(DnsQuery *query) { if (r < 0) goto finish; - r = varlink_replybo( + r = sd_varlink_replybo( q->varlink_request, SD_JSON_BUILD_PAIR("addresses", SD_JSON_BUILD_VARIANT(array)), SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(normalized)), @@ -282,11 +282,11 @@ static void vl_method_resolve_hostname_complete(DnsQuery *query) { finish: if (r < 0) { log_full_errno(ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_ERR, r, "Failed to send hostname reply: %m"); - r = varlink_error_errno(q->varlink_request, r); + r = sd_varlink_error_errno(q->varlink_request, r); } } -static int parse_as_address(Varlink *link, LookupParameters *p) { +static int parse_as_address(sd_varlink *link, LookupParameters *p) { _cleanup_free_ char *canonical = NULL; int r, ff, parsed_ifindex, ifindex; union in_addr_union parsed; @@ -302,7 +302,7 @@ static int parse_as_address(Varlink *link, LookupParameters *p) { /* Make sure the data we parsed matches what is requested */ if ((p->family != AF_UNSPEC && ff != p->family) || (p->ifindex > 0 && parsed_ifindex > 0 && parsed_ifindex != p->ifindex)) - return varlink_error(link, "io.systemd.Resolve.NoSuchResourceRecord", NULL); + return sd_varlink_error(link, "io.systemd.Resolve.NoSuchResourceRecord", NULL); ifindex = parsed_ifindex > 0 ? parsed_ifindex : p->ifindex; @@ -311,7 +311,7 @@ static int parse_as_address(Varlink *link, LookupParameters *p) { if (r < 0) return r; - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("addresses", SD_JSON_BUILD_ARRAY( @@ -324,7 +324,7 @@ static int parse_as_address(Varlink *link, LookupParameters *p) { SD_RESOLVED_SYNTHETIC))); } -static int vl_method_resolve_hostname(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_resolve_hostname(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, ifindex), 0 }, { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(LookupParameters, name), SD_JSON_MANDATORY }, @@ -343,30 +343,30 @@ static int vl_method_resolve_hostname(Varlink *link, sd_json_variant *parameters assert(link); - m = varlink_server_get_userdata(varlink_get_server(link)); + m = sd_varlink_server_get_userdata(sd_varlink_get_server(link)); assert(m); - if (FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) + if (FLAGS_SET(flags, SD_VARLINK_METHOD_ONEWAY)) return -EINVAL; - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.ifindex < 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); r = dns_name_is_valid(p.name); if (r < 0) return r; if (r == 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("name")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("name")); if (!IN_SET(p.family, AF_UNSPEC, AF_INET, AF_INET6)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("family")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("family")); if (!validate_and_mangle_flags(p.name, &p.flags, SD_RESOLVED_NO_SEARCH)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); r = parse_as_address(link, &p); if (r != 0) @@ -384,8 +384,8 @@ static int vl_method_resolve_hostname(Varlink *link, sd_json_variant *parameters if (r < 0) return r; - q->varlink_request = varlink_ref(link); - varlink_set_userdata(link, q); + q->varlink_request = sd_varlink_ref(link); + sd_varlink_set_userdata(link, q); q->request_family = p.family; q->complete = vl_method_resolve_hostname_complete; @@ -449,7 +449,7 @@ static void vl_method_resolve_address_complete(DnsQuery *query) { r = dns_query_process_cname_many(q); if (r == -ELOOP) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); goto finish; } if (r < 0) @@ -484,22 +484,22 @@ static void vl_method_resolve_address_complete(DnsQuery *query) { } if (sd_json_variant_is_blank_object(array)) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); goto finish; } - r = varlink_replybo( + r = sd_varlink_replybo( q->varlink_request, SD_JSON_BUILD_PAIR("names", SD_JSON_BUILD_VARIANT(array)), SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))); finish: if (r < 0) { log_full_errno(ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_ERR, r, "Failed to send address reply: %m"); - r = varlink_error_errno(q->varlink_request, r); + r = sd_varlink_error_errno(q->varlink_request, r); } } -static int vl_method_resolve_address(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_resolve_address(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, ifindex), 0 }, { "family", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, family), SD_JSON_MANDATORY }, @@ -518,27 +518,27 @@ static int vl_method_resolve_address(Varlink *link, sd_json_variant *parameters, assert(link); - m = varlink_server_get_userdata(varlink_get_server(link)); + m = sd_varlink_server_get_userdata(sd_varlink_get_server(link)); assert(m); - if (FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) + if (FLAGS_SET(flags, SD_VARLINK_METHOD_ONEWAY)) return -EINVAL; - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.ifindex < 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); if (!IN_SET(p.family, AF_INET, AF_INET6)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("family")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("family")); if (FAMILY_ADDRESS_SIZE(p.family) != p.address_size) - return varlink_error(link, "io.systemd.Resolve.BadAddressSize", NULL); + return sd_varlink_error(link, "io.systemd.Resolve.BadAddressSize", NULL); if (!validate_and_mangle_flags(NULL, &p.flags, 0)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); r = dns_question_new_reverse(&question, p.family, &p.address); if (r < 0) @@ -548,8 +548,8 @@ static int vl_method_resolve_address(Varlink *link, sd_json_variant *parameters, if (r < 0) return r; - q->varlink_request = varlink_ref(link); - varlink_set_userdata(link, q); + q->varlink_request = sd_varlink_ref(link); + sd_varlink_set_userdata(link, q); q->request_family = p.family; q->request_address = p.address; @@ -710,7 +710,7 @@ static int append_srv( return 1; /* added */ } -static Varlink *get_vl_link_aux_query(DnsQuery *aux) { +static sd_varlink *get_vl_link_aux_query(DnsQuery *aux) { assert(aux); /* Find the main query */ @@ -768,7 +768,7 @@ static void resolve_service_all_complete(DnsQuery *query) { assert(bad->auxiliary_result != 0); if (bad->auxiliary_result == -ELOOP) { - r = varlink_error(query->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); + r = sd_varlink_error(query->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); goto finish; } @@ -804,7 +804,7 @@ static void resolve_service_all_complete(DnsQuery *query) { } if (sd_json_variant_is_blank_object(srv)) { - r = varlink_error(query->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); + r = sd_varlink_error(query->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); goto finish; } @@ -828,7 +828,7 @@ static void resolve_service_all_complete(DnsQuery *query) { if (r < 0) goto finish; - r = varlink_replybo( + r = sd_varlink_replybo( query->varlink_request, SD_JSON_BUILD_PAIR("services", SD_JSON_BUILD_VARIANT(srv)), SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_object(txt), "txt", SD_JSON_BUILD_VARIANT(txt)), @@ -841,7 +841,7 @@ static void resolve_service_all_complete(DnsQuery *query) { finish: if (r < 0) { log_error_errno(r, "Failed to resolve service: %m"); - r = varlink_error_errno(q->varlink_request, r); + r = sd_varlink_error_errno(q->varlink_request, r); } } @@ -926,7 +926,7 @@ static void vl_method_resolve_service_complete(DnsQuery *query) { r = dns_query_process_cname_many(q); if (r == -ELOOP) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); goto finish; } if (r < 0) @@ -970,12 +970,12 @@ static void vl_method_resolve_service_complete(DnsQuery *query) { /* If there's exactly one SRV RR and it uses the root domain as hostname, then the service is * explicitly not offered on the domain. Report this as a recognizable error. See RFC 2782, * Section "Usage Rules". */ - r = varlink_error(q->varlink_request, "io.systemd.Resolve.ServiceNotProvided", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.ServiceNotProvided", NULL); goto finish; } if (found <= 0) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); goto finish; } @@ -986,11 +986,11 @@ static void vl_method_resolve_service_complete(DnsQuery *query) { finish: if (r < 0) { log_error_errno(r, "Failed to send address reply: %m"); - r = varlink_error_errno(q->varlink_request, r); + r = sd_varlink_error_errno(q->varlink_request, r); } } -static int vl_method_resolve_service(Varlink* link, sd_json_variant* parameters, VarlinkMethodFlags flags, void* userdata) { +static int vl_method_resolve_service(sd_varlink* link, sd_json_variant* parameters, sd_varlink_method_flags_t flags, void* userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParametersResolveService, name), 0 }, { "type", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParametersResolveService, type), 0 }, @@ -1012,43 +1012,43 @@ static int vl_method_resolve_service(Varlink* link, sd_json_variant* parameters, assert(link); - m = varlink_server_get_userdata(varlink_get_server(link)); + m = sd_varlink_server_get_userdata(sd_varlink_get_server(link)); assert(m); - if (FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) + if (FLAGS_SET(flags, SD_VARLINK_METHOD_ONEWAY)) return -EINVAL; - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.ifindex < 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); if (!IN_SET(p.family, AF_INET, AF_INET6, AF_UNSPEC)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("family")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("family")); if (isempty(p.name)) p.name = NULL; else if (!dns_service_name_is_valid(p.name)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("name")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("name")); if (isempty(p.type)) p.type = NULL; else if (!dns_srv_type_is_valid(p.type)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("type")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("type")); r = dns_name_is_valid(p.domain); if (r < 0) return r; if (r == 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("domain")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("domain")); if (p.name && !p.type) /* Service name cannot be specified without service type. */ - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("type")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("type")); if (!validate_and_mangle_flags(p.name, &p.flags, SD_RESOLVED_NO_TXT|SD_RESOLVED_NO_ADDRESS)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); r = dns_question_new_service(&question_utf8, p.name, p.type, p.domain, !(p.flags & SD_RESOLVED_NO_TXT), false); if (r < 0) @@ -1062,11 +1062,11 @@ static int vl_method_resolve_service(Varlink* link, sd_json_variant* parameters, if (r < 0) return r; - q->varlink_request = varlink_ref(link); + q->varlink_request = sd_varlink_ref(link); q->request_family = p.family; q->complete = vl_method_resolve_service_complete; - varlink_set_userdata(link, q); + sd_varlink_set_userdata(link, q); r = dns_query_go(q); if (r < 0) @@ -1091,7 +1091,7 @@ static void vl_method_resolve_record_complete(DnsQuery *query) { r = dns_query_process_cname_many(q); if (r == -ELOOP) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.CNAMELoop", NULL); goto finish; } if (r < 0) @@ -1136,22 +1136,22 @@ static void vl_method_resolve_record_complete(DnsQuery *query) { } if (added <= 0) { - r = varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); + r = sd_varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL); goto finish; } - r = varlink_replybo( + r = sd_varlink_replybo( q->varlink_request, SD_JSON_BUILD_PAIR("rrs", SD_JSON_BUILD_VARIANT(array)), SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))); finish: if (r < 0) { log_full_errno(ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_ERR, r, "Failed to send record reply: %m"); - varlink_error_errno(q->varlink_request, r); + sd_varlink_error_errno(q->varlink_request, r); } } -static int vl_method_resolve_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_resolve_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, ifindex), 0 }, { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(LookupParameters, name), SD_JSON_MANDATORY }, @@ -1171,33 +1171,33 @@ static int vl_method_resolve_record(Varlink *link, sd_json_variant *parameters, assert(link); - m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link))); + m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link))); - if (FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) + if (FLAGS_SET(flags, SD_VARLINK_METHOD_ONEWAY)) return -EINVAL; - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; if (p.ifindex < 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("ifindex")); r = dns_name_is_valid(p.name); if (r < 0) return r; if (r == 0) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("name")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("name")); if (!dns_type_is_valid_query(p.type)) - return varlink_error(link, "io.systemd.Resolve.ResourceRecordTypeInvalidForQuery", NULL); + return sd_varlink_error(link, "io.systemd.Resolve.ResourceRecordTypeInvalidForQuery", NULL); if (dns_type_is_zone_transfer(p.type)) - return varlink_error(link, "io.systemd.Resolve.ZoneTransfersNotPermitted", NULL); + return sd_varlink_error(link, "io.systemd.Resolve.ZoneTransfersNotPermitted", NULL); if (dns_type_is_obsolete(p.type)) - return varlink_error(link, "io.systemd.Resolve.ResourceRecordTypeObsolete", NULL); + return sd_varlink_error(link, "io.systemd.Resolve.ResourceRecordTypeObsolete", NULL); if (!validate_and_mangle_flags(p.name, &p.flags, SD_RESOLVED_NO_SEARCH)) - return varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); + return sd_varlink_error_invalid_parameter(link, JSON_VARIANT_STRING_CONST("flags")); _cleanup_(dns_question_unrefp) DnsQuestion *question = dns_question_new(1); if (!question) @@ -1216,8 +1216,8 @@ static int vl_method_resolve_record(Varlink *link, sd_json_variant *parameters, if (r < 0) return r; - q->varlink_request = varlink_ref(link); - varlink_set_userdata(link, q); + q->varlink_request = sd_varlink_ref(link); + sd_varlink_set_userdata(link, q); q->complete = vl_method_resolve_record_complete; r = dns_query_go(q); @@ -1228,38 +1228,38 @@ static int vl_method_resolve_record(Varlink *link, sd_json_variant *parameters, return 1; } -static int vl_method_subscribe_query_results(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_subscribe_query_results(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Manager *m; int r; assert(link); - m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link))); + m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link))); /* if the client didn't set the more flag, it is using us incorrectly */ - if (!FLAGS_SET(flags, VARLINK_METHOD_MORE)) - return varlink_error(link, VARLINK_ERROR_EXPECTED_MORE, NULL); + if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE)) + return sd_varlink_error(link, SD_VARLINK_ERROR_EXPECTED_MORE, NULL); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); /* Send a ready message to the connecting client, to indicate that we are now listinening, and all * queries issued after the point the client sees this will also be reported to the client. */ - r = varlink_notifybo(link, SD_JSON_BUILD_PAIR("ready", SD_JSON_BUILD_BOOLEAN(true))); + r = sd_varlink_notifybo(link, SD_JSON_BUILD_PAIR("ready", SD_JSON_BUILD_BOOLEAN(true))); if (r < 0) return log_error_errno(r, "Failed to report monitor to be established: %m"); r = set_ensure_put(&m->varlink_subscription, NULL, link); if (r < 0) return log_error_errno(r, "Failed to add subscription to set: %m"); - varlink_ref(link); + sd_varlink_ref(link); log_debug("%u clients now attached for varlink notifications", set_size(m->varlink_subscription)); return 1; } -static int vl_method_dump_cache(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_dump_cache(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *list = NULL; Manager *m; int r; @@ -1267,9 +1267,9 @@ static int vl_method_dump_cache(Varlink *link, sd_json_variant *parameters, Varl assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link))); + m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link))); LIST_FOREACH(scopes, s, m->dns_scopes) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL; @@ -1289,7 +1289,7 @@ static int vl_method_dump_cache(Varlink *link, sd_json_variant *parameters, Varl return r; } - return varlink_replybo(link, SD_JSON_BUILD_PAIR("dump", SD_JSON_BUILD_VARIANT(list))); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR("dump", SD_JSON_BUILD_VARIANT(list))); } static int dns_server_dump_state_to_json_list(DnsServer *server, sd_json_variant **list) { @@ -1306,7 +1306,7 @@ static int dns_server_dump_state_to_json_list(DnsServer *server, sd_json_variant return sd_json_variant_append_array(list, j); } -static int vl_method_dump_server_state(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_dump_server_state(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *list = NULL; Manager *m; int r; @@ -1315,9 +1315,9 @@ static int vl_method_dump_server_state(Varlink *link, sd_json_variant *parameter assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link))); + m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link))); LIST_FOREACH(servers, server, m->dns_servers) { r = dns_server_dump_state_to_json_list(server, &list); @@ -1344,10 +1344,10 @@ static int vl_method_dump_server_state(Varlink *link, sd_json_variant *parameter return r; } - return varlink_replybo(link, SD_JSON_BUILD_PAIR("dump", SD_JSON_BUILD_VARIANT(list))); + return sd_varlink_replybo(link, SD_JSON_BUILD_PAIR("dump", SD_JSON_BUILD_VARIANT(list))); } -static int vl_method_dump_statistics(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_dump_statistics(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL; Manager *m; int r; @@ -1355,34 +1355,34 @@ static int vl_method_dump_statistics(Varlink *link, sd_json_variant *parameters, assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link))); + m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link))); r = dns_manager_dump_statistics_json(m, &j); if (r < 0) return r; - return varlink_replyb(link, SD_JSON_BUILD_VARIANT(j)); + return sd_varlink_replyb(link, SD_JSON_BUILD_VARIANT(j)); } -static int vl_method_reset_statistics(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_reset_statistics(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { Manager *m; assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link))); + m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link))); dns_manager_reset_statistics(m); - return varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); + return sd_varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT); } static int varlink_monitor_server_init(Manager *m) { - _cleanup_(varlink_server_unrefp) VarlinkServer *server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *server = NULL; int r; assert(m); @@ -1390,17 +1390,17 @@ static int varlink_monitor_server_init(Manager *m) { if (m->varlink_monitor_server) return 0; - r = varlink_server_new(&server, VARLINK_SERVER_ROOT_ONLY); + r = sd_varlink_server_new(&server, SD_VARLINK_SERVER_ROOT_ONLY); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(server, m); + sd_varlink_server_set_userdata(server, m); - r = varlink_server_add_interface(server, &vl_interface_io_systemd_Resolve_Monitor); + r = sd_varlink_server_add_interface(server, &vl_interface_io_systemd_Resolve_Monitor); if (r < 0) return log_error_errno(r, "Failed to add Resolve.Monitor interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( server, "io.systemd.Resolve.Monitor.SubscribeQueryResults", vl_method_subscribe_query_results, "io.systemd.Resolve.Monitor.DumpCache", vl_method_dump_cache, @@ -1410,15 +1410,15 @@ static int varlink_monitor_server_init(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to register varlink methods: %m"); - r = varlink_server_bind_disconnect(server, vl_on_notification_disconnect); + r = sd_varlink_server_bind_disconnect(server, vl_on_notification_disconnect); if (r < 0) return log_error_errno(r, "Failed to register varlink disconnect handler: %m"); - r = varlink_server_listen_address(server, "/run/systemd/resolve/io.systemd.Resolve.Monitor", 0600); + r = sd_varlink_server_listen_address(server, "/run/systemd/resolve/io.systemd.Resolve.Monitor", 0600); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(server, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(server, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); @@ -1428,7 +1428,7 @@ static int varlink_monitor_server_init(Manager *m) { } static int varlink_main_server_init(Manager *m) { - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; int r; assert(m); @@ -1436,17 +1436,17 @@ static int varlink_main_server_init(Manager *m) { if (m->varlink_server) return 0; - r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID); + r = sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); - varlink_server_set_userdata(s, m); + sd_varlink_server_set_userdata(s, m); - r = varlink_server_add_interface(s, &vl_interface_io_systemd_Resolve); + r = sd_varlink_server_add_interface(s, &vl_interface_io_systemd_Resolve); if (r < 0) return log_error_errno(r, "Failed to add Resolve interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( s, "io.systemd.Resolve.ResolveHostname", vl_method_resolve_hostname, "io.systemd.Resolve.ResolveAddress", vl_method_resolve_address, @@ -1455,15 +1455,15 @@ static int varlink_main_server_init(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to register varlink methods: %m"); - r = varlink_server_bind_disconnect(s, vl_on_disconnect); + r = sd_varlink_server_bind_disconnect(s, vl_on_disconnect); if (r < 0) return log_error_errno(r, "Failed to register varlink disconnect handler: %m"); - r = varlink_server_listen_address(s, "/run/systemd/resolve/io.systemd.Resolve", 0666); + r = sd_varlink_server_listen_address(s, "/run/systemd/resolve/io.systemd.Resolve", 0666); if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket: %m"); - r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); @@ -1488,6 +1488,6 @@ int manager_varlink_init(Manager *m) { void manager_varlink_done(Manager *m) { assert(m); - m->varlink_server = varlink_server_unref(m->varlink_server); - m->varlink_monitor_server = varlink_server_unref(m->varlink_monitor_server); + m->varlink_server = sd_varlink_server_unref(m->varlink_server); + m->varlink_monitor_server = sd_varlink_server_unref(m->varlink_monitor_server); } diff --git a/src/shared/bus-polkit.c b/src/shared/bus-polkit.c index 00c55463c8..ed884c3001 100644 --- a/src/shared/bus-polkit.c +++ b/src/shared/bus-polkit.c @@ -7,6 +7,7 @@ #include "process-util.h" #include "strv.h" #include "user-util.h" +#include "varlink-util.h" static int bus_message_check_good_user(sd_bus_message *m, uid_t good_user) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; @@ -190,7 +191,7 @@ typedef struct AsyncPolkitQuery { sd_bus *bus; sd_bus_message *request; /* the original bus method call that triggered the polkit auth, NULL in case of varlink */ sd_bus_slot *slot; - Varlink *link; /* the original varlink method call that triggered the polkit auth, NULL in case of bus */ + sd_varlink *link; /* the original varlink method call that triggered the polkit auth, NULL in case of bus */ Hashmap *registry; sd_event_source *defer_event_source; @@ -218,7 +219,7 @@ static AsyncPolkitQuery *async_polkit_query_free(AsyncPolkitQuery *q) { sd_bus_message_unref(q->request); sd_bus_unref(q->bus); - varlink_unref(q->link); + sd_varlink_unref(q->link); async_polkit_query_action_free(q->action); @@ -374,7 +375,7 @@ static int async_polkit_process_reply(sd_bus_message *reply, AsyncPolkitQuery *q } if (q->link) { - r = varlink_dispatch_again(q->link); + r = sd_varlink_dispatch_again(q->link); if (r < 0) return r; } @@ -394,7 +395,7 @@ static int async_polkit_callback(sd_bus_message *reply, void *userdata, sd_bus_e if (q->request) (void) sd_bus_reply_method_errno(q->request, r, NULL); if (q->link) - (void) varlink_error_errno(q->link, r); + (void) sd_varlink_error_errno(q->link, r); async_polkit_query_unref(q); } return r; @@ -625,7 +626,7 @@ int bus_verify_polkit_async_full( #endif } -static int varlink_check_good_user(Varlink *link, uid_t good_user) { +static int varlink_check_good_user(sd_varlink *link, uid_t good_user) { int r; assert(link); @@ -634,20 +635,20 @@ static int varlink_check_good_user(Varlink *link, uid_t good_user) { return false; uid_t peer_uid; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; return good_user == peer_uid; } -static int varlink_check_peer_privilege(Varlink *link) { +static int varlink_check_peer_privilege(sd_varlink *link) { int r; assert(link); uid_t peer_uid; - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) return r; @@ -659,7 +660,7 @@ static int varlink_check_peer_privilege(Varlink *link) { #if ENABLE_POLKIT static int bus_message_new_polkit_auth_call_for_varlink( sd_bus *bus, - Varlink *link, + sd_varlink *link, const char *action, const char **details, bool interactive, @@ -681,7 +682,7 @@ static int bus_message_new_polkit_auth_call_for_varlink( return log_debug_errno(SYNTHETIC_ERRNO(EPERM), "Failed to get peer pidfd, cannot securely authenticate."); uid_t uid; - r = varlink_get_peer_uid(link, &uid); + r = sd_varlink_get_peer_uid(link, &uid); if (r < 0) return r; @@ -717,7 +718,7 @@ static int bus_message_new_polkit_auth_call_for_varlink( return 0; } -static bool varlink_allow_interactive_authentication(Varlink *link) { +static bool varlink_allow_interactive_authentication(sd_varlink *link) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; int r; @@ -726,7 +727,7 @@ static bool varlink_allow_interactive_authentication(Varlink *link) { /* We look for the allowInteractiveAuthentication field in the message currently being dispatched, * always under the same name. */ - r = varlink_get_current_parameters(link, &v); + r = sd_varlink_get_current_parameters(link, &v); if (r < 0) { log_debug_errno(r, "Unable to query current parameters: %m"); return false; @@ -746,7 +747,7 @@ static bool varlink_allow_interactive_authentication(Varlink *link) { #endif int varlink_verify_polkit_async_full( - Varlink *link, + sd_varlink *link, sd_bus *bus, const char *action, const char **details, @@ -789,9 +790,9 @@ int varlink_verify_polkit_async_full( if (!FLAGS_SET(flags, POLKIT_DONT_REPLY)) { /* Reply with a nice error */ if (sd_bus_error_has_name(&error, SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED)) - (void) varlink_error(link, VARLINK_ERROR_INTERACTIVE_AUTHENTICATION_REQUIRED, NULL); + (void) sd_varlink_error(link, SD_VARLINK_ERROR_INTERACTIVE_AUTHENTICATION_REQUIRED, NULL); else if (ERRNO_IS_NEG_PRIVILEGE(r)) - (void) varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL); + (void) sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL); } return r; @@ -806,7 +807,7 @@ int varlink_verify_polkit_async_full( if (r < 0) return r; - r = sd_bus_attach_event(mybus, varlink_get_event(link), 0); + r = sd_bus_attach_event(mybus, sd_varlink_get_event(link), 0); if (r < 0) return r; @@ -829,7 +830,7 @@ int varlink_verify_polkit_async_full( *q = (AsyncPolkitQuery) { .n_ref = 1, - .link = varlink_ref(link), + .link = sd_varlink_ref(link), .bus = sd_bus_ref(bus), }; } @@ -866,7 +867,7 @@ int varlink_verify_polkit_async_full( #endif } -bool varlink_has_polkit_action(Varlink *link, const char *action, const char **details, Hashmap **registry) { +bool varlink_has_polkit_action(sd_varlink *link, const char *action, const char **details, Hashmap **registry) { assert(link); assert(action); assert(registry); diff --git a/src/shared/bus-polkit.h b/src/shared/bus-polkit.h index ba83cedbe1..3ee9a41d39 100644 --- a/src/shared/bus-polkit.h +++ b/src/shared/bus-polkit.h @@ -2,10 +2,10 @@ #pragma once #include "sd-bus.h" +#include "sd-varlink.h" #include "hashmap.h" #include "user-util.h" -#include "varlink.h" typedef enum PolkitFLags { POLKIT_ALLOW_INTERACTIVE = 1 << 0, /* Allow interactive auth (typically not required, because can be derived from bus message/link automatically) */ @@ -21,8 +21,8 @@ static inline int bus_verify_polkit_async(sd_bus_message *call, const char *acti return bus_verify_polkit_async_full(call, action, details, UID_INVALID, 0, registry, error); } -int varlink_verify_polkit_async_full(Varlink *link, sd_bus *bus, const char *action, const char **details, uid_t good_user, PolkitFlags flags, Hashmap **registry); -static inline int varlink_verify_polkit_async(Varlink *link, sd_bus *bus, const char *action, const char **details, Hashmap **registry) { +int varlink_verify_polkit_async_full(sd_varlink *link, sd_bus *bus, const char *action, const char **details, uid_t good_user, PolkitFlags flags, Hashmap **registry); +static inline int varlink_verify_polkit_async(sd_varlink *link, sd_bus *bus, const char *action, const char **details, Hashmap **registry) { return varlink_verify_polkit_async_full(link, bus, action, details, UID_INVALID, 0, registry); } @@ -34,4 +34,4 @@ static inline int varlink_verify_polkit_async(Varlink *link, sd_bus *bus, const .type = SD_JSON_VARIANT_BOOLEAN, \ } -bool varlink_has_polkit_action(Varlink *link, const char *action, const char **details, Hashmap **registry); +bool varlink_has_polkit_action(sd_varlink *link, const char *action, const char **details, Hashmap **registry); diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index ba3c448db0..cdfadf3a09 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -8,6 +8,7 @@ #include "sd-id128.h" #include "sd-json.h" +#include "sd-varlink.h" #include "blockdev-util.h" #include "capability-util.h" @@ -36,7 +37,6 @@ #include "tmpfile-util.h" #include "tpm2-util.h" #include "user-util.h" -#include "varlink.h" #define PUBLIC_KEY_MAX (UINT32_C(1024) * UINT32_C(1024)) @@ -1526,18 +1526,18 @@ int decrypt_credential_and_warn(const char *validate_name, usec_t validate_times #endif int ipc_encrypt_credential(const char *name, usec_t timestamp, usec_t not_after, uid_t uid, const struct iovec *input, CredentialFlags flags, struct iovec *ret) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; assert(input && iovec_is_valid(input)); assert(ret); - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.Credentials"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.Credentials"); if (r < 0) return log_error_errno(r, "Failed to connect to io.systemd.Credentials: %m"); /* Mark anything we get from the service as sensitive, given that it might use a NULL cypher, at least in theory */ - r = varlink_set_input_sensitive(vl); + r = sd_varlink_set_input_sensitive(vl); if (r < 0) return log_error_errno(r, "Failed to enable sensitive Varlink input: %m"); @@ -1551,7 +1551,7 @@ int ipc_encrypt_credential(const char *name, usec_t timestamp, usec_t not_after, _cleanup_(sd_json_variant_unrefp) sd_json_variant *reply = NULL; const char *error_id = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.Credentials.Encrypt", &reply, @@ -1568,7 +1568,7 @@ int ipc_encrypt_credential(const char *name, usec_t timestamp, usec_t not_after, if (streq(error_id, "io.systemd.Credentials.NoSuchUser")) return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "No such user."); - return log_error_errno(varlink_error_to_errno(error_id, reply), "Failed to encrypt: %s", error_id); + return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to encrypt: %s", error_id); } r = sd_json_dispatch( @@ -1586,17 +1586,17 @@ int ipc_encrypt_credential(const char *name, usec_t timestamp, usec_t not_after, } int ipc_decrypt_credential(const char *validate_name, usec_t validate_timestamp, uid_t uid, const struct iovec *input, CredentialFlags flags, struct iovec *ret) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; assert(input && iovec_is_valid(input)); assert(ret); - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.Credentials"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.Credentials"); if (r < 0) return log_error_errno(r, "Failed to connect to io.systemd.Credentials: %m"); - r = varlink_set_input_sensitive(vl); + r = sd_varlink_set_input_sensitive(vl); if (r < 0) return log_error_errno(r, "Failed to enable sensitive Varlink input: %m"); @@ -1611,7 +1611,7 @@ int ipc_decrypt_credential(const char *validate_name, usec_t validate_timestamp, _cleanup_(sd_json_variant_unrefp) sd_json_variant *reply = NULL; const char *error_id = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.Credentials.Decrypt", &reply, @@ -1635,7 +1635,7 @@ int ipc_decrypt_credential(const char *validate_name, usec_t validate_timestamp, if (streq(error_id, "io.systemd.Credentials.BadScope")) return log_error_errno(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Scope mismtach."); - return log_error_errno(varlink_error_to_errno(error_id, reply), "Failed to decrypt: %s", error_id); + return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to decrypt: %s", error_id); } r = sd_json_dispatch( diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 28c2d7dbc0..ef730103b5 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -21,6 +21,7 @@ #include "sd-device.h" #include "sd-id128.h" #include "sd-json.h" +#include "sd-varlink.h" #include "architecture.h" #include "ask-password-api.h" @@ -77,7 +78,6 @@ #include "tmpfile-util.h" #include "udev-util.h" #include "user-util.h" -#include "varlink.h" #include "xattr-util.h" /* how many times to wait for the device nodes to appear */ @@ -4269,7 +4269,7 @@ int mountfsd_mount_image( _cleanup_(dissected_image_unrefp) DissectedImage *di = NULL; _cleanup_close_ int image_fd = -EBADF; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; _cleanup_free_ char *ps = NULL; unsigned max_fd = UINT_MAX; const char *error_id; @@ -4278,15 +4278,15 @@ int mountfsd_mount_image( assert(path); assert(ret); - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.MountFileSystem"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.MountFileSystem"); if (r < 0) return log_error_errno(r, "Failed to connect to mountfsd: %m"); - r = varlink_set_allow_fd_passing_input(vl, true); + r = sd_varlink_set_allow_fd_passing_input(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable varlink fd passing for read: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable varlink fd passing for write: %m"); @@ -4294,12 +4294,12 @@ int mountfsd_mount_image( if (image_fd < 0) return log_error_errno(errno, "Failed to open '%s': %m", path); - r = varlink_push_dup_fd(vl, image_fd); + r = sd_varlink_push_dup_fd(vl, image_fd); if (r < 0) return log_error_errno(r, "Failed to push image fd into varlink connection: %m"); if (userns_fd >= 0) { - r = varlink_push_dup_fd(vl, userns_fd); + r = sd_varlink_push_dup_fd(vl, userns_fd); if (r < 0) return log_error_errno(r, "Failed to push image fd into varlink connection: %m"); } @@ -4311,7 +4311,7 @@ int mountfsd_mount_image( } sd_json_variant *reply = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.MountFileSystem.MountImage", &reply, @@ -4325,7 +4325,7 @@ int mountfsd_mount_image( if (r < 0) return log_error_errno(r, "Failed to call MountImage() varlink call: %m"); if (!isempty(error_id)) - return log_error_errno(varlink_error_to_errno(error_id, reply), "Failed to call MountImage() varlink call: %s", error_id); + return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to call MountImage() varlink call: %s", error_id); r = sd_json_dispatch(reply, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &p); if (r < 0) @@ -4368,7 +4368,7 @@ int mountfsd_mount_image( if (max_fd == UINT_MAX || pp.fsmount_fd_idx > max_fd) max_fd = pp.fsmount_fd_idx; - fsmount_fd = varlink_take_fd(vl, pp.fsmount_fd_idx); + fsmount_fd = sd_varlink_take_fd(vl, pp.fsmount_fd_idx); if (fsmount_fd < 0) return fsmount_fd; } diff --git a/src/shared/meson.build b/src/shared/meson.build index 2250af703a..8fc39429e5 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -175,9 +175,6 @@ shared_sources = files( 'user-record.c', 'userdb-dropin.c', 'userdb.c', - 'varlink.c', - 'varlink-idl.c', - 'varlink-io.systemd.c', 'varlink-io.systemd.BootControl.c', 'varlink-io.systemd.Credentials.c', 'varlink-io.systemd.Hostname.c', @@ -196,7 +193,7 @@ shared_sources = files( 'varlink-io.systemd.oom.c', 'varlink-io.systemd.service.c', 'varlink-io.systemd.sysext.c', - 'varlink-org.varlink.service.c', + 'varlink-serialize.c', 'verb-log-control.c', 'verbs.c', 'vlan-util.c', diff --git a/src/shared/nsresource.c b/src/shared/nsresource.c index 5a34301377..4a2a9d2e41 100644 --- a/src/shared/nsresource.c +++ b/src/shared/nsresource.c @@ -2,6 +2,8 @@ #include <sys/prctl.h> +#include "sd-varlink.h" + #include "fd-util.h" #include "format-util.h" #include "json-util.h" @@ -9,7 +11,6 @@ #include "namespace-util.h" #include "nsresource.h" #include "process-util.h" -#include "varlink.h" static int make_pid_name(char **ret) { char comm[TASK_COMM_LEN]; @@ -40,7 +41,7 @@ static int make_pid_name(char **ret) { } int nsresource_allocate_userns(const char *name, uint64_t size) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; _cleanup_close_ int userns_fd = -EBADF; _cleanup_free_ char *_name = NULL; const char *error_id; @@ -59,11 +60,11 @@ int nsresource_allocate_userns(const char *name, uint64_t size) { if (size <= 0 || size > UINT64_C(0x100000000)) /* Note: the server actually only allows allocating 1 or 64K right now */ return -EINVAL; - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); if (r < 0) return log_debug_errno(r, "Failed to connect to namespace resource manager: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_debug_errno(r, "Failed to enable varlink fd passing for write: %m"); @@ -71,12 +72,12 @@ int nsresource_allocate_userns(const char *name, uint64_t size) { if (userns_fd < 0) return log_debug_errno(userns_fd, "Failed to acquire empty user namespace: %m"); - userns_fd_idx = varlink_push_dup_fd(vl, userns_fd); + userns_fd_idx = sd_varlink_push_dup_fd(vl, userns_fd); if (userns_fd_idx < 0) return log_debug_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); sd_json_variant *reply = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.NamespaceResource.AllocateUserRange", &reply, @@ -87,13 +88,13 @@ int nsresource_allocate_userns(const char *name, uint64_t size) { if (r < 0) return log_debug_errno(r, "Failed to call AllocateUserRange() varlink call: %m"); if (error_id) - return log_debug_errno(varlink_error_to_errno(error_id, reply), "Failed to allocate user namespace with %" PRIu64 " users: %s", size, error_id); + return log_debug_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to allocate user namespace with %" PRIu64 " users: %s", size, error_id); return TAKE_FD(userns_fd); } int nsresource_register_userns(const char *name, int userns_fd) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; _cleanup_close_ int _userns_fd = -EBADF; _cleanup_free_ char *_name = NULL; const char *error_id; @@ -117,20 +118,20 @@ int nsresource_register_userns(const char *name, int userns_fd) { userns_fd = _userns_fd; } - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); if (r < 0) return log_debug_errno(r, "Failed to connect to namespace resource manager: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_debug_errno(r, "Failed to enable varlink fd passing for write: %m"); - userns_fd_idx = varlink_push_dup_fd(vl, userns_fd); + userns_fd_idx = sd_varlink_push_dup_fd(vl, userns_fd); if (userns_fd_idx < 0) return log_debug_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); sd_json_variant *reply = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.NamespaceResource.RegisterUserNamespace", &reply, @@ -140,13 +141,13 @@ int nsresource_register_userns(const char *name, int userns_fd) { if (r < 0) return log_debug_errno(r, "Failed to call RegisterUserNamespace() varlink call: %m"); if (error_id) - return log_debug_errno(varlink_error_to_errno(error_id, reply), "Failed to register user namespace: %s", error_id); + return log_debug_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to register user namespace: %s", error_id); return 0; } int nsresource_add_mount(int userns_fd, int mount_fd) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; _cleanup_close_ int _userns_fd = -EBADF; int r, userns_fd_idx, mount_fd_idx; const char *error_id; @@ -161,24 +162,24 @@ int nsresource_add_mount(int userns_fd, int mount_fd) { userns_fd = _userns_fd; } - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); if (r < 0) return log_error_errno(r, "Failed to connect to namespace resource manager: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_error_errno(r, "Failed to enable varlink fd passing for write: %m"); - userns_fd_idx = varlink_push_dup_fd(vl, userns_fd); + userns_fd_idx = sd_varlink_push_dup_fd(vl, userns_fd); if (userns_fd_idx < 0) return log_error_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); - mount_fd_idx = varlink_push_dup_fd(vl, mount_fd); + mount_fd_idx = sd_varlink_push_dup_fd(vl, mount_fd); if (mount_fd_idx < 0) return log_error_errno(mount_fd_idx, "Failed to push mount fd into varlink connection: %m"); sd_json_variant *reply = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.NamespaceResource.AddMountToUserNamespace", &reply, @@ -192,13 +193,13 @@ int nsresource_add_mount(int userns_fd, int mount_fd) { return 0; } if (error_id) - return log_error_errno(varlink_error_to_errno(error_id, reply), "Failed to mount image: %s", error_id); + return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to mount image: %s", error_id); return 1; } int nsresource_add_cgroup(int userns_fd, int cgroup_fd) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; _cleanup_close_ int _userns_fd = -EBADF; int r, userns_fd_idx, cgroup_fd_idx; const char *error_id; @@ -213,24 +214,24 @@ int nsresource_add_cgroup(int userns_fd, int cgroup_fd) { userns_fd = _userns_fd; } - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); if (r < 0) return log_debug_errno(r, "Failed to connect to namespace resource manager: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_debug_errno(r, "Failed to enable varlink fd passing for write: %m"); - userns_fd_idx = varlink_push_dup_fd(vl, userns_fd); + userns_fd_idx = sd_varlink_push_dup_fd(vl, userns_fd); if (userns_fd_idx < 0) return log_debug_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); - cgroup_fd_idx = varlink_push_dup_fd(vl, cgroup_fd); + cgroup_fd_idx = sd_varlink_push_dup_fd(vl, cgroup_fd); if (cgroup_fd_idx < 0) return log_debug_errno(userns_fd_idx, "Failed to push cgroup fd into varlink connection: %m"); sd_json_variant *reply = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.NamespaceResource.AddControlGroupToUserNamespace", &reply, @@ -244,7 +245,7 @@ int nsresource_add_cgroup(int userns_fd, int cgroup_fd) { return 0; } if (error_id) - return log_debug_errno(varlink_error_to_errno(error_id, reply), "Failed to add cgroup to user namespace: %s", error_id); + return log_debug_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to add cgroup to user namespace: %s", error_id); return 1; } @@ -257,7 +258,7 @@ int nsresource_add_netif( char **ret_namespace_ifname) { _cleanup_close_ int _userns_fd = -EBADF, _netns_fd = -EBADF; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r, userns_fd_idx, netns_fd_idx; const char *error_id; @@ -277,24 +278,24 @@ int nsresource_add_netif( netns_fd = _netns_fd; } - r = varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); + r = sd_varlink_connect_address(&vl, "/run/systemd/io.systemd.NamespaceResource"); if (r < 0) return log_debug_errno(r, "Failed to connect to namespace resource manager: %m"); - r = varlink_set_allow_fd_passing_output(vl, true); + r = sd_varlink_set_allow_fd_passing_output(vl, true); if (r < 0) return log_debug_errno(r, "Failed to enable varlink fd passing for write: %m"); - userns_fd_idx = varlink_push_dup_fd(vl, userns_fd); + userns_fd_idx = sd_varlink_push_dup_fd(vl, userns_fd); if (userns_fd_idx < 0) return log_debug_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); - netns_fd_idx = varlink_push_dup_fd(vl, netns_fd); + netns_fd_idx = sd_varlink_push_dup_fd(vl, netns_fd); if (netns_fd_idx < 0) return log_debug_errno(netns_fd_idx, "Failed to push netns fd into varlink connection: %m"); sd_json_variant *reply = NULL; - r = varlink_callbo( + r = sd_varlink_callbo( vl, "io.systemd.NamespaceResource.AddNetworkToUserNamespace", &reply, @@ -310,7 +311,7 @@ int nsresource_add_netif( return 0; } if (error_id) - return log_debug_errno(varlink_error_to_errno(error_id, reply), "Failed to add network to user namespace: %s", 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( diff --git a/src/shared/userdb.c b/src/shared/userdb.c index 2eff470ec9..c893876eaf 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -2,6 +2,8 @@ #include <sys/auxv.h> +#include "sd-varlink.h" + #include "conf-files.h" #include "dirent-util.h" #include "dlfcn-util.h" @@ -18,9 +20,8 @@ #include "user-util.h" #include "userdb-dropin.h" #include "userdb.h" -#include "varlink.h" -DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(link_hash_ops, void, trivial_hash_func, trivial_compare_func, Varlink, varlink_unref); +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(link_hash_ops, void, trivial_hash_func, trivial_compare_func, sd_varlink, sd_varlink_unref); typedef enum LookupWhat { LOOKUP_USER, @@ -158,10 +159,10 @@ static void membership_data_done(struct membership_data *d) { } static int userdb_on_query_reply( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, const char *error_id, - VarlinkReplyFlags flags, + sd_varlink_reply_flags_t flags, void *userdata) { UserDBIterator *iterator = ASSERT_PTR(userdata); @@ -178,7 +179,7 @@ static int userdb_on_query_reply( r = -EHOSTDOWN; else if (streq(error_id, "io.systemd.UserDatabase.EnumerationNotSupported")) r = -EOPNOTSUPP; - else if (streq(error_id, VARLINK_ERROR_TIMEOUT)) + else if (streq(error_id, SD_VARLINK_ERROR_TIMEOUT)) r = -ETIMEDOUT; else r = -EIO; @@ -237,7 +238,7 @@ static int userdb_on_query_reply( iterator->n_found++; /* More stuff coming? then let's just exit cleanly here */ - if (FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) return 0; /* Otherwise, let's remove this link and exit cleanly then */ @@ -291,7 +292,7 @@ static int userdb_on_query_reply( iterator->found_group = TAKE_PTR(g); iterator->n_found++; - if (FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) return 0; r = 0; @@ -318,7 +319,7 @@ static int userdb_on_query_reply( iterator->found_group_name = TAKE_PTR(membership_data.group_name); iterator->n_found++; - if (FLAGS_SET(flags, VARLINK_REPLY_CONTINUES)) + if (FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) return 0; r = 0; @@ -336,7 +337,7 @@ finish: iterator->error = -r; assert_se(set_remove(iterator->links, link) == link); - link = varlink_unref(link); + link = sd_varlink_unref(link); return 0; } @@ -347,18 +348,18 @@ static int userdb_connect( bool more, sd_json_variant *query) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; assert(iterator); assert(path); assert(method); - r = varlink_connect_address(&vl, path); + r = sd_varlink_connect_address(&vl, path); if (r < 0) return log_debug_errno(r, "Unable to connect to %s: %m", path); - varlink_set_userdata(vl, iterator); + sd_varlink_set_userdata(vl, iterator); if (!iterator->event) { r = sd_event_new(&iterator->event); @@ -366,20 +367,20 @@ static int userdb_connect( return log_debug_errno(r, "Unable to allocate event loop: %m"); } - r = varlink_attach_event(vl, iterator->event, SD_EVENT_PRIORITY_NORMAL); + r = sd_varlink_attach_event(vl, iterator->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_debug_errno(r, "Failed to attach varlink connection to event loop: %m"); - (void) varlink_set_description(vl, path); + (void) sd_varlink_set_description(vl, path); - r = varlink_bind_reply(vl, userdb_on_query_reply); + r = sd_varlink_bind_reply(vl, userdb_on_query_reply); if (r < 0) return log_debug_errno(r, "Failed to bind reply callback: %m"); if (more) - r = varlink_observe(vl, method, query); + r = sd_varlink_observe(vl, method, query); else - r = varlink_invoke(vl, method, query); + r = sd_varlink_invoke(vl, method, query); if (r < 0) return log_debug_errno(r, "Failed to invoke varlink method: %m"); diff --git a/src/shared/varlink-idl.h b/src/shared/varlink-idl.h deleted file mode 100644 index ffb55f3066..0000000000 --- a/src/shared/varlink-idl.h +++ /dev/null @@ -1,182 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include <errno.h> -#include <stdbool.h> -#include <stdio.h> - -#include "sd-json.h" -#include "macro.h" - -/* This implements the Varlink Interface Definition Language ("Varlink IDL"), - * i.e. https://varlink.org/Interface-Definition - * - * Primarily allows encoding static interface definitions in C code, that can be converted to the textual IDL - * format on-the-fly. Can also parse the textual format back to C structures. Validates the interface - * definitions for internal consistency and validates JSON objects against the interface definitions. */ - -typedef enum VarlinkSymbolType { - VARLINK_ENUM_TYPE, - VARLINK_STRUCT_TYPE, - VARLINK_METHOD, - VARLINK_ERROR, - _VARLINK_INTERFACE_COMMENT, /* Not really a symbol, just a comment about the interface */ - _VARLINK_SYMBOL_COMMENT, /* Not really a symbol, just a comment about a symbol */ - _VARLINK_SYMBOL_TYPE_MAX, - _VARLINK_SYMBOL_TYPE_INVALID = -EINVAL, -} VarlinkSymbolType; - -typedef enum VarlinkFieldType { - _VARLINK_FIELD_TYPE_END_MARKER = 0, /* zero type means: this is the last entry in the fields[] array of VarlinkSymbol */ - VARLINK_STRUCT, - VARLINK_ENUM, - VARLINK_NAMED_TYPE, - VARLINK_BOOL, - VARLINK_INT, - VARLINK_FLOAT, - VARLINK_STRING, - VARLINK_OBJECT, - VARLINK_ENUM_VALUE, - _VARLINK_FIELD_COMMENT, /* Not really a field, just a comment about a field*/ - _VARLINK_FIELD_TYPE_MAX, - _VARLINK_FIELD_TYPE_INVALID = -EINVAL, -} VarlinkFieldType; - -typedef enum VarlinkFieldDirection { - VARLINK_REGULAR, - VARLINK_INPUT, - VARLINK_OUTPUT, - _VARLINK_FIELD_DIRECTION_MAX, - _VARLINK_FIELD_DIRECTION_INVALID = -EINVAL, -} VarlinkFieldDirection; - -typedef enum VarlinkFieldFlags { - VARLINK_ARRAY = 1 << 0, - VARLINK_MAP = 1 << 1, - VARLINK_NULLABLE = 1 << 2, - _VARLINK_FIELD_FLAGS_MAX = (1 << 3) - 1, - _VARLINK_FIELD_FLAGS_INVALID = -EINVAL, -} VarlinkFieldFlags; - -typedef struct VarlinkField VarlinkField; -typedef struct VarlinkSymbol VarlinkSymbol; -typedef struct VarlinkInterface VarlinkInterface; - -/* Fields are the components making up symbols */ -struct VarlinkField { - const char *name; - VarlinkFieldType field_type; - VarlinkFieldFlags field_flags; - VarlinkFieldDirection field_direction; /* in case of method call fields: whether input or output argument */ - const VarlinkSymbol *symbol; /* VARLINK_STRUCT, VARLINK_ENUM: anonymous symbol that carries the definitions, VARLINK_NAMED_TYPE: resolved symbol */ - const char *named_type; /* VARLINK_NAMED_TYPE */ -}; - -/* Symbols are primary named concepts in an interface, and are methods, errors or named types (either enum or struct). */ -struct VarlinkSymbol { - const char *name; /* most symbols have a name, but sometimes they are created on-the-fly for fields, in which case they are anonymous */ - VarlinkSymbolType symbol_type; - VarlinkField fields[]; -}; - -/* An interface definition has a name and consist of symbols */ -struct VarlinkInterface { - const char *name; - const VarlinkSymbol *symbols[]; -}; - -#define VARLINK_DEFINE_FIELD(_name, _field_type, _field_flags) \ - { .name = #_name, .field_type = (_field_type), .field_flags = (_field_flags) } - -#define VARLINK_DEFINE_FIELD_BY_TYPE(_name, _named_type, _field_flags) \ - { .name = #_name, .field_type = VARLINK_NAMED_TYPE, .named_type = #_named_type, .symbol = &vl_type_ ## _named_type, .field_flags = (_field_flags) } - -#define VARLINK_DEFINE_INPUT(_name, _field_type, _field_flags) \ - { .name = #_name, .field_type = (_field_type), .field_flags = (_field_flags), .field_direction = VARLINK_INPUT } - -#define VARLINK_DEFINE_INPUT_BY_TYPE(_name, _named_type, _field_flags) \ - { .name = #_name, .field_type = VARLINK_NAMED_TYPE, .named_type = #_named_type, .symbol = &vl_type_ ## _named_type, .field_flags = (_field_flags), .field_direction = VARLINK_INPUT } - -#define VARLINK_DEFINE_OUTPUT(_name, _field_type, _field_flags) \ - { .name = #_name, .field_type = (_field_type), .field_flags = (_field_flags), .field_direction = VARLINK_OUTPUT } - -#define VARLINK_DEFINE_OUTPUT_BY_TYPE(_name, _named_type, _field_flags) \ - { .name = #_name, .field_type = VARLINK_NAMED_TYPE, .named_type = #_named_type, .symbol = &vl_type_ ## _named_type, .field_flags = (_field_flags), .field_direction = VARLINK_OUTPUT } - -#define VARLINK_DEFINE_ENUM_VALUE(_name) \ - { .name = #_name, .field_type = VARLINK_ENUM_VALUE } - -#define VARLINK_FIELD_COMMENT(text) \ - { .name = "" text, .field_type = _VARLINK_FIELD_COMMENT } - -#define VARLINK_DEFINE_METHOD(_name, ...) \ - const VarlinkSymbol vl_method_ ## _name = { \ - .name = #_name, \ - .symbol_type = VARLINK_METHOD, \ - .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ - } - -#define VARLINK_DEFINE_ERROR(_name, ...) \ - const VarlinkSymbol vl_error_ ## _name = { \ - .name = #_name, \ - .symbol_type = VARLINK_ERROR, \ - .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ - } - -#define VARLINK_DEFINE_STRUCT_TYPE(_name, ...) \ - const VarlinkSymbol vl_type_ ## _name = { \ - .name = #_name, \ - .symbol_type = VARLINK_STRUCT_TYPE, \ - .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ - } - -#define VARLINK_DEFINE_ENUM_TYPE(_name, ...) \ - const VarlinkSymbol vl_type_ ## _name = { \ - .name = #_name, \ - .symbol_type = VARLINK_ENUM_TYPE, \ - .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ - } - -#define VARLINK_DEFINE_INTERFACE(_name, _full_name, ...) \ - const VarlinkInterface vl_interface_ ## _name = { \ - .name = (_full_name), \ - .symbols = { __VA_ARGS__ __VA_OPT__(,) NULL}, \ - } - -#define VARLINK_SYMBOL_COMMENT(text) \ - &(const VarlinkSymbol) { \ - .name = "" text, \ - .symbol_type = _VARLINK_SYMBOL_COMMENT, \ - } - -#define VARLINK_INTERFACE_COMMENT(text) \ - &(const VarlinkSymbol) { \ - .name = "" text, \ - .symbol_type = _VARLINK_INTERFACE_COMMENT, \ - } - -int varlink_idl_dump(FILE *f, int use_colors, size_t cols, const VarlinkInterface *interface); -int varlink_idl_format_full(const VarlinkInterface *interface, size_t cols, char **ret); - -static inline int varlink_idl_format(const VarlinkInterface *interface, char **ret) { - return varlink_idl_format_full(interface, SIZE_MAX, ret); -} - -int varlink_idl_parse(const char *text, unsigned *ret_line, unsigned *ret_column, VarlinkInterface **ret); -VarlinkInterface* varlink_interface_free(VarlinkInterface *interface); -DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkInterface*, varlink_interface_free); - -bool varlink_idl_field_name_is_valid(const char *name); -bool varlink_idl_symbol_name_is_valid(const char *name); -bool varlink_idl_interface_name_is_valid(const char *name); - -int varlink_idl_qualified_symbol_name_is_valid(const char *name); - -int varlink_idl_consistent(const VarlinkInterface *interface, int level); - -const VarlinkSymbol* varlink_idl_find_symbol(const VarlinkInterface *interface, VarlinkSymbolType type, const char *name); -const VarlinkField* varlink_idl_find_field(const VarlinkSymbol *symbol, const char *name); - -int varlink_idl_validate_method_call(const VarlinkSymbol *method, sd_json_variant *v, const char **bad_field); -int varlink_idl_validate_method_reply(const VarlinkSymbol *method, sd_json_variant *v, const char **bad_field); -int varlink_idl_validate_error(const VarlinkSymbol *error, sd_json_variant *v, const char **bad_field); diff --git a/src/shared/varlink-internal.h b/src/shared/varlink-internal.h deleted file mode 100644 index 715202a49e..0000000000 --- a/src/shared/varlink-internal.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include <stdio.h> - -#include "fdset.h" -#include "varlink.h" - -int varlink_server_serialize(VarlinkServer *s, FILE *f, FDSet *fds); -int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *fds); diff --git a/src/shared/varlink-io.systemd.BootControl.c b/src/shared/varlink-io.systemd.BootControl.c index 110d4b7be7..449cc98bb4 100644 --- a/src/shared/varlink-io.systemd.BootControl.c +++ b/src/shared/varlink-io.systemd.BootControl.c @@ -2,83 +2,83 @@ #include "varlink-io.systemd.BootControl.h" -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( BootEntryType, - VARLINK_FIELD_COMMENT("Boot Loader Specification Type #1 entries (.conf files)"), - VARLINK_DEFINE_ENUM_VALUE(type1), - VARLINK_FIELD_COMMENT("Boot Loader Specification Type #2 entries (UKIs)"), - VARLINK_DEFINE_ENUM_VALUE(type2), - VARLINK_FIELD_COMMENT("Additional entries reported by boot loader"), - VARLINK_DEFINE_ENUM_VALUE(loader), - VARLINK_FIELD_COMMENT("Automatically generated entries"), - VARLINK_DEFINE_ENUM_VALUE(auto)); + SD_VARLINK_FIELD_COMMENT("Boot Loader Specification Type #1 entries (.conf files)"), + SD_VARLINK_DEFINE_ENUM_VALUE(type1), + SD_VARLINK_FIELD_COMMENT("Boot Loader Specification Type #2 entries (UKIs)"), + SD_VARLINK_DEFINE_ENUM_VALUE(type2), + SD_VARLINK_FIELD_COMMENT("Additional entries reported by boot loader"), + SD_VARLINK_DEFINE_ENUM_VALUE(loader), + SD_VARLINK_FIELD_COMMENT("Automatically generated entries"), + SD_VARLINK_DEFINE_ENUM_VALUE(auto)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( BootEntry, - VARLINK_DEFINE_FIELD_BY_TYPE(type, BootEntryType, 0), - VARLINK_FIELD_COMMENT("The string identifier of the entry"), - VARLINK_DEFINE_FIELD(id, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(path, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(root, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(title, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(showTitle, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(sortKey, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(version, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(machineId, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(architecture, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(options, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(linux, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(efi, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(initrd, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(devicetree, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(devicetreeOverlay, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_FIELD_COMMENT("Indicates whether the boot loader reported this entry on the current boot"), - VARLINK_DEFINE_FIELD(isReported, VARLINK_BOOL, 0), - VARLINK_FIELD_COMMENT("Indicates the number of tries left for this boot entry before it is assumed to be not working."), - VARLINK_DEFINE_FIELD(triesLeft, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Indicates the number of unsuccessful tries already made for this boot entry."), - VARLINK_DEFINE_FIELD(triesDone, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Indicates whether this entry is the default entry."), - VARLINK_DEFINE_FIELD(isDefault, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Indicates whether this entry has been booted."), - VARLINK_DEFINE_FIELD(isSelected, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_FIELD_BY_TYPE(type, BootEntryType, 0), + SD_VARLINK_FIELD_COMMENT("The string identifier of the entry"), + SD_VARLINK_DEFINE_FIELD(id, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(path, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(root, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(title, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(showTitle, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(sortKey, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(version, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(machineId, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(architecture, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(options, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(linux, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(efi, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(initrd, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(devicetree, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(devicetreeOverlay, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_FIELD_COMMENT("Indicates whether the boot loader reported this entry on the current boot"), + SD_VARLINK_DEFINE_FIELD(isReported, SD_VARLINK_BOOL, 0), + SD_VARLINK_FIELD_COMMENT("Indicates the number of tries left for this boot entry before it is assumed to be not working."), + SD_VARLINK_DEFINE_FIELD(triesLeft, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Indicates the number of unsuccessful tries already made for this boot entry."), + SD_VARLINK_DEFINE_FIELD(triesDone, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Indicates whether this entry is the default entry."), + SD_VARLINK_DEFINE_FIELD(isDefault, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Indicates whether this entry has been booted."), + SD_VARLINK_DEFINE_FIELD(isSelected, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ListBootEntries, - VARLINK_FIELD_COMMENT("A boot menu entry structure"), - VARLINK_DEFINE_OUTPUT_BY_TYPE(entry, BootEntry, VARLINK_NULLABLE)); + SD_VARLINK_FIELD_COMMENT("A boot menu entry structure"), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(entry, BootEntry, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( SetRebootToFirmware, - VARLINK_FIELD_COMMENT("The new value of the reboot-to-firmware-UI flag"), - VARLINK_DEFINE_INPUT(state, VARLINK_BOOL, 0)); + SD_VARLINK_FIELD_COMMENT("The new value of the reboot-to-firmware-UI flag"), + SD_VARLINK_DEFINE_INPUT(state, SD_VARLINK_BOOL, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( GetRebootToFirmware, - VARLINK_FIELD_COMMENT("The current state of the reboot-to-firmware-UI flag"), - VARLINK_DEFINE_OUTPUT(state, VARLINK_BOOL, 0)); + SD_VARLINK_FIELD_COMMENT("The current state of the reboot-to-firmware-UI flag"), + SD_VARLINK_DEFINE_OUTPUT(state, SD_VARLINK_BOOL, 0)); -static VARLINK_DEFINE_ERROR( +static SD_VARLINK_DEFINE_ERROR( RebootToFirmwareNotSupported); -static VARLINK_DEFINE_ERROR( +static SD_VARLINK_DEFINE_ERROR( NoSuchBootEntry); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_BootControl, "io.systemd.BootControl", - VARLINK_INTERFACE_COMMENT("Boot Loader control APIs"), - VARLINK_SYMBOL_COMMENT("The type of a boot entry"), + SD_VARLINK_INTERFACE_COMMENT("Boot Loader control APIs"), + SD_VARLINK_SYMBOL_COMMENT("The type of a boot entry"), &vl_type_BootEntryType, - VARLINK_SYMBOL_COMMENT("A structure encapsulating a boot entry"), + SD_VARLINK_SYMBOL_COMMENT("A structure encapsulating a boot entry"), &vl_type_BootEntry, - VARLINK_SYMBOL_COMMENT("Enumerates boot entries. Method call must be called with 'more' flag set. Each response returns one entry. If no entries are defined returns the NoSuchBootEntry error."), + SD_VARLINK_SYMBOL_COMMENT("Enumerates boot entries. Method call must be called with 'more' flag set. Each response returns one entry. If no entries are defined returns the NoSuchBootEntry error."), &vl_method_ListBootEntries, - VARLINK_SYMBOL_COMMENT("Sets the reboot-to-firmware-UI flag of the firmware, if this concept exists. Returns the RebootToFirmwareNotSupported error if not."), + SD_VARLINK_SYMBOL_COMMENT("Sets the reboot-to-firmware-UI flag of the firmware, if this concept exists. Returns the RebootToFirmwareNotSupported error if not."), &vl_method_SetRebootToFirmware, - VARLINK_SYMBOL_COMMENT("Gets the current state of the reboot-to-firmware-UI flag of the firmware, if this concept exists. Returns the RebootToFirmwareNotSupported error if not."), + SD_VARLINK_SYMBOL_COMMENT("Gets the current state of the reboot-to-firmware-UI flag of the firmware, if this concept exists. Returns the RebootToFirmwareNotSupported error if not."), &vl_method_GetRebootToFirmware, - VARLINK_SYMBOL_COMMENT("SetRebootToFirmware() and GetRebootToFirmware() return this if the firmware does not actually support the reboot-to-firmware-UI concept."), + SD_VARLINK_SYMBOL_COMMENT("SetRebootToFirmware() and GetRebootToFirmware() return this if the firmware does not actually support the reboot-to-firmware-UI concept."), &vl_error_RebootToFirmwareNotSupported, - VARLINK_SYMBOL_COMMENT("No boot entry defined."), + SD_VARLINK_SYMBOL_COMMENT("No boot entry defined."), &vl_error_NoSuchBootEntry); diff --git a/src/shared/varlink-io.systemd.BootControl.h b/src/shared/varlink-io.systemd.BootControl.h index fa72b703d1..2c1fecf446 100644 --- a/src/shared/varlink-io.systemd.BootControl.h +++ b/src/shared/varlink-io.systemd.BootControl.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_BootControl; +extern const sd_varlink_interface vl_interface_io_systemd_BootControl; diff --git a/src/shared/varlink-io.systemd.Credentials.c b/src/shared/varlink-io.systemd.Credentials.c index aafdfcb410..4c4f222ec5 100644 --- a/src/shared/varlink-io.systemd.Credentials.c +++ b/src/shared/varlink-io.systemd.Credentials.c @@ -2,65 +2,65 @@ #include "varlink-io.systemd.Credentials.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Encrypt, - VARLINK_FIELD_COMMENT("The name for the encrypted credential, a string suitable for inclusion in a file name. If not specified no name is encoded in the credential. Typically, if this credential is stored on disk, this is how the file should be called, and permits authentication of the filename."), - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Plaintext to encrypt. Suitable only for textual data. Either this field or 'data' (below) must be provided."), - VARLINK_DEFINE_INPUT(text, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Plaintext to encrypt, encoded in Base64. Suitable for binary data. Either this field or 'text' (above) must be provided."), - VARLINK_DEFINE_INPUT(data, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Timestamp to store in the credential. In µs since the UNIX epoch, i.e. Jan 1st 1970. If not specified the current time is used."), - VARLINK_DEFINE_INPUT(timestamp, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Timestamp when to the credential should be considered invalid. In µs since the UNIX epoch. If not specified, the credential remains valid forever."), - VARLINK_DEFINE_INPUT(notAfter, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The intended scope for the credential. One of 'system' or 'user'. If not specified defaults to 'system', unless an uid is specified (see below), in which case it default to 'user'."), - VARLINK_DEFINE_INPUT(scope, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The numeric UNIX UID of the user the credential shall be scoped to. Only relevant if 'user' scope is selected (see above). If not specified and 'user' scope is selected defaults to the UID of the calling user, if that can be determined."), - VARLINK_DEFINE_INPUT(uid, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Controls whether interactive authentication (via polkit) shall be allowed. If unspecified defaults to false."), - VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Encrypted credential in Base64 encoding. This can be stored in a credential file, for consumption in LoadEncryptedCredential= and similar calls. Note that the Base64 encoding should be retained when copied into a file."), - VARLINK_DEFINE_OUTPUT(blob, VARLINK_STRING, 0)); + SD_VARLINK_FIELD_COMMENT("The name for the encrypted credential, a string suitable for inclusion in a file name. If not specified no name is encoded in the credential. Typically, if this credential is stored on disk, this is how the file should be called, and permits authentication of the filename."), + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Plaintext to encrypt. Suitable only for textual data. Either this field or 'data' (below) must be provided."), + SD_VARLINK_DEFINE_INPUT(text, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Plaintext to encrypt, encoded in Base64. Suitable for binary data. Either this field or 'text' (above) must be provided."), + SD_VARLINK_DEFINE_INPUT(data, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Timestamp to store in the credential. In µs since the UNIX epoch, i.e. Jan 1st 1970. If not specified the current time is used."), + SD_VARLINK_DEFINE_INPUT(timestamp, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Timestamp when to the credential should be considered invalid. In µs since the UNIX epoch. If not specified, the credential remains valid forever."), + SD_VARLINK_DEFINE_INPUT(notAfter, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The intended scope for the credential. One of 'system' or 'user'. If not specified defaults to 'system', unless an uid is specified (see below), in which case it default to 'user'."), + SD_VARLINK_DEFINE_INPUT(scope, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The numeric UNIX UID of the user the credential shall be scoped to. Only relevant if 'user' scope is selected (see above). If not specified and 'user' scope is selected defaults to the UID of the calling user, if that can be determined."), + SD_VARLINK_DEFINE_INPUT(uid, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Controls whether interactive authentication (via polkit) shall be allowed. If unspecified defaults to false."), + SD_VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Encrypted credential in Base64 encoding. This can be stored in a credential file, for consumption in LoadEncryptedCredential= and similar calls. Note that the Base64 encoding should be retained when copied into a file."), + SD_VARLINK_DEFINE_OUTPUT(blob, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Decrypt, - VARLINK_FIELD_COMMENT("The name of the encrypted credential. Must the same string specified when the credential was encrypted, in order to authenticate this. If not specified authentication of the credential name is not done."), - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The encrypted credential in Base64 encoding. This corresponds of the 'blob' field returned by the 'Encrypt' method."), - VARLINK_DEFINE_INPUT(blob, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("The timestamp to use when validating the credential's time validity range. If not specified the current time is used."), - VARLINK_DEFINE_INPUT(timestamp, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The scope for this credential. If not specified no restrictions on the credential scope are made."), - VARLINK_DEFINE_INPUT(scope, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("If the 'user' scope is selected, specifies the numeric UNIX UID of the user the credential is associated with. If not specified this is automatically derived from the UID of the calling user, if that can be determined."), - VARLINK_DEFINE_INPUT(uid, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Controls whether interactive authentication (via polkit) shall be allowed. If unspecified defaults to false."), - VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The decrypted plaintext data in Base64 encoding."), - VARLINK_DEFINE_OUTPUT(data, VARLINK_STRING, 0)); + SD_VARLINK_FIELD_COMMENT("The name of the encrypted credential. Must the same string specified when the credential was encrypted, in order to authenticate this. If not specified authentication of the credential name is not done."), + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The encrypted credential in Base64 encoding. This corresponds of the 'blob' field returned by the 'Encrypt' method."), + SD_VARLINK_DEFINE_INPUT(blob, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("The timestamp to use when validating the credential's time validity range. If not specified the current time is used."), + SD_VARLINK_DEFINE_INPUT(timestamp, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The scope for this credential. If not specified no restrictions on the credential scope are made."), + SD_VARLINK_DEFINE_INPUT(scope, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("If the 'user' scope is selected, specifies the numeric UNIX UID of the user the credential is associated with. If not specified this is automatically derived from the UID of the calling user, if that can be determined."), + SD_VARLINK_DEFINE_INPUT(uid, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Controls whether interactive authentication (via polkit) shall be allowed. If unspecified defaults to false."), + SD_VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The decrypted plaintext data in Base64 encoding."), + SD_VARLINK_DEFINE_OUTPUT(data, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_ERROR(BadFormat); -static VARLINK_DEFINE_ERROR(NameMismatch); -static VARLINK_DEFINE_ERROR(TimeMismatch); -static VARLINK_DEFINE_ERROR(NoSuchUser); -static VARLINK_DEFINE_ERROR(BadScope); +static SD_VARLINK_DEFINE_ERROR(BadFormat); +static SD_VARLINK_DEFINE_ERROR(NameMismatch); +static SD_VARLINK_DEFINE_ERROR(TimeMismatch); +static SD_VARLINK_DEFINE_ERROR(NoSuchUser); +static SD_VARLINK_DEFINE_ERROR(BadScope); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Credentials, "io.systemd.Credentials", - VARLINK_INTERFACE_COMMENT("APIs for encrypting and decrypting service credentials."), - VARLINK_SYMBOL_COMMENT("Encrypts some plaintext data, returns an encrypted credential."), + SD_VARLINK_INTERFACE_COMMENT("APIs for encrypting and decrypting service credentials."), + SD_VARLINK_SYMBOL_COMMENT("Encrypts some plaintext data, returns an encrypted credential."), &vl_method_Encrypt, - VARLINK_SYMBOL_COMMENT("Decrypts an encrypted credential, returns plaintext data."), + SD_VARLINK_SYMBOL_COMMENT("Decrypts an encrypted credential, returns plaintext data."), &vl_method_Decrypt, - VARLINK_SYMBOL_COMMENT("Indicates that a corrupt and unsupported encrypted credential was provided."), + SD_VARLINK_SYMBOL_COMMENT("Indicates that a corrupt and unsupported encrypted credential was provided."), &vl_error_BadFormat, - VARLINK_SYMBOL_COMMENT("The specified name does not match the name stored in the credential."), + SD_VARLINK_SYMBOL_COMMENT("The specified name does not match the name stored in the credential."), &vl_error_NameMismatch, - VARLINK_SYMBOL_COMMENT("The credential's is no longer or not yet valid."), + SD_VARLINK_SYMBOL_COMMENT("The credential's is no longer or not yet valid."), &vl_error_TimeMismatch, - VARLINK_SYMBOL_COMMENT("The specified user does not exist."), + SD_VARLINK_SYMBOL_COMMENT("The specified user does not exist."), &vl_error_NoSuchUser, - VARLINK_SYMBOL_COMMENT("The credential does not match the selected scope."), + SD_VARLINK_SYMBOL_COMMENT("The credential does not match the selected scope."), &vl_error_BadScope); diff --git a/src/shared/varlink-io.systemd.Credentials.h b/src/shared/varlink-io.systemd.Credentials.h index c0ecc3d840..4f1842e238 100644 --- a/src/shared/varlink-io.systemd.Credentials.h +++ b/src/shared/varlink-io.systemd.Credentials.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Credentials; +extern const sd_varlink_interface vl_interface_io_systemd_Credentials; diff --git a/src/shared/varlink-io.systemd.Hostname.c b/src/shared/varlink-io.systemd.Hostname.c index 247bca6da3..a41d7cb85f 100644 --- a/src/shared/varlink-io.systemd.Hostname.c +++ b/src/shared/varlink-io.systemd.Hostname.c @@ -2,39 +2,39 @@ #include "varlink-io.systemd.Credentials.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Describe, - VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(Hostname, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(StaticHostname, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(PrettyHostname, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(DefaultHostname, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(HostnameSource, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(IconName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(Chassis, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(Deployment, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(Location, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(KernelName, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(KernelRelease, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(KernelVersion, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(OperatingSystemPrettyName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(OperatingSystemCPEName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(OperatingSystemHomeURL, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(OperatingSystemSupportEnd, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(OperatingSystemReleaseData, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(MachineInformationData, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(HardwareVendor, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(HardwareModel, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(HardwareSerial, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(FirmwareVersion, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(FirmwareVendor, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(FirmwareDate, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(MachineID, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(BootID, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(ProductUUID, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(VSockCID, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(Hostname, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(StaticHostname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(PrettyHostname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(DefaultHostname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(HostnameSource, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(IconName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(Chassis, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(Deployment, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(Location, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(KernelName, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(KernelRelease, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(KernelVersion, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(OperatingSystemPrettyName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(OperatingSystemCPEName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(OperatingSystemHomeURL, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(OperatingSystemSupportEnd, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(OperatingSystemReleaseData, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(MachineInformationData, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(HardwareVendor, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(HardwareModel, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(HardwareSerial, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(FirmwareVersion, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(FirmwareVendor, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(FirmwareDate, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(MachineID, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(BootID, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(ProductUUID, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(VSockCID, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Hostname, "io.systemd.Hostname", &vl_method_Describe); diff --git a/src/shared/varlink-io.systemd.Hostname.h b/src/shared/varlink-io.systemd.Hostname.h index 29bb20ef68..e390a7d0c0 100644 --- a/src/shared/varlink-io.systemd.Hostname.h +++ b/src/shared/varlink-io.systemd.Hostname.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Hostname; +extern const sd_varlink_interface vl_interface_io_systemd_Hostname; diff --git a/src/shared/varlink-io.systemd.Import.c b/src/shared/varlink-io.systemd.Import.c index 4b2f3dcdea..622d571c20 100644 --- a/src/shared/varlink-io.systemd.Import.c +++ b/src/shared/varlink-io.systemd.Import.c @@ -2,128 +2,128 @@ #include "varlink-io.systemd.Import.h" -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( ImageClass, - VARLINK_FIELD_COMMENT("An image to boot as a system on baremetal, in a VM or as a container"), - VARLINK_DEFINE_ENUM_VALUE(machine), - VARLINK_FIELD_COMMENT("An portable service image"), - VARLINK_DEFINE_ENUM_VALUE(portable), - VARLINK_FIELD_COMMENT("A system extension image"), - VARLINK_DEFINE_ENUM_VALUE(sysext), - VARLINK_FIELD_COMMENT("A configuration extension image"), - VARLINK_DEFINE_ENUM_VALUE(confext)); + SD_VARLINK_FIELD_COMMENT("An image to boot as a system on baremetal, in a VM or as a container"), + SD_VARLINK_DEFINE_ENUM_VALUE(machine), + SD_VARLINK_FIELD_COMMENT("An portable service image"), + SD_VARLINK_DEFINE_ENUM_VALUE(portable), + SD_VARLINK_FIELD_COMMENT("A system extension image"), + SD_VARLINK_DEFINE_ENUM_VALUE(sysext), + SD_VARLINK_FIELD_COMMENT("A configuration extension image"), + SD_VARLINK_DEFINE_ENUM_VALUE(confext)); -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( RemoteType, - VARLINK_FIELD_COMMENT("Raw binary disk images, typically in a GPT envelope"), - VARLINK_DEFINE_ENUM_VALUE(raw), - VARLINK_FIELD_COMMENT("A tarball, optionally compressed"), - VARLINK_DEFINE_ENUM_VALUE(tar)); + SD_VARLINK_FIELD_COMMENT("Raw binary disk images, typically in a GPT envelope"), + SD_VARLINK_DEFINE_ENUM_VALUE(raw), + SD_VARLINK_FIELD_COMMENT("A tarball, optionally compressed"), + SD_VARLINK_DEFINE_ENUM_VALUE(tar)); -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( TransferType, - VARLINK_FIELD_COMMENT("A local import of a tarball"), - VARLINK_DEFINE_ENUM_VALUE(import_tar), - VARLINK_FIELD_COMMENT("A local import of a raw disk image"), - VARLINK_DEFINE_ENUM_VALUE(import_raw), - VARLINK_FIELD_COMMENT("A local import of a file system tree"), - VARLINK_DEFINE_ENUM_VALUE(import_fs), - VARLINK_FIELD_COMMENT("A local export of a tarball"), - VARLINK_DEFINE_ENUM_VALUE(export_tar), - VARLINK_FIELD_COMMENT("A local export of a raw disk image"), - VARLINK_DEFINE_ENUM_VALUE(export_raw), - VARLINK_FIELD_COMMENT("A download of a tarball"), - VARLINK_DEFINE_ENUM_VALUE(pull_tar), - VARLINK_FIELD_COMMENT("A download of a raw disk image"), - VARLINK_DEFINE_ENUM_VALUE(pull_raw)); + SD_VARLINK_FIELD_COMMENT("A local import of a tarball"), + SD_VARLINK_DEFINE_ENUM_VALUE(import_tar), + SD_VARLINK_FIELD_COMMENT("A local import of a raw disk image"), + SD_VARLINK_DEFINE_ENUM_VALUE(import_raw), + SD_VARLINK_FIELD_COMMENT("A local import of a file system tree"), + SD_VARLINK_DEFINE_ENUM_VALUE(import_fs), + SD_VARLINK_FIELD_COMMENT("A local export of a tarball"), + SD_VARLINK_DEFINE_ENUM_VALUE(export_tar), + SD_VARLINK_FIELD_COMMENT("A local export of a raw disk image"), + SD_VARLINK_DEFINE_ENUM_VALUE(export_raw), + SD_VARLINK_FIELD_COMMENT("A download of a tarball"), + SD_VARLINK_DEFINE_ENUM_VALUE(pull_tar), + SD_VARLINK_FIELD_COMMENT("A download of a raw disk image"), + SD_VARLINK_DEFINE_ENUM_VALUE(pull_raw)); -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( ImageVerify, - VARLINK_FIELD_COMMENT("No verification"), - VARLINK_DEFINE_ENUM_VALUE(no), - VARLINK_FIELD_COMMENT("Verify that downloads match checksum file (SHA256SUMS), but do not check signature of checksum file"), - VARLINK_DEFINE_ENUM_VALUE(checksum), - VARLINK_FIELD_COMMENT("Verify that downloads match checksum file (SHA256SUMS), and check signature of checksum file."), - VARLINK_DEFINE_ENUM_VALUE(signature)); + SD_VARLINK_FIELD_COMMENT("No verification"), + SD_VARLINK_DEFINE_ENUM_VALUE(no), + SD_VARLINK_FIELD_COMMENT("Verify that downloads match checksum file (SHA256SUMS), but do not check signature of checksum file"), + SD_VARLINK_DEFINE_ENUM_VALUE(checksum), + SD_VARLINK_FIELD_COMMENT("Verify that downloads match checksum file (SHA256SUMS), and check signature of checksum file."), + SD_VARLINK_DEFINE_ENUM_VALUE(signature)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( LogMessage, - VARLINK_FIELD_COMMENT("The log message"), - VARLINK_DEFINE_FIELD(message, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("The priority of the log message, using the BSD syslog priority levels"), - VARLINK_DEFINE_FIELD(priority, VARLINK_INT, 0)); + SD_VARLINK_FIELD_COMMENT("The log message"), + SD_VARLINK_DEFINE_FIELD(message, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("The priority of the log message, using the BSD syslog priority levels"), + SD_VARLINK_DEFINE_FIELD(priority, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ListTransfers, - VARLINK_FIELD_COMMENT("Image class to filter by"), - VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("A unique numeric identifier for the ongoing transfer"), - VARLINK_DEFINE_OUTPUT(id, VARLINK_INT, 0), - VARLINK_FIELD_COMMENT("The type of transfer"), - VARLINK_DEFINE_OUTPUT_BY_TYPE(type, TransferType, 0), - VARLINK_FIELD_COMMENT("The remote URL"), - VARLINK_DEFINE_OUTPUT(remote, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("The local image name"), - VARLINK_DEFINE_OUTPUT(local, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("The class of the image"), - VARLINK_DEFINE_OUTPUT_BY_TYPE(class, ImageClass, 0), - VARLINK_FIELD_COMMENT("Progress in percent"), - VARLINK_DEFINE_OUTPUT(percent, VARLINK_FLOAT, 0)); + SD_VARLINK_FIELD_COMMENT("Image class to filter by"), + SD_VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("A unique numeric identifier for the ongoing transfer"), + SD_VARLINK_DEFINE_OUTPUT(id, SD_VARLINK_INT, 0), + SD_VARLINK_FIELD_COMMENT("The type of transfer"), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(type, TransferType, 0), + SD_VARLINK_FIELD_COMMENT("The remote URL"), + SD_VARLINK_DEFINE_OUTPUT(remote, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("The local image name"), + SD_VARLINK_DEFINE_OUTPUT(local, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("The class of the image"), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(class, ImageClass, 0), + SD_VARLINK_FIELD_COMMENT("Progress in percent"), + SD_VARLINK_DEFINE_OUTPUT(percent, SD_VARLINK_FLOAT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Pull, - VARLINK_FIELD_COMMENT("The remote URL to download from"), - VARLINK_DEFINE_INPUT(remote, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("The local image name to download to"), - VARLINK_DEFINE_INPUT(local, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The type of the resource"), - VARLINK_DEFINE_INPUT_BY_TYPE(type, RemoteType, 0), - VARLINK_FIELD_COMMENT("The image class"), - VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, 0), - VARLINK_FIELD_COMMENT("The whether and how thoroughly to verify the download before installing it locally. Defauts to 'signature'."), - VARLINK_DEFINE_INPUT_BY_TYPE(verify, ImageVerify, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("If true, an existing image by the local name is deleted. Defaults to false."), - VARLINK_DEFINE_INPUT(force, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Whether to make the image read-only after downloading. Defaults ot false."), - VARLINK_DEFINE_INPUT(readOnly, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Whether to keep a pristine copy of the download separate from the locally installed image. Defaults to false."), - VARLINK_DEFINE_INPUT(keepDownload, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Whether to permit interactive authentication. Defaults to false."), - VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("A progress update, as percent value"), - VARLINK_DEFINE_OUTPUT(progress, VARLINK_FLOAT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("A log message about the ongoing transfer"), - VARLINK_DEFINE_OUTPUT_BY_TYPE(log, LogMessage, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The numeric ID of this download"), - VARLINK_DEFINE_OUTPUT(id, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_FIELD_COMMENT("The remote URL to download from"), + SD_VARLINK_DEFINE_INPUT(remote, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("The local image name to download to"), + SD_VARLINK_DEFINE_INPUT(local, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The type of the resource"), + SD_VARLINK_DEFINE_INPUT_BY_TYPE(type, RemoteType, 0), + SD_VARLINK_FIELD_COMMENT("The image class"), + SD_VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, 0), + SD_VARLINK_FIELD_COMMENT("The whether and how thoroughly to verify the download before installing it locally. Defauts to 'signature'."), + SD_VARLINK_DEFINE_INPUT_BY_TYPE(verify, ImageVerify, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("If true, an existing image by the local name is deleted. Defaults to false."), + SD_VARLINK_DEFINE_INPUT(force, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Whether to make the image read-only after downloading. Defaults ot false."), + SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Whether to keep a pristine copy of the download separate from the locally installed image. Defaults to false."), + SD_VARLINK_DEFINE_INPUT(keepDownload, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Whether to permit interactive authentication. Defaults to false."), + SD_VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("A progress update, as percent value"), + SD_VARLINK_DEFINE_OUTPUT(progress, SD_VARLINK_FLOAT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("A log message about the ongoing transfer"), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(log, LogMessage, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The numeric ID of this download"), + SD_VARLINK_DEFINE_OUTPUT(id, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_ERROR(AlreadyInProgress); -static VARLINK_DEFINE_ERROR(TransferCancelled); -static VARLINK_DEFINE_ERROR(TransferFailed); -static VARLINK_DEFINE_ERROR(NoTransfers); +static SD_VARLINK_DEFINE_ERROR(AlreadyInProgress); +static SD_VARLINK_DEFINE_ERROR(TransferCancelled); +static SD_VARLINK_DEFINE_ERROR(TransferFailed); +static SD_VARLINK_DEFINE_ERROR(NoTransfers); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Import, "io.systemd.Import", - VARLINK_SYMBOL_COMMENT("Describes the class of images"), + SD_VARLINK_SYMBOL_COMMENT("Describes the class of images"), &vl_type_ImageClass, - VARLINK_SYMBOL_COMMENT("Describes the type of a images to transfer"), + SD_VARLINK_SYMBOL_COMMENT("Describes the type of a images to transfer"), &vl_type_RemoteType, - VARLINK_SYMBOL_COMMENT("Describes the type of a transfer"), + SD_VARLINK_SYMBOL_COMMENT("Describes the type of a transfer"), &vl_type_TransferType, - VARLINK_SYMBOL_COMMENT("Describes whether and how thoroughly to verify the download before installing it locally"), + SD_VARLINK_SYMBOL_COMMENT("Describes whether and how thoroughly to verify the download before installing it locally"), &vl_type_ImageVerify, - VARLINK_SYMBOL_COMMENT("Structure for log messages associated with a transfer operation"), + SD_VARLINK_SYMBOL_COMMENT("Structure for log messages associated with a transfer operation"), &vl_type_LogMessage, - VARLINK_SYMBOL_COMMENT("List ongoing transfers, or query details about specific transfers"), + SD_VARLINK_SYMBOL_COMMENT("List ongoing transfers, or query details about specific transfers"), &vl_method_ListTransfers, - VARLINK_SYMBOL_COMMENT("Download a .tar or .raw file. This must be called with the 'more' flag enabled. It will immediately return the numeric ID of the transfer, and then follow up with progress and log message updates, until the transfer is complete."), + SD_VARLINK_SYMBOL_COMMENT("Download a .tar or .raw file. This must be called with the 'more' flag enabled. It will immediately return the numeric ID of the transfer, and then follow up with progress and log message updates, until the transfer is complete."), &vl_method_Pull, - VARLINK_SYMBOL_COMMENT("A transfer for the specified file is already ongoing"), + SD_VARLINK_SYMBOL_COMMENT("A transfer for the specified file is already ongoing"), &vl_error_AlreadyInProgress, - VARLINK_SYMBOL_COMMENT("The transfer has been cancelled on user request"), + SD_VARLINK_SYMBOL_COMMENT("The transfer has been cancelled on user request"), &vl_error_TransferCancelled, - VARLINK_SYMBOL_COMMENT("The transfer failed"), + SD_VARLINK_SYMBOL_COMMENT("The transfer failed"), &vl_error_TransferFailed, - VARLINK_SYMBOL_COMMENT("No currently ongoing transfer"), + SD_VARLINK_SYMBOL_COMMENT("No currently ongoing transfer"), &vl_error_NoTransfers); diff --git a/src/shared/varlink-io.systemd.Import.h b/src/shared/varlink-io.systemd.Import.h index 6579c29b39..22e85492fa 100644 --- a/src/shared/varlink-io.systemd.Import.h +++ b/src/shared/varlink-io.systemd.Import.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Import; +extern const sd_varlink_interface vl_interface_io_systemd_Import; diff --git a/src/shared/varlink-io.systemd.Journal.c b/src/shared/varlink-io.systemd.Journal.c index b93fb72aca..66514a9d57 100644 --- a/src/shared/varlink-io.systemd.Journal.c +++ b/src/shared/varlink-io.systemd.Journal.c @@ -2,14 +2,14 @@ #include "varlink-io.systemd.Journal.h" -static VARLINK_DEFINE_METHOD(Synchronize); -static VARLINK_DEFINE_METHOD(Rotate); -static VARLINK_DEFINE_METHOD(FlushToVar); -static VARLINK_DEFINE_METHOD(RelinquishVar); +static SD_VARLINK_DEFINE_METHOD(Synchronize); +static SD_VARLINK_DEFINE_METHOD(Rotate); +static SD_VARLINK_DEFINE_METHOD(FlushToVar); +static SD_VARLINK_DEFINE_METHOD(RelinquishVar); -static VARLINK_DEFINE_ERROR(NotSupportedByNamespaces); +static SD_VARLINK_DEFINE_ERROR(NotSupportedByNamespaces); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Journal, "io.systemd.Journal", &vl_method_Synchronize, diff --git a/src/shared/varlink-io.systemd.Journal.h b/src/shared/varlink-io.systemd.Journal.h index 0bc94a775c..a6a6050c44 100644 --- a/src/shared/varlink-io.systemd.Journal.h +++ b/src/shared/varlink-io.systemd.Journal.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Journal; +extern const sd_varlink_interface vl_interface_io_systemd_Journal; diff --git a/src/shared/varlink-io.systemd.Machine.c b/src/shared/varlink-io.systemd.Machine.c index 4d93527273..1c8f39e3c7 100644 --- a/src/shared/varlink-io.systemd.Machine.c +++ b/src/shared/varlink-io.systemd.Machine.c @@ -1,68 +1,69 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "varlink-idl.h" +#include "sd-varlink-idl.h" + #include "varlink-io.systemd.Machine.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Register, - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(id, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(service, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(class, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(leader, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(rootDirectory, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(ifIndices, VARLINK_INT, VARLINK_ARRAY|VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(vSockCid, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(sshAddress, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(sshPrivateKeyPath, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Controls whether to allocate a scope unit for the machine to register. If false, the client already took care of that and registered a service/scope specific to the machine."), - VARLINK_DEFINE_INPUT(allocateUnit, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Whether to allow interactive authentication on this operation."), - VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(id, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(service, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(class, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(leader, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(rootDirectory, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(ifIndices, SD_VARLINK_INT, SD_VARLINK_ARRAY|SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(vSockCid, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(sshAddress, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(sshPrivateKeyPath, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Controls whether to allocate a scope unit for the machine to register. If false, the client already took care of that and registered a service/scope specific to the machine."), + SD_VARLINK_DEFINE_INPUT(allocateUnit, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Whether to allow interactive authentication on this operation."), + SD_VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( Timestamp, - VARLINK_FIELD_COMMENT("Timestamp in µs in the CLOCK_REALTIME clock (wallclock)"), - VARLINK_DEFINE_FIELD(realtime, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Timestamp in µs in the CLOCK_MONOTONIC clock"), - VARLINK_DEFINE_FIELD(monotonic, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_FIELD_COMMENT("Timestamp in µs in the CLOCK_REALTIME clock (wallclock)"), + SD_VARLINK_DEFINE_FIELD(realtime, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Timestamp in µs in the CLOCK_MONOTONIC clock"), + SD_VARLINK_DEFINE_FIELD(monotonic, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( List, - VARLINK_FIELD_COMMENT("If non-null the name of a running machine to report details on. If null/unspecified enumerates all running machines."), - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Name of the machine"), - VARLINK_DEFINE_OUTPUT(name, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("128bit ID identifying this machine, formatted in hexadecimal"), - VARLINK_DEFINE_OUTPUT(id, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Name of the software that registered this machine"), - VARLINK_DEFINE_OUTPUT(service, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The class of this machine"), - VARLINK_DEFINE_OUTPUT(class, VARLINK_STRING, 0), - VARLINK_FIELD_COMMENT("Leader process PID of this machine"), - VARLINK_DEFINE_OUTPUT(leader, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Root directory of this machine, if known, relative to host file system"), - VARLINK_DEFINE_OUTPUT(rootDirectory, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("The service manager unit this machine resides in"), - VARLINK_DEFINE_OUTPUT(unit, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("Timestamp when the machine was activated"), - VARLINK_DEFINE_OUTPUT_BY_TYPE(timestamp, Timestamp, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("AF_VSOCK CID of the machine if known and applicable"), - VARLINK_DEFINE_OUTPUT(vSockCid, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_FIELD_COMMENT("SSH address to connect to"), - VARLINK_DEFINE_OUTPUT(sshAddress, VARLINK_STRING, VARLINK_NULLABLE)); + SD_VARLINK_FIELD_COMMENT("If non-null the name of a running machine to report details on. If null/unspecified enumerates all running machines."), + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Name of the machine"), + SD_VARLINK_DEFINE_OUTPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("128bit ID identifying this machine, formatted in hexadecimal"), + SD_VARLINK_DEFINE_OUTPUT(id, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Name of the software that registered this machine"), + SD_VARLINK_DEFINE_OUTPUT(service, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The class of this machine"), + SD_VARLINK_DEFINE_OUTPUT(class, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("Leader process PID of this machine"), + SD_VARLINK_DEFINE_OUTPUT(leader, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Root directory of this machine, if known, relative to host file system"), + SD_VARLINK_DEFINE_OUTPUT(rootDirectory, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("The service manager unit this machine resides in"), + SD_VARLINK_DEFINE_OUTPUT(unit, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("Timestamp when the machine was activated"), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(timestamp, Timestamp, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("AF_VSOCK CID of the machine if known and applicable"), + SD_VARLINK_DEFINE_OUTPUT(vSockCid, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("SSH address to connect to"), + SD_VARLINK_DEFINE_OUTPUT(sshAddress, SD_VARLINK_STRING, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_ERROR(NoSuchMachine); -static VARLINK_DEFINE_ERROR(MachineExists); +static SD_VARLINK_DEFINE_ERROR(NoSuchMachine); +static SD_VARLINK_DEFINE_ERROR(MachineExists); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Machine, "io.systemd.Machine", - VARLINK_SYMBOL_COMMENT("A timestamp object consisting of both CLOCK_REALTIME and CLOCK_MONOTONIC timestamps"), + SD_VARLINK_SYMBOL_COMMENT("A timestamp object consisting of both CLOCK_REALTIME and CLOCK_MONOTONIC timestamps"), &vl_type_Timestamp, &vl_method_Register, - VARLINK_SYMBOL_COMMENT("List running machines"), + SD_VARLINK_SYMBOL_COMMENT("List running machines"), &vl_method_List, - VARLINK_SYMBOL_COMMENT("No matching machine currently running"), + SD_VARLINK_SYMBOL_COMMENT("No matching machine currently running"), &vl_error_NoSuchMachine, &vl_error_MachineExists); diff --git a/src/shared/varlink-io.systemd.Machine.h b/src/shared/varlink-io.systemd.Machine.h index c9fc85f150..605a314526 100644 --- a/src/shared/varlink-io.systemd.Machine.h +++ b/src/shared/varlink-io.systemd.Machine.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Machine; +extern const sd_varlink_interface vl_interface_io_systemd_Machine; diff --git a/src/shared/varlink-io.systemd.ManagedOOM.c b/src/shared/varlink-io.systemd.ManagedOOM.c index d6414b3718..8fc329b707 100644 --- a/src/shared/varlink-io.systemd.ManagedOOM.c +++ b/src/shared/varlink-io.systemd.ManagedOOM.c @@ -9,13 +9,13 @@ * * Compare with io.systemd.oom where the client/server roles of oomd and the service manager are swapped! */ -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( SubscribeManagedOOMCGroups, - VARLINK_DEFINE_OUTPUT_BY_TYPE(cgroups, ControlGroup, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(cgroups, ControlGroup, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_ERROR(SubscriptionTaken); +static SD_VARLINK_DEFINE_ERROR(SubscriptionTaken); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_ManagedOOM, "io.systemd.ManagedOOM", &vl_method_SubscribeManagedOOMCGroups, diff --git a/src/shared/varlink-io.systemd.ManagedOOM.h b/src/shared/varlink-io.systemd.ManagedOOM.h index 2c8bf54c4e..ee095ee60d 100644 --- a/src/shared/varlink-io.systemd.ManagedOOM.h +++ b/src/shared/varlink-io.systemd.ManagedOOM.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_ManagedOOM; +extern const sd_varlink_interface vl_interface_io_systemd_ManagedOOM; diff --git a/src/shared/varlink-io.systemd.MountFileSystem.c b/src/shared/varlink-io.systemd.MountFileSystem.c index 4a33578a10..e735d9e2fc 100644 --- a/src/shared/varlink-io.systemd.MountFileSystem.c +++ b/src/shared/varlink-io.systemd.MountFileSystem.c @@ -2,60 +2,60 @@ #include "varlink-io.systemd.MountFileSystem.h" -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( PartitionDesignator, - VARLINK_DEFINE_ENUM_VALUE(root), - VARLINK_DEFINE_ENUM_VALUE(usr), - VARLINK_DEFINE_ENUM_VALUE(home), - VARLINK_DEFINE_ENUM_VALUE(srv), - VARLINK_DEFINE_ENUM_VALUE(esp), - VARLINK_DEFINE_ENUM_VALUE(xbootldr), - VARLINK_DEFINE_ENUM_VALUE(swap), - VARLINK_DEFINE_ENUM_VALUE(root_verity), - VARLINK_DEFINE_ENUM_VALUE(usr_verity), - VARLINK_DEFINE_ENUM_VALUE(root_verity_sig), - VARLINK_DEFINE_ENUM_VALUE(usr_verity_sig), - VARLINK_DEFINE_ENUM_VALUE(tmp), - VARLINK_DEFINE_ENUM_VALUE(var)); + SD_VARLINK_DEFINE_ENUM_VALUE(root), + SD_VARLINK_DEFINE_ENUM_VALUE(usr), + SD_VARLINK_DEFINE_ENUM_VALUE(home), + SD_VARLINK_DEFINE_ENUM_VALUE(srv), + SD_VARLINK_DEFINE_ENUM_VALUE(esp), + SD_VARLINK_DEFINE_ENUM_VALUE(xbootldr), + SD_VARLINK_DEFINE_ENUM_VALUE(swap), + SD_VARLINK_DEFINE_ENUM_VALUE(root_verity), + SD_VARLINK_DEFINE_ENUM_VALUE(usr_verity), + SD_VARLINK_DEFINE_ENUM_VALUE(root_verity_sig), + SD_VARLINK_DEFINE_ENUM_VALUE(usr_verity_sig), + SD_VARLINK_DEFINE_ENUM_VALUE(tmp), + SD_VARLINK_DEFINE_ENUM_VALUE(var)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( PartitionInfo, - VARLINK_DEFINE_FIELD(designator, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(writable, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(growFileSystem, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(partitionNumber, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(architecture, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(partitionUuid, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(fileSystemType, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(partitionLabel, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(size, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(offset, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(mountFileDescriptor, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_FIELD(designator, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(writable, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(growFileSystem, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(partitionNumber, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(architecture, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(partitionUuid, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(fileSystemType, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(partitionLabel, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(size, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(offset, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(mountFileDescriptor, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( MountImage, - VARLINK_DEFINE_INPUT(imageFileDescriptor, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(readOnly, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(growFileSystems, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(password, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(imagePolicy, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(partitions, PartitionInfo, VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(imagePolicy, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(imageSize, VARLINK_INT, 0), - VARLINK_DEFINE_OUTPUT(sectorSize, VARLINK_INT, 0), - VARLINK_DEFINE_OUTPUT(imageName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(imageUuid, VARLINK_STRING, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(imageFileDescriptor, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(growFileSystems, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(password, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(imagePolicy, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(partitions, PartitionInfo, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(imagePolicy, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(imageSize, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_OUTPUT(sectorSize, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_OUTPUT(imageName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(imageUuid, SD_VARLINK_STRING, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_ERROR(IncompatibleImage); -static VARLINK_DEFINE_ERROR(MultipleRootPartitionsFound); -static VARLINK_DEFINE_ERROR(RootPartitionNotFound); -static VARLINK_DEFINE_ERROR(DeniedByImagePolicy); -static VARLINK_DEFINE_ERROR(KeyNotFound); -static VARLINK_DEFINE_ERROR(VerityFailure); +static SD_VARLINK_DEFINE_ERROR(IncompatibleImage); +static SD_VARLINK_DEFINE_ERROR(MultipleRootPartitionsFound); +static SD_VARLINK_DEFINE_ERROR(RootPartitionNotFound); +static SD_VARLINK_DEFINE_ERROR(DeniedByImagePolicy); +static SD_VARLINK_DEFINE_ERROR(KeyNotFound); +static SD_VARLINK_DEFINE_ERROR(VerityFailure); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_MountFileSystem, "io.systemd.MountFileSystem", &vl_type_PartitionDesignator, diff --git a/src/shared/varlink-io.systemd.MountFileSystem.h b/src/shared/varlink-io.systemd.MountFileSystem.h index dc75957df4..0e6ad51e64 100644 --- a/src/shared/varlink-io.systemd.MountFileSystem.h +++ b/src/shared/varlink-io.systemd.MountFileSystem.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_MountFileSystem; +extern const sd_varlink_interface vl_interface_io_systemd_MountFileSystem; diff --git a/src/shared/varlink-io.systemd.NamespaceResource.c b/src/shared/varlink-io.systemd.NamespaceResource.c index e98c6c6663..83419acba4 100644 --- a/src/shared/varlink-io.systemd.NamespaceResource.c +++ b/src/shared/varlink-io.systemd.NamespaceResource.c @@ -2,48 +2,48 @@ #include "varlink-io.systemd.NamespaceResource.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( AllocateUserRange, - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(size, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(target, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(size, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(target, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( RegisterUserNamespace, - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( AddMountToUserNamespace, - VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(mountFileDescriptor, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(mountFileDescriptor, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( AddControlGroupToUserNamespace, - VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(controlGroupFileDescriptor, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(controlGroupFileDescriptor, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( AddNetworkToUserNamespace, - VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(networkNamespaceFileDescriptor, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(namespaceInterfaceName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(mode, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(hostInterfaceName, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(namespaceInterfaceName, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_ERROR(UserNamespaceInterfaceNotSupported); -static VARLINK_DEFINE_ERROR(NameExists); -static VARLINK_DEFINE_ERROR(UserNamespaceExists); -static VARLINK_DEFINE_ERROR(DynamicRangeUnavailable); -static VARLINK_DEFINE_ERROR(NoDynamicRange); -static VARLINK_DEFINE_ERROR(UserNamespaceNotRegistered); -static VARLINK_DEFINE_ERROR(UserNamespaceWithoutUserRange); -static VARLINK_DEFINE_ERROR(TooManyControlGroups); -static VARLINK_DEFINE_ERROR(ControlGroupAlreadyAdded); - -VARLINK_DEFINE_INTERFACE( + SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(networkNamespaceFileDescriptor, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(namespaceInterfaceName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(mode, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(hostInterfaceName, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(namespaceInterfaceName, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_ERROR(UserNamespaceInterfaceNotSupported); +static SD_VARLINK_DEFINE_ERROR(NameExists); +static SD_VARLINK_DEFINE_ERROR(UserNamespaceExists); +static SD_VARLINK_DEFINE_ERROR(DynamicRangeUnavailable); +static SD_VARLINK_DEFINE_ERROR(NoDynamicRange); +static SD_VARLINK_DEFINE_ERROR(UserNamespaceNotRegistered); +static SD_VARLINK_DEFINE_ERROR(UserNamespaceWithoutUserRange); +static SD_VARLINK_DEFINE_ERROR(TooManyControlGroups); +static SD_VARLINK_DEFINE_ERROR(ControlGroupAlreadyAdded); + +SD_VARLINK_DEFINE_INTERFACE( io_systemd_NamespaceResource, "io.systemd.NamespaceResource", &vl_method_AllocateUserRange, diff --git a/src/shared/varlink-io.systemd.NamespaceResource.h b/src/shared/varlink-io.systemd.NamespaceResource.h index 443cb97e48..b8137d48fc 100644 --- a/src/shared/varlink-io.systemd.NamespaceResource.h +++ b/src/shared/varlink-io.systemd.NamespaceResource.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_NamespaceResource; +extern const sd_varlink_interface vl_interface_io_systemd_NamespaceResource; diff --git a/src/shared/varlink-io.systemd.Network.c b/src/shared/varlink-io.systemd.Network.c index 394cc33ace..fe0aecf1f1 100644 --- a/src/shared/varlink-io.systemd.Network.c +++ b/src/shared/varlink-io.systemd.Network.c @@ -2,51 +2,51 @@ #include "varlink-io.systemd.Network.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( GetStates, - VARLINK_DEFINE_OUTPUT(AddressState, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(IPv4AddressState, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(IPv6AddressState, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(CarrierState, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(OnlineState, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(OperationalState, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_METHOD( + SD_VARLINK_DEFINE_OUTPUT(AddressState, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(IPv4AddressState, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(IPv6AddressState, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(CarrierState, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(OnlineState, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(OperationalState, SD_VARLINK_STRING, 0)); + +static SD_VARLINK_DEFINE_METHOD( GetNamespaceId, - VARLINK_DEFINE_OUTPUT(NamespaceId, VARLINK_INT, 0), - VARLINK_DEFINE_OUTPUT(NamespaceNSID, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_OUTPUT(NamespaceId, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_OUTPUT(NamespaceNSID, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( LLDPNeighbor, - VARLINK_DEFINE_FIELD(ChassisID, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(RawChassisID, VARLINK_INT, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(PortID, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(RawPortID, VARLINK_INT, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(PortDescription, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(SystemName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(SystemDescription, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(EnabledCapabilities, VARLINK_INT, VARLINK_NULLABLE)); - -static VARLINK_DEFINE_STRUCT_TYPE( + SD_VARLINK_DEFINE_FIELD(ChassisID, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(RawChassisID, SD_VARLINK_INT, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(PortID, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(RawPortID, SD_VARLINK_INT, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(PortDescription, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(SystemName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(SystemDescription, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(EnabledCapabilities, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); + +static SD_VARLINK_DEFINE_STRUCT_TYPE( LLDPNeighborsByInterface, - VARLINK_DEFINE_FIELD(InterfaceIndex, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(InterfaceName, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(InterfaceAlternativeNames, VARLINK_STRING, VARLINK_ARRAY|VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD_BY_TYPE(Neighbors, LLDPNeighbor, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_FIELD(InterfaceIndex, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(InterfaceName, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(InterfaceAlternativeNames, SD_VARLINK_STRING, SD_VARLINK_ARRAY|SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(Neighbors, LLDPNeighbor, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( GetLLDPNeighbors, - VARLINK_DEFINE_INPUT(InterfaceIndex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(InterfaceName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(Neighbors, LLDPNeighborsByInterface, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_INPUT(InterfaceIndex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(InterfaceName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(Neighbors, LLDPNeighborsByInterface, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( SetPersistentStorage, - VARLINK_DEFINE_INPUT(Ready, VARLINK_BOOL, 0)); + SD_VARLINK_DEFINE_INPUT(Ready, SD_VARLINK_BOOL, 0)); -static VARLINK_DEFINE_ERROR(StorageReadOnly); +static SD_VARLINK_DEFINE_ERROR(StorageReadOnly); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Network, "io.systemd.Network", &vl_method_GetStates, diff --git a/src/shared/varlink-io.systemd.Network.h b/src/shared/varlink-io.systemd.Network.h index 12d532ab32..1d2871636f 100644 --- a/src/shared/varlink-io.systemd.Network.h +++ b/src/shared/varlink-io.systemd.Network.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Network; +extern const sd_varlink_interface vl_interface_io_systemd_Network; diff --git a/src/shared/varlink-io.systemd.PCRExtend.c b/src/shared/varlink-io.systemd.PCRExtend.c index 37d403f0ee..956a0eacca 100644 --- a/src/shared/varlink-io.systemd.PCRExtend.c +++ b/src/shared/varlink-io.systemd.PCRExtend.c @@ -2,13 +2,13 @@ #include "varlink-io.systemd.PCRExtend.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Extend, - VARLINK_DEFINE_INPUT(pcr, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(text, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(data, VARLINK_STRING, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(pcr, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(text, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(data, SD_VARLINK_STRING, SD_VARLINK_NULLABLE)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_PCRExtend, "io.systemd.PCRExtend", &vl_method_Extend); diff --git a/src/shared/varlink-io.systemd.PCRExtend.h b/src/shared/varlink-io.systemd.PCRExtend.h index ffc075af2c..212edd59dd 100644 --- a/src/shared/varlink-io.systemd.PCRExtend.h +++ b/src/shared/varlink-io.systemd.PCRExtend.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_PCRExtend; +extern const sd_varlink_interface vl_interface_io_systemd_PCRExtend; diff --git a/src/shared/varlink-io.systemd.PCRLock.c b/src/shared/varlink-io.systemd.PCRLock.c index 22c653228c..f385eb31c3 100644 --- a/src/shared/varlink-io.systemd.PCRLock.c +++ b/src/shared/varlink-io.systemd.PCRLock.c @@ -2,21 +2,21 @@ #include "varlink-io.systemd.PCRLock.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ReadEventLog, - VARLINK_DEFINE_OUTPUT(record, VARLINK_OBJECT, 0)); + SD_VARLINK_DEFINE_OUTPUT(record, SD_VARLINK_OBJECT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( MakePolicy, - VARLINK_DEFINE_INPUT(force, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(force, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( RemovePolicy); -static VARLINK_DEFINE_ERROR( +static SD_VARLINK_DEFINE_ERROR( NoChange); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_PCRLock, "io.systemd.PCRLock", &vl_method_ReadEventLog, diff --git a/src/shared/varlink-io.systemd.PCRLock.h b/src/shared/varlink-io.systemd.PCRLock.h index 687f09ef84..b323892c71 100644 --- a/src/shared/varlink-io.systemd.PCRLock.h +++ b/src/shared/varlink-io.systemd.PCRLock.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_PCRLock; +extern const sd_varlink_interface vl_interface_io_systemd_PCRLock; diff --git a/src/shared/varlink-io.systemd.Resolve.Monitor.c b/src/shared/varlink-io.systemd.Resolve.Monitor.c index ba928fa2cf..36681f5ea0 100644 --- a/src/shared/varlink-io.systemd.Resolve.Monitor.c +++ b/src/shared/varlink-io.systemd.Resolve.Monitor.c @@ -6,105 +6,105 @@ * hence import them here. */ #include "varlink-io.systemd.Resolve.h" -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ResourceRecordArray, - VARLINK_DEFINE_FIELD_BY_TYPE(rr, ResourceRecord, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(raw, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_FIELD_BY_TYPE(rr, ResourceRecord, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(raw, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( Answer, - VARLINK_DEFINE_FIELD_BY_TYPE(rr, ResourceRecord, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(raw, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(ifindex, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_FIELD_BY_TYPE(rr, ResourceRecord, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(raw, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( SubscribeQueryResults, /* First reply */ - VARLINK_DEFINE_OUTPUT(ready, VARLINK_BOOL, VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(ready, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), /* Subsequent replies */ - VARLINK_DEFINE_OUTPUT(state, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(result, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(rcode, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(errno, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(extendedDNSErrorCode, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(extendedDNSErrorMessage, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(question, ResourceKey, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT_BY_TYPE(collectedQuestions, ResourceKey, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT_BY_TYPE(answer, Answer, VARLINK_NULLABLE|VARLINK_ARRAY)); - -static VARLINK_DEFINE_STRUCT_TYPE( + SD_VARLINK_DEFINE_OUTPUT(state, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(result, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(rcode, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(errno, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(extendedDNSErrorCode, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(extendedDNSErrorMessage, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(question, ResourceKey, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(collectedQuestions, ResourceKey, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(answer, Answer, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY)); + +static SD_VARLINK_DEFINE_STRUCT_TYPE( CacheEntry, - VARLINK_DEFINE_FIELD_BY_TYPE(key, ResourceKey, 0), - VARLINK_DEFINE_FIELD_BY_TYPE(rrs, ResourceRecordArray, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(type, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(until, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_FIELD_BY_TYPE(key, ResourceKey, 0), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(rrs, ResourceRecordArray, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(type, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(until, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ScopeCache, - VARLINK_DEFINE_FIELD(protocol, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(family, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(ifname, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD_BY_TYPE(cache, CacheEntry, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_FIELD(protocol, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(family, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(ifname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(cache, CacheEntry, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( DumpCache, - VARLINK_DEFINE_OUTPUT_BY_TYPE(dump, ScopeCache, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(dump, ScopeCache, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ServerState, - VARLINK_DEFINE_FIELD(Server, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(Type, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(Interface, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(InterfaceIndex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(VerifiedFeatureLevel, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(PossibleFeatureLevel, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(DNSSECMode, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(DNSSECSupported, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(ReceivedUDPFragmentMax, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(FailedUDPAttempts, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(FailedTCPAttempts, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(PacketTruncated, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(PacketBadOpt, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(PacketRRSIGMissing, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(PacketInvalid, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(PacketDoOff, VARLINK_BOOL, 0)); - -static VARLINK_DEFINE_METHOD( + SD_VARLINK_DEFINE_FIELD(Server, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(Type, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(Interface, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(InterfaceIndex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(VerifiedFeatureLevel, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(PossibleFeatureLevel, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(DNSSECMode, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(DNSSECSupported, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(ReceivedUDPFragmentMax, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(FailedUDPAttempts, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(FailedTCPAttempts, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(PacketTruncated, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(PacketBadOpt, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(PacketRRSIGMissing, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(PacketInvalid, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(PacketDoOff, SD_VARLINK_BOOL, 0)); + +static SD_VARLINK_DEFINE_METHOD( DumpServerState, - VARLINK_DEFINE_OUTPUT_BY_TYPE(dump, ServerState, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(dump, ServerState, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( TransactionStatistics, - VARLINK_DEFINE_FIELD(currentTransactions, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(totalTransactions, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(totalTimeouts, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(totalTimeoutsServedStale, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(totalFailedResponses, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(totalFailedResponsesServedStale, VARLINK_INT, 0)); - -static VARLINK_DEFINE_STRUCT_TYPE( + SD_VARLINK_DEFINE_FIELD(currentTransactions, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(totalTransactions, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(totalTimeouts, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(totalTimeoutsServedStale, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(totalFailedResponses, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(totalFailedResponsesServedStale, SD_VARLINK_INT, 0)); + +static SD_VARLINK_DEFINE_STRUCT_TYPE( CacheStatistics, - VARLINK_DEFINE_FIELD(size, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(hits, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(misses, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_FIELD(size, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(hits, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(misses, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( DnssecStatistics, - VARLINK_DEFINE_FIELD(secure, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(insecure, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(bogus, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(indeterminate, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_FIELD(secure, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(insecure, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(bogus, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(indeterminate, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( DumpStatistics, - VARLINK_DEFINE_OUTPUT_BY_TYPE(transactions, TransactionStatistics, 0), - VARLINK_DEFINE_OUTPUT_BY_TYPE(cache, CacheStatistics, 0), - VARLINK_DEFINE_OUTPUT_BY_TYPE(dnssec, DnssecStatistics, 0)); + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(transactions, TransactionStatistics, 0), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(cache, CacheStatistics, 0), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(dnssec, DnssecStatistics, 0)); -static VARLINK_DEFINE_METHOD(ResetStatistics); +static SD_VARLINK_DEFINE_METHOD(ResetStatistics); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Resolve_Monitor, "io.systemd.Resolve.Monitor", &vl_method_SubscribeQueryResults, diff --git a/src/shared/varlink-io.systemd.Resolve.Monitor.h b/src/shared/varlink-io.systemd.Resolve.Monitor.h index a133ec30a5..e633ddfe52 100644 --- a/src/shared/varlink-io.systemd.Resolve.Monitor.h +++ b/src/shared/varlink-io.systemd.Resolve.Monitor.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_Resolve_Monitor; +extern const sd_varlink_interface vl_interface_io_systemd_Resolve_Monitor; diff --git a/src/shared/varlink-io.systemd.Resolve.c b/src/shared/varlink-io.systemd.Resolve.c index 71f4dc84c0..83c68321c4 100644 --- a/src/shared/varlink-io.systemd.Resolve.c +++ b/src/shared/varlink-io.systemd.Resolve.c @@ -2,175 +2,175 @@ #include "varlink-io.systemd.Resolve.h" -VARLINK_DEFINE_STRUCT_TYPE( +SD_VARLINK_DEFINE_STRUCT_TYPE( ResourceKey, - VARLINK_DEFINE_FIELD(class, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(type, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(name, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_FIELD(class, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(type, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(name, SD_VARLINK_STRING, 0)); -VARLINK_DEFINE_STRUCT_TYPE( +SD_VARLINK_DEFINE_STRUCT_TYPE( ResourceRecord, - VARLINK_DEFINE_FIELD_BY_TYPE(key, ResourceKey, 0), - VARLINK_DEFINE_FIELD(priority, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(weight, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(port, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(name, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(cpu, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(os, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(items, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(address, VARLINK_INT, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(mname, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(rname, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(serial, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(refresh, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(expire, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(minimum, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(exchange, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(version, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(size, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(horiz_pre, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(vert_pre, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(latitude, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(longitude, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(altitude, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(keyTag, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(algorithm, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(digestType, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(digest, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(fptype, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(fingerprint, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(flags, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(protocol, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(dnskey, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(signer, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(typeCovered, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(labels, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(originalTtl, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(expiration, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(inception, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(signature, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(nextDomain, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(types, VARLINK_INT, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(iterations, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(salt, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(hash, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(certUsage, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(selector, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(matchingType, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(data, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(tag, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(value, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(target, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(params, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(order, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(preference, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(naptrFlags, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(services, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(regexp, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(replacement, VARLINK_STRING, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_FIELD_BY_TYPE(key, ResourceKey, 0), + SD_VARLINK_DEFINE_FIELD(priority, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(weight, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(port, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(name, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(cpu, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(os, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(items, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(address, SD_VARLINK_INT, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(mname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(rname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(serial, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(refresh, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(expire, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(minimum, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(exchange, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(version, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(size, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(horiz_pre, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(vert_pre, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(latitude, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(longitude, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(altitude, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(keyTag, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(algorithm, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(digestType, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(digest, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(fptype, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(fingerprint, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(flags, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(protocol, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(dnskey, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(signer, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(typeCovered, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(labels, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(originalTtl, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(expiration, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(inception, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(signature, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(nextDomain, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(types, SD_VARLINK_INT, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(iterations, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(salt, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(hash, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(certUsage, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(selector, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(matchingType, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(data, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(tag, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(value, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(target, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(params, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(order, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(preference, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(naptrFlags, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(services, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(regexp, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(replacement, SD_VARLINK_STRING, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ResolvedAddress, - VARLINK_DEFINE_FIELD(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(family, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(address, VARLINK_INT, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_FIELD(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(family, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(address, SD_VARLINK_INT, SD_VARLINK_ARRAY)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ResolveHostname, - VARLINK_DEFINE_INPUT(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(family, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(flags, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(addresses, ResolvedAddress, VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(name, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(flags, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(family, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(flags, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(addresses, ResolvedAddress, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(flags, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ResolvedName, - VARLINK_DEFINE_FIELD(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(name, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_FIELD(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(name, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ResolveAddress, - VARLINK_DEFINE_INPUT(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(family, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(address, VARLINK_INT, VARLINK_ARRAY), - VARLINK_DEFINE_INPUT(flags, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(names, ResolvedName, VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(flags, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(family, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(address, SD_VARLINK_INT, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_INPUT(flags, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(names, ResolvedName, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(flags, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ResolvedService, - VARLINK_DEFINE_FIELD(priority, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(weight, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(port, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(hostname, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(canonicalName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD_BY_TYPE(addresses, ResolvedAddress, VARLINK_ARRAY|VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_FIELD(priority, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(weight, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(port, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(hostname, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(canonicalName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(addresses, ResolvedAddress, SD_VARLINK_ARRAY|SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ResolvedCanonical, - VARLINK_DEFINE_FIELD(name, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(type, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(domain, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_FIELD(name, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(type, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(domain, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ResolveService, - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(type, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(domain, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(family, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(flags, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(services, ResolvedService, VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(txt, VARLINK_STRING, VARLINK_ARRAY|VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(canonical, ResolvedCanonical, 0), - VARLINK_DEFINE_OUTPUT(flags, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(type, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(domain, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(family, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(flags, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(services, ResolvedService, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(txt, SD_VARLINK_STRING, SD_VARLINK_ARRAY|SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(canonical, ResolvedCanonical, 0), + SD_VARLINK_DEFINE_OUTPUT(flags, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( ResolvedRecord, - VARLINK_DEFINE_FIELD(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD_BY_TYPE(rr, ResourceRecord, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(raw, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_FIELD(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(rr, ResourceRecord, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(raw, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ResolveRecord, - VARLINK_DEFINE_INPUT(ifindex, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(name, VARLINK_STRING, 0), - VARLINK_DEFINE_INPUT(class, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(type, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(flags, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(rrs, ResolvedRecord, VARLINK_ARRAY), - VARLINK_DEFINE_OUTPUT(flags, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_INPUT(class, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(type, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(flags, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(rrs, ResolvedRecord, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_OUTPUT(flags, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_ERROR(NoNameServers); -static VARLINK_DEFINE_ERROR(NoSuchResourceRecord); -static VARLINK_DEFINE_ERROR(QueryTimedOut); -static VARLINK_DEFINE_ERROR(MaxAttemptsReached); -static VARLINK_DEFINE_ERROR(InvalidReply); -static VARLINK_DEFINE_ERROR(QueryAborted); -static VARLINK_DEFINE_ERROR( +static SD_VARLINK_DEFINE_ERROR(NoNameServers); +static SD_VARLINK_DEFINE_ERROR(NoSuchResourceRecord); +static SD_VARLINK_DEFINE_ERROR(QueryTimedOut); +static SD_VARLINK_DEFINE_ERROR(MaxAttemptsReached); +static SD_VARLINK_DEFINE_ERROR(InvalidReply); +static SD_VARLINK_DEFINE_ERROR(QueryAborted); +static SD_VARLINK_DEFINE_ERROR( DNSSECValidationFailed, - VARLINK_DEFINE_FIELD(result, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(extendedDNSErrorCode, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(extendedDNSErrorMessage, VARLINK_STRING, VARLINK_NULLABLE)); -static VARLINK_DEFINE_ERROR(NoTrustAnchor); -static VARLINK_DEFINE_ERROR(ResourceRecordTypeUnsupported); -static VARLINK_DEFINE_ERROR(NetworkDown); -static VARLINK_DEFINE_ERROR(NoSource); -static VARLINK_DEFINE_ERROR(StubLoop); -static VARLINK_DEFINE_ERROR( + SD_VARLINK_DEFINE_FIELD(result, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(extendedDNSErrorCode, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(extendedDNSErrorMessage, SD_VARLINK_STRING, SD_VARLINK_NULLABLE)); +static SD_VARLINK_DEFINE_ERROR(NoTrustAnchor); +static SD_VARLINK_DEFINE_ERROR(ResourceRecordTypeUnsupported); +static SD_VARLINK_DEFINE_ERROR(NetworkDown); +static SD_VARLINK_DEFINE_ERROR(NoSource); +static SD_VARLINK_DEFINE_ERROR(StubLoop); +static SD_VARLINK_DEFINE_ERROR( DNSError, - VARLINK_DEFINE_FIELD(rcode, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(extendedDNSErrorCode, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(extendedDNSErrorMessage, VARLINK_STRING, VARLINK_NULLABLE)); -static VARLINK_DEFINE_ERROR(CNAMELoop); -static VARLINK_DEFINE_ERROR(BadAddressSize); -static VARLINK_DEFINE_ERROR(ResourceRecordTypeInvalidForQuery); -static VARLINK_DEFINE_ERROR(ZoneTransfersNotPermitted); -static VARLINK_DEFINE_ERROR(ResourceRecordTypeObsolete); + SD_VARLINK_DEFINE_FIELD(rcode, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(extendedDNSErrorCode, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(extendedDNSErrorMessage, SD_VARLINK_STRING, SD_VARLINK_NULLABLE)); +static SD_VARLINK_DEFINE_ERROR(CNAMELoop); +static SD_VARLINK_DEFINE_ERROR(BadAddressSize); +static SD_VARLINK_DEFINE_ERROR(ResourceRecordTypeInvalidForQuery); +static SD_VARLINK_DEFINE_ERROR(ZoneTransfersNotPermitted); +static SD_VARLINK_DEFINE_ERROR(ResourceRecordTypeObsolete); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_Resolve, "io.systemd.Resolve", &vl_method_ResolveHostname, diff --git a/src/shared/varlink-io.systemd.Resolve.h b/src/shared/varlink-io.systemd.Resolve.h index 48a9241ef4..b7a828530d 100644 --- a/src/shared/varlink-io.systemd.Resolve.h +++ b/src/shared/varlink-io.systemd.Resolve.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkSymbol vl_type_ResourceKey; -extern const VarlinkSymbol vl_type_ResourceRecord; +extern const sd_varlink_symbol vl_type_ResourceKey; +extern const sd_varlink_symbol vl_type_ResourceRecord; -extern const VarlinkInterface vl_interface_io_systemd_Resolve; +extern const sd_varlink_interface vl_interface_io_systemd_Resolve; diff --git a/src/shared/varlink-io.systemd.UserDatabase.c b/src/shared/varlink-io.systemd.UserDatabase.c index c10a7d3eea..b714550f7d 100644 --- a/src/shared/varlink-io.systemd.UserDatabase.c +++ b/src/shared/varlink-io.systemd.UserDatabase.c @@ -2,38 +2,38 @@ #include "varlink-io.systemd.UserDatabase.h" -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( GetUserRecord, - VARLINK_DEFINE_INPUT(uid, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(userName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(service, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(record, VARLINK_OBJECT, 0), - VARLINK_DEFINE_OUTPUT(incomplete, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(uid, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(userName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(service, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(record, SD_VARLINK_OBJECT, 0), + SD_VARLINK_DEFINE_OUTPUT(incomplete, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( GetGroupRecord, - VARLINK_DEFINE_INPUT(gid, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(groupName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(service, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(record, VARLINK_OBJECT, 0), - VARLINK_DEFINE_OUTPUT(incomplete, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT(gid, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(groupName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(service, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(record, SD_VARLINK_OBJECT, 0), + SD_VARLINK_DEFINE_OUTPUT(incomplete, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( GetMemberships, - VARLINK_DEFINE_INPUT(userName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(groupName, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(service, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(userName, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(groupName, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_INPUT(userName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(groupName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(service, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(userName, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(groupName, SD_VARLINK_STRING, 0)); -static VARLINK_DEFINE_ERROR(NoRecordFound); -static VARLINK_DEFINE_ERROR(BadService); -static VARLINK_DEFINE_ERROR(ServiceNotAvailable); -static VARLINK_DEFINE_ERROR(ConflictingRecordNotFound); -static VARLINK_DEFINE_ERROR(EnumerationNotSupported); +static SD_VARLINK_DEFINE_ERROR(NoRecordFound); +static SD_VARLINK_DEFINE_ERROR(BadService); +static SD_VARLINK_DEFINE_ERROR(ServiceNotAvailable); +static SD_VARLINK_DEFINE_ERROR(ConflictingRecordNotFound); +static SD_VARLINK_DEFINE_ERROR(EnumerationNotSupported); /* As per https://systemd.io/USER_GROUP_API/ */ -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_UserDatabase, "io.systemd.UserDatabase", &vl_method_GetUserRecord, diff --git a/src/shared/varlink-io.systemd.UserDatabase.h b/src/shared/varlink-io.systemd.UserDatabase.h index 346ca848ac..fd8389f125 100644 --- a/src/shared/varlink-io.systemd.UserDatabase.h +++ b/src/shared/varlink-io.systemd.UserDatabase.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_UserDatabase; +extern const sd_varlink_interface vl_interface_io_systemd_UserDatabase; diff --git a/src/shared/varlink-io.systemd.h b/src/shared/varlink-io.systemd.h deleted file mode 100644 index 6c17c6c4c7..0000000000 --- a/src/shared/varlink-io.systemd.h +++ /dev/null @@ -1,6 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include "varlink-idl.h" - -extern const VarlinkInterface vl_interface_io_systemd; diff --git a/src/shared/varlink-io.systemd.oom.c b/src/shared/varlink-io.systemd.oom.c index e1da3fa527..67beb6b780 100644 --- a/src/shared/varlink-io.systemd.oom.c +++ b/src/shared/varlink-io.systemd.oom.c @@ -7,18 +7,18 @@ * Compare with io.systemd.ManagedOOM where the client/server roles of the service manager and oomd are * swapped! */ -VARLINK_DEFINE_STRUCT_TYPE( +SD_VARLINK_DEFINE_STRUCT_TYPE( ControlGroup, - VARLINK_DEFINE_FIELD(mode, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(path, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(property, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(limit, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_FIELD(mode, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(path, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(property, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( ReportManagedOOMCGroups, - VARLINK_DEFINE_INPUT_BY_TYPE(cgroups, ControlGroup, VARLINK_ARRAY)); + SD_VARLINK_DEFINE_INPUT_BY_TYPE(cgroups, ControlGroup, SD_VARLINK_ARRAY)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_oom, "io.systemd.oom", &vl_method_ReportManagedOOMCGroups, diff --git a/src/shared/varlink-io.systemd.oom.h b/src/shared/varlink-io.systemd.oom.h index 911dbc29e6..5964c49825 100644 --- a/src/shared/varlink-io.systemd.oom.h +++ b/src/shared/varlink-io.systemd.oom.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkSymbol vl_type_ControlGroup; -extern const VarlinkInterface vl_interface_io_systemd_oom; +extern const sd_varlink_symbol vl_type_ControlGroup; +extern const sd_varlink_interface vl_interface_io_systemd_oom; diff --git a/src/shared/varlink-io.systemd.service.c b/src/shared/varlink-io.systemd.service.c index 87479e3758..666778bd41 100644 --- a/src/shared/varlink-io.systemd.service.c +++ b/src/shared/varlink-io.systemd.service.c @@ -2,35 +2,36 @@ #include <unistd.h> +#include "macro.h" #include "varlink-io.systemd.service.h" -static VARLINK_DEFINE_METHOD(Ping); +static SD_VARLINK_DEFINE_METHOD(Ping); -static VARLINK_DEFINE_METHOD(Reload); +static SD_VARLINK_DEFINE_METHOD(Reload); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( SetLogLevel, - VARLINK_DEFINE_INPUT(level, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(level, SD_VARLINK_INT, 0)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_service, "io.systemd.service", &vl_method_Ping, &vl_method_Reload, &vl_method_SetLogLevel); -int varlink_method_ping(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int varlink_method_ping(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); log_debug("Received io.systemd.service.Ping"); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -int varlink_method_set_log_level(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "level", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int64, 0, SD_JSON_MANDATORY }, {} @@ -46,25 +47,25 @@ int varlink_method_set_log_level(Varlink *link, sd_json_variant *parameters, Var /* NOTE: The method does have 1 parameter, but we must compare to 2 here, because * sd_json_variant_elements() breaks abstraction and exposes internal structure of JsonObject. */ if (sd_json_variant_elements(parameters) != 2) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &level); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &level); if (r != 0) return r; if (LOG_PRI(level) != level) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - r = varlink_get_peer_uid(link, &uid); + r = sd_varlink_get_peer_uid(link, &uid); if (r < 0) return r; if (uid != getuid() && uid != 0) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, parameters); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, parameters); log_debug("Received io.systemd.service.SetLogLevel(%" PRIi64 ")", level); log_set_max_level(level); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } diff --git a/src/shared/varlink-io.systemd.service.h b/src/shared/varlink-io.systemd.service.h index 6ea1a0f11b..3f164783f5 100644 --- a/src/shared/varlink-io.systemd.service.h +++ b/src/shared/varlink-io.systemd.service.h @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink.h" -#include "varlink-idl.h" +#include "sd-varlink.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_service; +extern const sd_varlink_interface vl_interface_io_systemd_service; -int varlink_method_ping(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); -int varlink_method_set_log_level(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); +int varlink_method_ping(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/shared/varlink-io.systemd.sysext.c b/src/shared/varlink-io.systemd.sysext.c index 66e35341bc..b20afb2950 100644 --- a/src/shared/varlink-io.systemd.sysext.c +++ b/src/shared/varlink-io.systemd.sysext.c @@ -2,59 +2,59 @@ #include "varlink-io.systemd.sysext.h" -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( ImageClass, - VARLINK_DEFINE_ENUM_VALUE(sysext), - VARLINK_DEFINE_ENUM_VALUE(confext)); + SD_VARLINK_DEFINE_ENUM_VALUE(sysext), + SD_VARLINK_DEFINE_ENUM_VALUE(confext)); -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( ImageType, - VARLINK_DEFINE_ENUM_VALUE(directory), - VARLINK_DEFINE_ENUM_VALUE(subvolume), - VARLINK_DEFINE_ENUM_VALUE(raw), - VARLINK_DEFINE_ENUM_VALUE(block)); + SD_VARLINK_DEFINE_ENUM_VALUE(directory), + SD_VARLINK_DEFINE_ENUM_VALUE(subvolume), + SD_VARLINK_DEFINE_ENUM_VALUE(raw), + SD_VARLINK_DEFINE_ENUM_VALUE(block)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Merge, - VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(force, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(noReload, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(noexec, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(force, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(noReload, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(noexec, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Unmerge, - VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(noReload, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(noReload, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( Refresh, - VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(force, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(noReload, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(noexec, VARLINK_BOOL, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(force, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(noReload, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_INPUT(noexec, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( List, - VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT_BY_TYPE(Class, ImageClass, 0), - VARLINK_DEFINE_OUTPUT_BY_TYPE(Type, ImageType, 0), - VARLINK_DEFINE_OUTPUT(Name, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(Path, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(ReadOnly, VARLINK_BOOL, 0), - VARLINK_DEFINE_OUTPUT(CreationTimestamp, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(ModificationTimestamp, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(Usage, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(UsageExclusive, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(Limit, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(LimitExclusive, VARLINK_INT, VARLINK_NULLABLE)); + SD_VARLINK_DEFINE_INPUT_BY_TYPE(class, ImageClass, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(Class, ImageClass, 0), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(Type, ImageType, 0), + SD_VARLINK_DEFINE_OUTPUT(Name, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_OUTPUT(Path, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(ReadOnly, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_OUTPUT(CreationTimestamp, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(ModificationTimestamp, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(Usage, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(UsageExclusive, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(Limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(LimitExclusive, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); -static VARLINK_DEFINE_ERROR(NoImagesFound); +static SD_VARLINK_DEFINE_ERROR(NoImagesFound); -static VARLINK_DEFINE_ERROR( +static SD_VARLINK_DEFINE_ERROR( AlreadyMerged, - VARLINK_DEFINE_FIELD(hierarchy, VARLINK_STRING, 0)); + SD_VARLINK_DEFINE_FIELD(hierarchy, SD_VARLINK_STRING, 0)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_sysext, "io.systemd.sysext", &vl_type_ImageClass, diff --git a/src/shared/varlink-io.systemd.sysext.h b/src/shared/varlink-io.systemd.sysext.h index ee649c68b5..16769bdee6 100644 --- a/src/shared/varlink-io.systemd.sysext.h +++ b/src/shared/varlink-io.systemd.sysext.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "varlink-idl.h" +#include "sd-varlink-idl.h" -extern const VarlinkInterface vl_interface_io_systemd_sysext; +extern const sd_varlink_interface vl_interface_io_systemd_sysext; diff --git a/src/shared/varlink-org.varlink.service.c b/src/shared/varlink-org.varlink.service.c deleted file mode 100644 index e5122c08be..0000000000 --- a/src/shared/varlink-org.varlink.service.c +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ - -#include "varlink-org.varlink.service.h" - -static VARLINK_DEFINE_METHOD( - GetInfo, - VARLINK_DEFINE_OUTPUT(vendor, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(product, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(version, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(url, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(interfaces, VARLINK_STRING, VARLINK_ARRAY)); - -static VARLINK_DEFINE_METHOD( - GetInterfaceDescription, - VARLINK_DEFINE_INPUT(interface, VARLINK_STRING, 0), - VARLINK_DEFINE_OUTPUT(description, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_ERROR( - InterfaceNotFound, - VARLINK_DEFINE_FIELD(interface, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_ERROR( - MethodNotFound, - VARLINK_DEFINE_FIELD(method, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_ERROR( - MethodNotImplemented, - VARLINK_DEFINE_FIELD(method, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_ERROR( - InvalidParameter, - VARLINK_DEFINE_FIELD(parameter, VARLINK_STRING, 0)); - -static VARLINK_DEFINE_ERROR(PermissionDenied); - -static VARLINK_DEFINE_ERROR(ExpectedMore); - -/* As per https://varlink.org/Service */ -VARLINK_DEFINE_INTERFACE( - org_varlink_service, - "org.varlink.service", - &vl_method_GetInfo, - &vl_method_GetInterfaceDescription, - &vl_error_InterfaceNotFound, - &vl_error_MethodNotFound, - &vl_error_MethodNotImplemented, - &vl_error_InvalidParameter, - &vl_error_PermissionDenied, - &vl_error_ExpectedMore); diff --git a/src/shared/varlink-org.varlink.service.h b/src/shared/varlink-org.varlink.service.h deleted file mode 100644 index 75c55e6e82..0000000000 --- a/src/shared/varlink-org.varlink.service.h +++ /dev/null @@ -1,6 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include "varlink-idl.h" - -extern const VarlinkInterface vl_interface_org_varlink_service; diff --git a/src/shared/varlink-serialize.c b/src/shared/varlink-serialize.c new file mode 100644 index 0000000000..422808df39 --- /dev/null +++ b/src/shared/varlink-serialize.c @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "parse-util.h" +#include "varlink-internal.h" +#include "varlink-serialize.h" + +int varlink_server_serialize(sd_varlink_server *s, FILE *f, FDSet *fds) { + assert(f); + assert(fds); + + if (!s) + return 0; + + LIST_FOREACH(sockets, ss, s->sockets) { + int copy; + + assert(ss->address); + assert(ss->fd >= 0); + + fprintf(f, "varlink-server-socket-address=%s", ss->address); + + /* If we fail to serialize the fd, it will be considered an error during deserialization */ + copy = fdset_put_dup(fds, ss->fd); + if (copy < 0) + return copy; + + fprintf(f, " varlink-server-socket-fd=%i", copy); + + fputc('\n', f); + } + + return 0; +} + +int varlink_server_deserialize_one(sd_varlink_server *s, const char *value, FDSet *fds) { + _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL; + _cleanup_free_ char *address = NULL; + const char *v = ASSERT_PTR(value); + int r, fd = -EBADF; + char *buf; + size_t n; + + assert(s); + assert(fds); + + n = strcspn(v, " "); + address = strndup(v, n); + if (!address) + return log_oom_debug(); + + if (v[n] != ' ') + return varlink_server_log_errno(s, SYNTHETIC_ERRNO(EINVAL), + "Failed to deserialize sd_varlink_server_socket: %s: %m", value); + v = startswith(v + n + 1, "varlink-server-socket-fd="); + if (!v) + return varlink_server_log_errno(s, SYNTHETIC_ERRNO(EINVAL), + "Failed to deserialize VarlinkServerSocket fd %s: %m", value); + + n = strcspn(v, " "); + buf = strndupa_safe(v, n); + + fd = parse_fd(buf); + if (fd < 0) + return varlink_server_log_errno(s, fd, "Unable to parse VarlinkServerSocket varlink-server-socket-fd=%s: %m", buf); + if (!fdset_contains(fds, fd)) + return varlink_server_log_errno(s, SYNTHETIC_ERRNO(EBADF), + "VarlinkServerSocket varlink-server-socket-fd= has unknown fd %d: %m", fd); + + ss = new(VarlinkServerSocket, 1); + if (!ss) + return log_oom_debug(); + + *ss = (VarlinkServerSocket) { + .server = s, + .address = TAKE_PTR(address), + .fd = fdset_remove(fds, fd), + }; + + r = varlink_server_add_socket_event_source(s, ss, SD_EVENT_PRIORITY_NORMAL); + if (r < 0) + return varlink_server_log_errno(s, r, "Failed to add VarlinkServerSocket event source to the event loop: %m"); + + LIST_PREPEND(sockets, s->sockets, TAKE_PTR(ss)); + return 0; +} diff --git a/src/shared/varlink-serialize.h b/src/shared/varlink-serialize.h new file mode 100644 index 0000000000..149aa88b11 --- /dev/null +++ b/src/shared/varlink-serialize.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include <stdio.h> + +#include "sd-varlink.h" + +#include "fdset.h" + +int varlink_server_serialize(sd_varlink_server *s, FILE *f, FDSet *fds); +int varlink_server_deserialize_one(sd_varlink_server *s, const char *value, FDSet *fds); diff --git a/src/shared/varlink.h b/src/shared/varlink.h deleted file mode 100644 index 47eed171de..0000000000 --- a/src/shared/varlink.h +++ /dev/null @@ -1,301 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include <sys/socket.h> - -#include "sd-event.h" -#include "sd-json.h" - -#include "pidref.h" -#include "set.h" -#include "time-util.h" -#include "varlink-idl.h" - -/* A minimal Varlink implementation. We only implement the minimal, obvious bits here though. No validation, - * no introspection, no name service, just the stuff actually needed. - * - * You might wonder why we aren't using libvarlink here? Varlink is a very simple protocol, which allows us - * to write our own implementation relatively easily. However, the main reasons are these: - * - * • We want to use our own JSON subsystem, with all the benefits that brings (i.e. accurate unsigned+signed - * 64-bit integers, full fuzzing, logging during parsing and so on). If we'd want to use that with - * libvarlink we'd have to serialize and deserialize all the time from its own representation which is - * inefficient and nasty. - * - * • We want integration into sd-event, but also synchronous event-loop-less operation - * - * • We need proper per-UID accounting and access control, since we want to allow communication between - * unprivileged clients and privileged servers. - * - * • And of course, we don't want the name service and introspection stuff for now (though that might - * change). - */ - -typedef struct Varlink Varlink; -typedef struct VarlinkServer VarlinkServer; - -typedef enum VarlinkReplyFlags { - VARLINK_REPLY_ERROR = 1 << 0, - VARLINK_REPLY_CONTINUES = 1 << 1, - VARLINK_REPLY_LOCAL = 1 << 2, -} VarlinkReplyFlags; - -typedef enum VarlinkMethodFlags { - VARLINK_METHOD_ONEWAY = 1 << 0, - VARLINK_METHOD_MORE = 2 << 1, -} VarlinkMethodFlags; - -typedef enum VarlinkServerFlags { - VARLINK_SERVER_ROOT_ONLY = 1 << 0, /* Only accessible by root */ - VARLINK_SERVER_MYSELF_ONLY = 1 << 1, /* Only accessible by our own UID */ - VARLINK_SERVER_ACCOUNT_UID = 1 << 2, /* Do per user accounting */ - VARLINK_SERVER_INHERIT_USERDATA = 1 << 3, /* Initialize Varlink connection userdata from VarlinkServer userdata */ - VARLINK_SERVER_INPUT_SENSITIVE = 1 << 4, /* Automatically mark al connection input as sensitive */ - _VARLINK_SERVER_FLAGS_ALL = (1 << 5) - 1, -} VarlinkServerFlags; - -typedef int (*VarlinkMethod)(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); -typedef int (*VarlinkReply)(Varlink *link, sd_json_variant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata); -typedef int (*VarlinkConnect)(VarlinkServer *server, Varlink *link, void *userdata); -typedef void (*VarlinkDisconnect)(VarlinkServer *server, Varlink *link, void *userdata); - -int varlink_connect_address(Varlink **ret, const char *address); -int varlink_connect_exec(Varlink **ret, const char *command, char **argv); -int varlink_connect_url(Varlink **ret, const char *url); -int varlink_connect_fd(Varlink **ret, int fd); -int varlink_connect_fd_pair(Varlink **ret, int input_fd, int output_fd, const struct ucred *override_ucred); - -Varlink* varlink_ref(Varlink *link); -Varlink* varlink_unref(Varlink *v); - -int varlink_get_fd(Varlink *v); -int varlink_get_events(Varlink *v); -int varlink_get_timeout(Varlink *v, usec_t *ret); - -int varlink_attach_event(Varlink *v, sd_event *e, int64_t priority); -void varlink_detach_event(Varlink *v); -sd_event *varlink_get_event(Varlink *v); - -int varlink_process(Varlink *v); -int varlink_wait(Varlink *v, usec_t timeout); - -int varlink_is_idle(Varlink *v); - -int varlink_flush(Varlink *v); -int varlink_close(Varlink *v); - -Varlink* varlink_flush_close_unref(Varlink *v); -Varlink* varlink_close_unref(Varlink *v); - -/* Enqueue method call, not expecting a reply */ -int varlink_send(Varlink *v, const char *method, sd_json_variant *parameters); -int varlink_sendb(Varlink *v, const char *method, ...); -#define varlink_sendbo(v, method, ...) \ - varlink_sendb((v), (method), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Send method call and wait for reply */ -int varlink_call_full(Varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags); -static inline int varlink_call(Varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id) { - return varlink_call_full(v, method, parameters, ret_parameters, ret_error_id, NULL); -} -int varlink_call_and_log(Varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters); - -int varlink_callb_ap(Varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags, va_list ap); -static inline int varlink_callb_full(Varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags, ...) { - va_list ap; - int r; - - va_start(ap, ret_flags); - r = varlink_callb_ap(v, method, ret_parameters, ret_error_id, ret_flags, ap); - va_end(ap); - return r; -} -#define varlink_callbo_full(v, method, ret_parameters, ret_error_id, ret_flags, ...) \ - varlink_callb_full((v), (method), (ret_parameters), (ret_error_id), (ret_flags), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) -static inline int varlink_callb(Varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, ...) { - va_list ap; - int r; - - va_start(ap, ret_error_id); - r = varlink_callb_ap(v, method, ret_parameters, ret_error_id, NULL, ap); - va_end(ap); - return r; -} -#define varlink_callbo(v, method, ret_parameters, ret_error_id, ...) \ - varlink_callb((v), (method), (ret_parameters), (ret_error_id), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) -int varlink_callb_and_log(Varlink *v, const char *method, sd_json_variant **ret_parameters, ...); -#define varlink_callbo_and_log(v, method, ret_parameters, ...) \ - varlink_callb_and_log((v), (method), (ret_parameters), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Send method call and begin collecting all 'more' replies into an array, finishing when a final reply is sent */ -int varlink_collect_full(Varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags); -static inline int varlink_collect(Varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id) { - return varlink_collect_full(v, method, parameters, ret_parameters, ret_error_id, NULL); -} -int varlink_collectb(Varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, ...); -#define varlink_collectbo(v, method, ret_parameters, ret_error_id, ...) \ - varlink_collectb((v), (method), (ret_parameters), (ret_error_id), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Enqueue method call, expect a reply, which is eventually delivered to the reply callback */ -int varlink_invoke(Varlink *v, const char *method, sd_json_variant *parameters); -int varlink_invokeb(Varlink *v, const char *method, ...); -#define varlink_invokebo(v, method, ...) \ - varlink_invokeb((v), (method), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Enqueue method call, expect a reply now, and possibly more later, which are all delivered to the reply callback */ -int varlink_observe(Varlink *v, const char *method, sd_json_variant *parameters); -int varlink_observeb(Varlink *v, const char *method, ...); -#define varlink_observebo(v, method, ...) \ - varlink_observeb((v), (method), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Enqueue a final reply */ -int varlink_reply(Varlink *v, sd_json_variant *parameters); -int varlink_replyb(Varlink *v, ...); -#define varlink_replybo(v, ...) \ - varlink_replyb((v), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Enqueue a (final) error */ -int varlink_error(Varlink *v, const char *error_id, sd_json_variant *parameters); -int varlink_errorb(Varlink *v, const char *error_id, ...); -#define varlink_errorbo(v, error_id, ...) \ - varlink_errorb((v), (error_id), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) -int varlink_error_invalid_parameter(Varlink *v, sd_json_variant *parameters); -int varlink_error_invalid_parameter_name(Varlink *v, const char *name); -int varlink_error_errno(Varlink *v, int error); - -/* Enqueue a "more" reply */ -int varlink_notify(Varlink *v, sd_json_variant *parameters); -int varlink_notifyb(Varlink *v, ...); -#define varlink_notifybo(v, ...) \ - varlink_notifyb((v), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) - -/* Ask for the current message to be dispatched again */ -int varlink_dispatch_again(Varlink *v); - -/* Get the currently processed incoming message */ -int varlink_get_current_parameters(Varlink *v, sd_json_variant **ret); - -/* Parsing incoming data via json_dispatch() and generate a nice error on parse errors */ -int varlink_dispatch(Varlink *v, sd_json_variant *parameters, const sd_json_dispatch_field table[], void *userdata); - -/* Write outgoing fds into the socket (to be associated with the next enqueued message) */ -int varlink_push_fd(Varlink *v, int fd); -int varlink_push_dup_fd(Varlink *v, int fd); -int varlink_reset_fds(Varlink *v); - -/* Read incoming fds from the socket (associated with the currently handled message) */ -int varlink_peek_fd(Varlink *v, size_t i); -int varlink_peek_dup_fd(Varlink *v, size_t i); -int varlink_take_fd(Varlink *v, size_t i); - -int varlink_set_allow_fd_passing_input(Varlink *v, bool b); -int varlink_set_allow_fd_passing_output(Varlink *v, bool b); - -/* Bind a disconnect, reply or timeout callback */ -int varlink_bind_reply(Varlink *v, VarlinkReply reply); - -void* varlink_set_userdata(Varlink *v, void *userdata); -void* varlink_get_userdata(Varlink *v); - -int varlink_get_peer_uid(Varlink *v, uid_t *ret); -int varlink_get_peer_gid(Varlink *v, gid_t *ret); -int varlink_get_peer_pid(Varlink *v, pid_t *ret); -int varlink_get_peer_pidref(Varlink *v, PidRef *ret); - -int varlink_set_relative_timeout(Varlink *v, usec_t usec); - -VarlinkServer* varlink_get_server(Varlink *v); - -int varlink_set_description(Varlink *v, const char *d); - -/* Automatically mark the parameters part of incoming messages as security sensitive */ -int varlink_set_input_sensitive(Varlink *v); - -/* Create a varlink server */ -int varlink_server_new(VarlinkServer **ret, VarlinkServerFlags flags); -VarlinkServer *varlink_server_ref(VarlinkServer *s); -VarlinkServer *varlink_server_unref(VarlinkServer *s); - -/* Add addresses or fds to listen on */ -int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t mode); -int varlink_server_listen_fd(VarlinkServer *s, int fd); -int varlink_server_listen_auto(VarlinkServer *s); -int varlink_server_add_connection(VarlinkServer *s, int fd, Varlink **ret); -int varlink_server_add_connection_pair(VarlinkServer *s, int input_fd, int output_fd, const struct ucred *ucred_override, Varlink **ret); -int varlink_server_add_connection_stdio(VarlinkServer *s, Varlink **ret); - -/* Bind callbacks */ -int varlink_server_bind_method(VarlinkServer *s, const char *method, VarlinkMethod callback); -int varlink_server_bind_method_many_internal(VarlinkServer *s, ...); -#define varlink_server_bind_method_many(s, ...) varlink_server_bind_method_many_internal(s, __VA_ARGS__, NULL) -int varlink_server_bind_connect(VarlinkServer *s, VarlinkConnect connect); -int varlink_server_bind_disconnect(VarlinkServer *s, VarlinkDisconnect disconnect); - -/* Add interface definition */ -int varlink_server_add_interface(VarlinkServer *s, const VarlinkInterface *interface); -int varlink_server_add_interface_many_internal(VarlinkServer *s, ...); -#define varlink_server_add_interface_many(s, ...) varlink_server_add_interface_many_internal(s, __VA_ARGS__, NULL) - -void* varlink_server_set_userdata(VarlinkServer *s, void *userdata); -void* varlink_server_get_userdata(VarlinkServer *s); - -int varlink_server_attach_event(VarlinkServer *v, sd_event *e, int64_t priority); -int varlink_server_detach_event(VarlinkServer *v); -sd_event *varlink_server_get_event(VarlinkServer *v); - -int varlink_server_loop_auto(VarlinkServer *server); - -int varlink_server_shutdown(VarlinkServer *server); - -int varlink_server_set_exit_on_idle(VarlinkServer *s, bool b); - -unsigned varlink_server_connections_max(VarlinkServer *s); -unsigned varlink_server_connections_per_uid_max(VarlinkServer *s); - -int varlink_server_set_connections_per_uid_max(VarlinkServer *s, unsigned m); -int varlink_server_set_connections_max(VarlinkServer *s, unsigned m); - -unsigned varlink_server_current_connections(VarlinkServer *s); - -int varlink_server_set_description(VarlinkServer *s, const char *description); - -typedef enum VarlinkInvocationFlags { - VARLINK_ALLOW_LISTEN = 1 << 0, - VARLINK_ALLOW_ACCEPT = 1 << 1, - _VARLINK_SERVER_INVOCATION_FLAGS_MAX = (1 << 2) - 1, - _VARLINK_SERVER_INVOCATION_FLAGS_INVALID = -EINVAL, -} VarlinkInvocationFlags; - -int varlink_invocation(VarlinkInvocationFlags flags); - -int varlink_error_to_errno(const char *error, sd_json_variant *parameters); - -int varlink_many_notifyb(Set *s, ...); -#define varlink_many_notifybo(s, ...) \ - varlink_many_notifyb((s), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) -int varlink_many_reply(Set *s, sd_json_variant *parameters); -int varlink_many_error(Set *s, const char *error_id, sd_json_variant *parameters); - -DEFINE_TRIVIAL_CLEANUP_FUNC(Varlink *, varlink_unref); -DEFINE_TRIVIAL_CLEANUP_FUNC(Varlink *, varlink_close_unref); -DEFINE_TRIVIAL_CLEANUP_FUNC(Varlink *, varlink_flush_close_unref); -DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServer *, varlink_server_unref); - -/* These are local errors that never cross the wire, and are our own invention */ -#define VARLINK_ERROR_DISCONNECTED "io.systemd.Disconnected" -#define VARLINK_ERROR_TIMEOUT "io.systemd.TimedOut" -#define VARLINK_ERROR_PROTOCOL "io.systemd.Protocol" - -/* This one we invented, and use for generically propagating system errors (errno) to clients */ -#define VARLINK_ERROR_SYSTEM "io.systemd.System" - -/* This one we invented and is a weaker version of "org.varlink.service.PermissionDenied", and indicates that if user would allow interactive auth, we might allow access */ -#define VARLINK_ERROR_INTERACTIVE_AUTHENTICATION_REQUIRED "io.systemd.InteractiveAuthenticationRequired" - -/* These are errors defined in the Varlink spec */ -#define VARLINK_ERROR_INTERFACE_NOT_FOUND "org.varlink.service.InterfaceNotFound" -#define VARLINK_ERROR_METHOD_NOT_FOUND "org.varlink.service.MethodNotFound" -#define VARLINK_ERROR_METHOD_NOT_IMPLEMENTED "org.varlink.service.MethodNotImplemented" -#define VARLINK_ERROR_INVALID_PARAMETER "org.varlink.service.InvalidParameter" -#define VARLINK_ERROR_PERMISSION_DENIED "org.varlink.service.PermissionDenied" -#define VARLINK_ERROR_EXPECTED_MORE "org.varlink.service.ExpectedMore" diff --git a/src/ssh-generator/ssh-proxy.c b/src/ssh-generator/ssh-proxy.c index 3631113612..67bdb056ef 100644 --- a/src/ssh-generator/ssh-proxy.c +++ b/src/ssh-generator/ssh-proxy.c @@ -4,6 +4,8 @@ #include <stdio.h> #include <unistd.h> +#include "sd-varlink.h" + #include "fd-util.h" #include "io-util.h" #include "iovec-util.h" @@ -14,7 +16,7 @@ #include "socket-util.h" #include "string-util.h" #include "strv.h" -#include "varlink.h" +#include "varlink-util.h" static int process_vsock_cid(unsigned cid, const char *port) { int r; @@ -138,13 +140,13 @@ static int process_vsock_mux(const char *path, const char *port) { } static int process_machine(const char *machine, const char *port) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; assert(machine); assert(port); - r = varlink_connect_address(&vl, "/run/systemd/machine/io.systemd.Machine"); + r = sd_varlink_connect_address(&vl, "/run/systemd/machine/io.systemd.Machine"); if (r < 0) return log_error_errno(r, "Failed to connect to machined on /run/systemd/machine/io.systemd.Machine: %m"); diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 3dc966a61e..c696daad0d 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -8,6 +8,7 @@ #include <unistd.h> #include "sd-bus.h" +#include "sd-varlink.h" #include "build.h" #include "bus-locator.h" @@ -48,7 +49,6 @@ #include "string-util.h" #include "terminal-util.h" #include "user-util.h" -#include "varlink.h" #include "varlink-io.systemd.sysext.h" #include "verbs.h" @@ -411,7 +411,7 @@ static int verb_unmerge(int argc, char **argv, void *userdata) { arg_no_reload); } -static int parse_image_class_parameter(Varlink *link, const char *value, ImageClass *image_class, char ***hierarchies) { +static int parse_image_class_parameter(sd_varlink *link, const char *value, ImageClass *image_class, char ***hierarchies) { _cleanup_strv_free_ char **h = NULL; ImageClass c; int r; @@ -424,7 +424,7 @@ static int parse_image_class_parameter(Varlink *link, const char *value, ImageCl c = image_class_from_string(value); if (!IN_SET(c, IMAGE_SYSEXT, IMAGE_CONFEXT)) - return varlink_error_invalid_parameter_name(link, "class"); + return sd_varlink_error_invalid_parameter_name(link, "class"); if (hierarchies) { r = parse_env_extension_hierarchies(&h, image_class_info[c].name_env); @@ -443,7 +443,7 @@ typedef struct MethodUnmergeParameters { int no_reload; } MethodUnmergeParameters; -static int vl_method_unmerge(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_unmerge(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "class", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodUnmergeParameters, class), 0 }, @@ -459,7 +459,7 @@ static int vl_method_unmerge(Varlink *link, sd_json_variant *parameters, Varlink assert(link); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -473,7 +473,7 @@ static int vl_method_unmerge(Varlink *link, sd_json_variant *parameters, Varlink if (r < 0) return r; - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } static int verb_status(int argc, char **argv, void *userdata) { @@ -1918,7 +1918,7 @@ typedef struct MethodMergeParameters { int noexec; } MethodMergeParameters; -static int parse_merge_parameters(Varlink *link, sd_json_variant *parameters, MethodMergeParameters *p) { +static int parse_merge_parameters(sd_varlink *link, sd_json_variant *parameters, MethodMergeParameters *p) { static const sd_json_dispatch_field dispatch_table[] = { { "class", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodMergeParameters, class), 0 }, @@ -1932,10 +1932,10 @@ static int parse_merge_parameters(Varlink *link, sd_json_variant *parameters, Me assert(parameters); assert(p); - return varlink_dispatch(link, parameters, dispatch_table, p); + return sd_varlink_dispatch(link, parameters, dispatch_table, p); } -static int vl_method_merge(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_merge(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_hashmap_free_ Hashmap *images = NULL; MethodMergeParameters p = { .force = -1, @@ -1968,7 +1968,7 @@ static int vl_method_merge(Varlink *link, sd_json_variant *parameters, VarlinkMe if (r < 0) return r; if (r > 0) - return varlink_errorbo(link, "io.systemd.sysext.AlreadyMerged", SD_JSON_BUILD_PAIR_STRING("hierarchy", which)); + return sd_varlink_errorbo(link, "io.systemd.sysext.AlreadyMerged", SD_JSON_BUILD_PAIR_STRING("hierarchy", which)); r = merge(image_class, hierarchies ?: arg_hierarchies, @@ -1979,7 +1979,7 @@ static int vl_method_merge(Varlink *link, sd_json_variant *parameters, VarlinkMe if (r < 0) return r; - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } static int refresh( @@ -2038,7 +2038,7 @@ static int verb_refresh(int argc, char **argv, void *userdata) { arg_noexec); } -static int vl_method_refresh(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_refresh(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { MethodMergeParameters p = { .force = -1, @@ -2067,7 +2067,7 @@ static int vl_method_refresh(Varlink *link, sd_json_variant *parameters, Varlink if (r < 0) return r; - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } static int verb_list(int argc, char **argv, void *userdata) { @@ -2113,7 +2113,7 @@ typedef struct MethodListParameters { const char *class; } MethodListParameters; -static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_list(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "class", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodListParameters, class), 0 }, @@ -2129,7 +2129,7 @@ static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMet assert(link); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -2148,7 +2148,7 @@ static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMet HASHMAP_FOREACH(img, images) { if (v) { /* Send previous item with more=true */ - r = varlink_notify(link, v); + r = sd_varlink_notify(link, v); if (r < 0) return r; } @@ -2161,9 +2161,9 @@ static int vl_method_list(Varlink *link, sd_json_variant *parameters, VarlinkMet } if (v) /* Send final item with more=false */ - return varlink_reply(link, v); + return sd_varlink_reply(link, v); - return varlink_error(link, "io.systemd.sysext.NoImagesFound", NULL); + return sd_varlink_error(link, "io.systemd.sysext.NoImagesFound", NULL); } static int verb_help(int argc, char **argv, void *userdata) { @@ -2313,7 +2313,7 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached(); } - r = varlink_invocation(VARLINK_ALLOW_ACCEPT); + r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT); if (r < 0) return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m"); if (r > 0) @@ -2367,19 +2367,19 @@ static int run(int argc, char *argv[]) { return log_error_errno(r, "Failed to parse environment variable: %m"); if (arg_varlink) { - _cleanup_(varlink_server_unrefp) VarlinkServer *varlink_server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; /* Invocation as Varlink service */ - r = varlink_server_new(&varlink_server, VARLINK_SERVER_ROOT_ONLY); + r = sd_varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ROOT_ONLY); if (r < 0) return log_error_errno(r, "Failed to allocate Varlink server: %m"); - r = varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_sysext); + r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_sysext); if (r < 0) return log_error_errno(r, "Failed to add Varlink interface: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( varlink_server, "io.systemd.sysext.Merge", vl_method_merge, "io.systemd.sysext.Unmerge", vl_method_unmerge, @@ -2388,7 +2388,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to bind Varlink methods: %m"); - r = varlink_server_loop_auto(varlink_server); + r = sd_varlink_server_loop_auto(varlink_server); if (r == -EPERM) return log_error_errno(r, "Invoked by unprivileged Varlink peer, refusing."); if (r < 0) diff --git a/src/systemd/meson.build b/src/systemd/meson.build index 4065ac4f30..06ba4cbc07 100644 --- a/src/systemd/meson.build +++ b/src/systemd/meson.build @@ -15,6 +15,8 @@ _systemd_headers = [ 'sd-login.h', 'sd-messages.h', 'sd-path.h', + 'sd-varlink.h', + 'sd-varlink-idl.h', ] # https://github.com/mesonbuild/meson/issues/1633 diff --git a/src/systemd/sd-varlink-idl.h b/src/systemd/sd-varlink-idl.h new file mode 100644 index 0000000000..af36f3daf9 --- /dev/null +++ b/src/systemd/sd-varlink-idl.h @@ -0,0 +1,204 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#ifndef foosdvarlinkidlhfoo +#define foosdvarlinkidlhfoo + +/*** + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <https://www.gnu.org/licenses/>. +***/ + +#include <errno.h> +#include <stdbool.h> +#include <stdio.h> + +#include "sd-json.h" + +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; + +/* This implements the Varlink Interface Definition Language ("Varlink IDL"), + * i.e. https://varlink.org/Interface-Definition + * + * Primarily allows encoding static interface definitions in C code, that can be converted to the textual IDL + * format on-the-fly. Can also parse the textual format back to C structures. Validates the interface + * definitions for internal consistency and validates JSON objects against the interface definitions. */ + +__extension__ typedef enum sd_varlink_symbol_type_t { + SD_VARLINK_ENUM_TYPE, + SD_VARLINK_STRUCT_TYPE, + SD_VARLINK_METHOD, + SD_VARLINK_ERROR, + _SD_VARLINK_INTERFACE_COMMENT, /* Not really a symbol, just a comment about the interface */ + _SD_VARLINK_SYMBOL_COMMENT, /* Not really a symbol, just a comment about a symbol */ + _SD_VARLINK_SYMBOL_TYPE_MAX, + _SD_VARLINK_SYMBOL_TYPE_INVALID = -EINVAL, + _SD_ENUM_FORCE_S64(SD_VARLINK_SYMBOL) +} sd_varlink_symbol_type_t; + +__extension__ typedef enum sd_varlink_field_type_t { + _SD_VARLINK_FIELD_TYPE_END_MARKER = 0, /* zero type means: this is the last entry in the fields[] array of VarlinkSymbol */ + SD_VARLINK_STRUCT, + SD_VARLINK_ENUM, + SD_VARLINK_NAMED_TYPE, + SD_VARLINK_BOOL, + SD_VARLINK_INT, + SD_VARLINK_FLOAT, + SD_VARLINK_STRING, + SD_VARLINK_OBJECT, + SD_VARLINK_ENUM_VALUE, + _SD_VARLINK_FIELD_COMMENT, /* Not really a field, just a comment about a field*/ + _SD_VARLINK_FIELD_TYPE_MAX, + _SD_VARLINK_FIELD_TYPE_INVALID = -EINVAL, + _SD_ENUM_FORCE_S64(SD_VARLINK_FIELD) +} sd_varlink_field_type_t; + +__extension__ typedef enum sd_varlink_field_direction_t { + SD_VARLINK_REGULAR, + SD_VARLINK_INPUT, + SD_VARLINK_OUTPUT, + _SD_VARLINK_FIELD_DIRECTION_MAX, + _SD_VARLINK_FIELD_DIRECTION_INVALID = -EINVAL, + _SD_ENUM_FORCE_S64(SD_VARLINK_FIELD_DIRECTION) +} sd_varlink_field_direction_t; + +__extension__ typedef enum sd_varlink_field_flags_t { + SD_VARLINK_ARRAY = 1 << 0, + SD_VARLINK_MAP = 1 << 1, + SD_VARLINK_NULLABLE = 1 << 2, + _SD_VARLINK_FIELD_FLAGS_MAX = (1 << 3) - 1, + _SD_VARLINK_FIELD_FLAGS_INVALID = -EINVAL, + _SD_ENUM_FORCE_S64(SD_VARLINK_FIELD_FLAGS) +} sd_varlink_field_flags_t; + +typedef struct sd_varlink_field sd_varlink_field; +typedef struct sd_varlink_symbol sd_varlink_symbol; +typedef struct sd_varlink_interface sd_varlink_interface; + +/* Fields are the components making up symbols */ +struct sd_varlink_field { + const char *name; + sd_varlink_field_type_t field_type; + sd_varlink_field_flags_t field_flags; + sd_varlink_field_direction_t field_direction; /* in case of method call fields: whether input or output argument */ + const sd_varlink_symbol *symbol; /* VARLINK_STRUCT, VARLINK_ENUM: anonymous symbol that carries the definitions, VARLINK_NAMED_TYPE: resolved symbol */ + const char *named_type; /* VARLINK_NAMED_TYPE */ +}; + +/* Symbols are primary named concepts in an interface, and are methods, errors or named types (either enum or struct). */ +struct sd_varlink_symbol { + const char *name; /* most symbols have a name, but sometimes they are created on-the-fly for fields, in which case they are anonymous */ + sd_varlink_symbol_type_t symbol_type; +#if __STDC_VERSION__ >= 199901L + sd_varlink_field fields[]; +#else + sd_varlink_field fields[1]; +#endif +}; + +/* An interface definition has a name and consist of symbols */ +struct sd_varlink_interface { + const char *name; +#if __STDC_VERSION__ >= 199901L + const sd_varlink_symbol *symbols[]; +#else + const sd_varlink_symbol *symbols[1]; +#endif +}; + +#define SD_VARLINK_DEFINE_FIELD(_name, _field_type, _field_flags) \ + { .name = #_name, .field_type = (_field_type), .field_flags = (_field_flags) } + +#define SD_VARLINK_DEFINE_FIELD_BY_TYPE(_name, _named_type, _field_flags) \ + { .name = #_name, .field_type = SD_VARLINK_NAMED_TYPE, .named_type = #_named_type, .symbol = &vl_type_ ## _named_type, .field_flags = (_field_flags) } + +#define SD_VARLINK_DEFINE_INPUT(_name, _field_type, _field_flags) \ + { .name = #_name, .field_type = (_field_type), .field_flags = (_field_flags), .field_direction = SD_VARLINK_INPUT } + +#define SD_VARLINK_DEFINE_INPUT_BY_TYPE(_name, _named_type, _field_flags) \ + { .name = #_name, .field_type = SD_VARLINK_NAMED_TYPE, .named_type = #_named_type, .symbol = &vl_type_ ## _named_type, .field_flags = (_field_flags), .field_direction = SD_VARLINK_INPUT } + +#define SD_VARLINK_DEFINE_OUTPUT(_name, _field_type, _field_flags) \ + { .name = #_name, .field_type = (_field_type), .field_flags = (_field_flags), .field_direction = SD_VARLINK_OUTPUT } + +#define SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(_name, _named_type, _field_flags) \ + { .name = #_name, .field_type = SD_VARLINK_NAMED_TYPE, .named_type = #_named_type, .symbol = &vl_type_ ## _named_type, .field_flags = (_field_flags), .field_direction = SD_VARLINK_OUTPUT } + +#define SD_VARLINK_DEFINE_ENUM_VALUE(_name) \ + { .name = #_name, .field_type = SD_VARLINK_ENUM_VALUE } + +#define SD_VARLINK_FIELD_COMMENT(text) \ + { .name = "" text, .field_type = _SD_VARLINK_FIELD_COMMENT } + +/* C++ older than C20+ does not support __VA_OPT__(), but we really need it here. */ +#if (defined(__STDC_VERSION__) && ((__STDC_VERSION__ >= 202311L) || defined(_GNU_SOURCE))) || (defined(__cplusplus) && (__cplusplus >= 202002L)) +#define SD_VARLINK_DEFINE_METHOD(_name, ...) \ + const sd_varlink_symbol vl_method_ ## _name = { \ + .name = #_name, \ + .symbol_type = SD_VARLINK_METHOD, \ + .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ + } + +#define SD_VARLINK_DEFINE_ERROR(_name, ...) \ + const sd_varlink_symbol vl_error_ ## _name = { \ + .name = #_name, \ + .symbol_type = SD_VARLINK_ERROR, \ + .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ + } + +#define SD_VARLINK_DEFINE_STRUCT_TYPE(_name, ...) \ + const sd_varlink_symbol vl_type_ ## _name = { \ + .name = #_name, \ + .symbol_type = SD_VARLINK_STRUCT_TYPE, \ + .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ + } + +#define SD_VARLINK_DEFINE_ENUM_TYPE(_name, ...) \ + const sd_varlink_symbol vl_type_ ## _name = { \ + .name = #_name, \ + .symbol_type = SD_VARLINK_ENUM_TYPE, \ + .fields = { __VA_ARGS__ __VA_OPT__(,) {}}, \ + } + +#define SD_VARLINK_DEFINE_INTERFACE(_name, _full_name, ...) \ + const sd_varlink_interface vl_interface_ ## _name = { \ + .name = (_full_name), \ + .symbols = { __VA_ARGS__ __VA_OPT__(,) NULL}, \ + } +#endif + +#define SD_VARLINK_SYMBOL_COMMENT(text) \ + &(const sd_varlink_symbol) { \ + .name = "" text, \ + .symbol_type = _SD_VARLINK_SYMBOL_COMMENT, \ + } + +#define SD_VARLINK_INTERFACE_COMMENT(text) \ + &(const sd_varlink_symbol) { \ + .name = "" text, \ + .symbol_type = _SD_VARLINK_INTERFACE_COMMENT, \ + } + +__extension__ typedef enum sd_varlink_idl_format_flags_t { + SD_VARLINK_IDL_FORMAT_COLOR = 1 << 0, + SD_VARLINK_IDL_FORMAT_COLOR_AUTO = 1 << 1, + _SD_ENUM_FORCE_S64(SD_VARLINK_IDL_FORMAT) +} sd_varlink_idl_format_flags_t; + +int sd_varlink_idl_dump(FILE *f, const sd_varlink_interface *interface, sd_varlink_idl_format_flags_t flags, size_t cols); +int sd_varlink_idl_format_full(const sd_varlink_interface *interface, sd_varlink_idl_format_flags_t flags, size_t cols, char **ret); +int sd_varlink_idl_format(const sd_varlink_interface *interface, char **ret); + +_SD_END_DECLARATIONS; + +#endif diff --git a/src/systemd/sd-varlink.h b/src/systemd/sd-varlink.h new file mode 100644 index 0000000000..f93756ef52 --- /dev/null +++ b/src/systemd/sd-varlink.h @@ -0,0 +1,296 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#ifndef foosdvarlinkhfoo +#define foosdvarlinkhfoo + +/*** + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <https://www.gnu.org/licenses/>. +***/ + +#include <stdarg.h> +#include <sys/types.h> + +#include "sd-event.h" +#include "sd-json.h" +#include "sd-varlink-idl.h" + +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; + +/* A minimal Varlink implementation. We only implement the minimal, obvious bits here though. No validation, + * no introspection, no name service, just the stuff actually needed. + * + * You might wonder why we aren't using libvarlink here? Varlink is a very simple protocol, which allows us + * to write our own implementation relatively easily. However, the main reasons are these: + * + * • We want to use our own JSON subsystem, with all the benefits that brings (i.e. accurate unsigned+signed + * 64-bit integers, full fuzzing, logging during parsing and so on). If we'd want to use that with + * libvarlink we'd have to serialize and deserialize all the time from its own representation which is + * inefficient and nasty. + * + * • We want integration into sd-event, but also synchronous event-loop-less operation + * + * • We need proper per-UID accounting and access control, since we want to allow communication between + * unprivileged clients and privileged servers. + * + * • And of course, we don't want the name service and introspection stuff for now (though that might + * change). + */ + +typedef struct sd_varlink sd_varlink; +typedef struct sd_varlink_server sd_varlink_server; + +__extension__ typedef enum sd_varlink_reply_flags_t { + SD_VARLINK_REPLY_ERROR = 1 << 0, + SD_VARLINK_REPLY_CONTINUES = 1 << 1, + SD_VARLINK_REPLY_LOCAL = 1 << 2, + _SD_ENUM_FORCE_S64(SD_VARLINK_REPLY) +} sd_varlink_reply_flags_t; + +__extension__ typedef enum sd_varlink_method_flags_t { + SD_VARLINK_METHOD_ONEWAY = 1 << 0, + SD_VARLINK_METHOD_MORE = 1 << 1, + _SD_ENUM_FORCE_S64(SD_VARLINK_METHOD) +} sd_varlink_method_flags_t; + +__extension__ typedef enum sd_varlink_server_flags_t { + SD_VARLINK_SERVER_ROOT_ONLY = 1 << 0, /* Only accessible by root */ + SD_VARLINK_SERVER_MYSELF_ONLY = 1 << 1, /* Only accessible by our own UID */ + SD_VARLINK_SERVER_ACCOUNT_UID = 1 << 2, /* Do per user accounting */ + SD_VARLINK_SERVER_INHERIT_USERDATA = 1 << 3, /* Initialize Varlink connection userdata from VarlinkServer userdata */ + SD_VARLINK_SERVER_INPUT_SENSITIVE = 1 << 4, /* Automatically mark all connection input as sensitive */ + _SD_ENUM_FORCE_S64(SD_VARLINK_SERVER) +} sd_varlink_server_flags_t; + +__extension__ typedef enum sd_varlink_invocation_flags_t { + SD_VARLINK_ALLOW_LISTEN = 1 << 0, + SD_VARLINK_ALLOW_ACCEPT = 1 << 1, + _SD_ENUM_FORCE_S64(SD_VARLINK_INVOCATION) +} sd_varlink_invocation_flags_t; + +typedef int (*sd_varlink_method_t)(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +typedef int (*sd_varlink_reply_t)(sd_varlink *link, sd_json_variant *parameters, const char *error_id, sd_varlink_reply_flags_t flags, void *userdata); +typedef int (*sd_varlink_connect_t)(sd_varlink_server *server, sd_varlink *link, void *userdata); +typedef void (*sd_varlink_disconnect_t)(sd_varlink_server *server, sd_varlink *link, void *userdata); + +struct ucred; /* forward declaration of the Linux structure */ + +int sd_varlink_connect_address(sd_varlink **ret, const char *address); +int sd_varlink_connect_exec(sd_varlink **ret, const char *command, char **argv); +int sd_varlink_connect_url(sd_varlink **ret, const char *url); +int sd_varlink_connect_fd(sd_varlink **ret, int fd); +int sd_varlink_connect_fd_pair(sd_varlink **ret, int input_fd, int output_fd, const struct ucred *override_ucred); + +sd_varlink* sd_varlink_ref(sd_varlink *link); +sd_varlink* sd_varlink_unref(sd_varlink *v); + +int sd_varlink_get_fd(sd_varlink *v); +int sd_varlink_get_events(sd_varlink *v); +int sd_varlink_get_timeout(sd_varlink *v, uint64_t *ret); + +int sd_varlink_attach_event(sd_varlink *v, sd_event *e, int64_t priority); +void sd_varlink_detach_event(sd_varlink *v); +sd_event *sd_varlink_get_event(sd_varlink *v); + +int sd_varlink_process(sd_varlink *v); +int sd_varlink_wait(sd_varlink *v, uint64_t timeout); + +int sd_varlink_is_idle(sd_varlink *v); + +int sd_varlink_flush(sd_varlink *v); +int sd_varlink_close(sd_varlink *v); + +sd_varlink* sd_varlink_flush_close_unref(sd_varlink *v); +sd_varlink* sd_varlink_close_unref(sd_varlink *v); + +/* Enqueue method call, not expecting a reply */ +int sd_varlink_send(sd_varlink *v, const char *method, sd_json_variant *parameters); +int sd_varlink_sendb(sd_varlink *v, const char *method, ...); +#define sd_varlink_sendbo(v, method, ...) \ + sd_varlink_sendb((v), (method), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Send method call and wait for reply */ +int sd_varlink_call_full(sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id, sd_varlink_reply_flags_t *ret_flags); +int sd_varlink_call(sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id); + +int sd_varlink_callb_ap(sd_varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, sd_varlink_reply_flags_t *ret_flags, va_list ap); +int sd_varlink_callb_full(sd_varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, sd_varlink_reply_flags_t *ret_flags, ...); +#define sd_varlink_callbo_full(v, method, ret_parameters, ret_error_id, ret_flags, ...) \ + sd_varlink_callb_full((v), (method), (ret_parameters), (ret_error_id), (ret_flags), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) +int sd_varlink_callb(sd_varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, ...); +#define sd_varlink_callbo(v, method, ret_parameters, ret_error_id, ...) \ + sd_varlink_callb((v), (method), (ret_parameters), (ret_error_id), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Send method call and begin collecting all 'more' replies into an array, finishing when a final reply is sent */ +int sd_varlink_collect_full(sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id, sd_varlink_reply_flags_t *ret_flags); +int sd_varlink_collect(sd_varlink *v, const char *method, sd_json_variant *parameters, sd_json_variant **ret_parameters, const char **ret_error_id); +int sd_varlink_collectb(sd_varlink *v, const char *method, sd_json_variant **ret_parameters, const char **ret_error_id, ...); +#define sd_varlink_collectbo(v, method, ret_parameters, ret_error_id, ...) \ + sd_varlink_collectb((v), (method), (ret_parameters), (ret_error_id), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Enqueue method call, expect a reply, which is eventually delivered to the reply callback */ +int sd_varlink_invoke(sd_varlink *v, const char *method, sd_json_variant *parameters); +int sd_varlink_invokeb(sd_varlink *v, const char *method, ...); +#define sd_varlink_invokebo(v, method, ...) \ + sd_varlink_invokeb((v), (method), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Enqueue method call, expect a reply now, and possibly more later, which are all delivered to the reply callback */ +int sd_varlink_observe(sd_varlink *v, const char *method, sd_json_variant *parameters); +int sd_varlink_observeb(sd_varlink *v, const char *method, ...); +#define sd_varlink_observebo(v, method, ...) \ + sd_varlink_observeb((v), (method), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Enqueue a final reply */ +int sd_varlink_reply(sd_varlink *v, sd_json_variant *parameters); +int sd_varlink_replyb(sd_varlink *v, ...); +#define sd_varlink_replybo(v, ...) \ + sd_varlink_replyb((v), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Enqueue a (final) error */ +int sd_varlink_error(sd_varlink *v, const char *error_id, sd_json_variant *parameters); +int sd_varlink_errorb(sd_varlink *v, const char *error_id, ...); +#define sd_varlink_errorbo(v, error_id, ...) \ + sd_varlink_errorb((v), (error_id), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) +int sd_varlink_error_invalid_parameter(sd_varlink *v, sd_json_variant *parameters); +int sd_varlink_error_invalid_parameter_name(sd_varlink *v, const char *name); +int sd_varlink_error_errno(sd_varlink *v, int error); + +/* Enqueue a "more" reply */ +int sd_varlink_notify(sd_varlink *v, sd_json_variant *parameters); +int sd_varlink_notifyb(sd_varlink *v, ...); +#define sd_varlink_notifybo(v, ...) \ + sd_varlink_notifyb((v), SD_JSON_BUILD_OBJECT(__VA_ARGS__)) + +/* Ask for the current message to be dispatched again */ +int sd_varlink_dispatch_again(sd_varlink *v); + +/* Get the currently processed incoming message */ +int sd_varlink_get_current_parameters(sd_varlink *v, sd_json_variant **ret); + +/* Parsing incoming data via json_dispatch() and generate a nice error on parse errors */ +int sd_varlink_dispatch(sd_varlink *v, sd_json_variant *parameters, const sd_json_dispatch_field table[], void *userdata); + +/* Write outgoing fds into the socket (to be associated with the next enqueued message) */ +int sd_varlink_push_fd(sd_varlink *v, int fd); +int sd_varlink_push_dup_fd(sd_varlink *v, int fd); +int sd_varlink_reset_fds(sd_varlink *v); + +/* Read incoming fds from the socket (associated with the currently handled message) */ +int sd_varlink_peek_fd(sd_varlink *v, size_t i); +int sd_varlink_peek_dup_fd(sd_varlink *v, size_t i); +int sd_varlink_take_fd(sd_varlink *v, size_t i); + +int sd_varlink_set_allow_fd_passing_input(sd_varlink *v, int b); +int sd_varlink_set_allow_fd_passing_output(sd_varlink *v, int b); + +/* Bind a disconnect, reply or timeout callback */ +int sd_varlink_bind_reply(sd_varlink *v, sd_varlink_reply_t reply); + +void* sd_varlink_set_userdata(sd_varlink *v, void *userdata); +void* sd_varlink_get_userdata(sd_varlink *v); + +int sd_varlink_get_peer_uid(sd_varlink *v, uid_t *ret); +int sd_varlink_get_peer_gid(sd_varlink *v, gid_t *ret); +int sd_varlink_get_peer_pid(sd_varlink *v, pid_t *ret); +int sd_varlink_get_peer_pidfd(sd_varlink *v); + +int sd_varlink_set_relative_timeout(sd_varlink *v, uint64_t usec); + +sd_varlink_server* sd_varlink_get_server(sd_varlink *v); + +int sd_varlink_set_description(sd_varlink *v, const char *d); + +/* Automatically mark the parameters part of incoming messages as security sensitive */ +int sd_varlink_set_input_sensitive(sd_varlink *v); + +/* Create a varlink server */ +int sd_varlink_server_new(sd_varlink_server **ret, sd_varlink_server_flags_t flags); +sd_varlink_server* sd_varlink_server_ref(sd_varlink_server *s); +sd_varlink_server* sd_varlink_server_unref(sd_varlink_server *s); + +/* Add addresses or fds to listen on */ +int sd_varlink_server_listen_address(sd_varlink_server *s, const char *address, mode_t mode); +int sd_varlink_server_listen_fd(sd_varlink_server *s, int fd); +int sd_varlink_server_listen_auto(sd_varlink_server *s); +int sd_varlink_server_add_connection(sd_varlink_server *s, int fd, sd_varlink **ret); +int sd_varlink_server_add_connection_pair(sd_varlink_server *s, int input_fd, int output_fd, const struct ucred *ucred_override, sd_varlink **ret); +int sd_varlink_server_add_connection_stdio(sd_varlink_server *s, sd_varlink **ret); + +/* Bind callbacks */ +int sd_varlink_server_bind_method(sd_varlink_server *s, const char *method, sd_varlink_method_t callback); +int sd_varlink_server_bind_method_many_internal(sd_varlink_server *s, ...); +#define sd_varlink_server_bind_method_many(s, ...) sd_varlink_server_bind_method_many_internal(s, __VA_ARGS__, NULL) +int sd_varlink_server_bind_connect(sd_varlink_server *s, sd_varlink_connect_t connect); +int sd_varlink_server_bind_disconnect(sd_varlink_server *s, sd_varlink_disconnect_t disconnect); + +/* Add interface definition */ +int sd_varlink_server_add_interface(sd_varlink_server *s, const sd_varlink_interface *interface); +int sd_varlink_server_add_interface_many_internal(sd_varlink_server *s, ...); +#define sd_varlink_server_add_interface_many(s, ...) sd_varlink_server_add_interface_many_internal(s, __VA_ARGS__, NULL) + +void* sd_varlink_server_set_userdata(sd_varlink_server *s, void *userdata); +void* sd_varlink_server_get_userdata(sd_varlink_server *s); + +int sd_varlink_server_attach_event(sd_varlink_server *v, sd_event *e, int64_t priority); +int sd_varlink_server_detach_event(sd_varlink_server *v); +sd_event *sd_varlink_server_get_event(sd_varlink_server *v); + +int sd_varlink_server_loop_auto(sd_varlink_server *server); + +int sd_varlink_server_shutdown(sd_varlink_server *server); + +int sd_varlink_server_set_exit_on_idle(sd_varlink_server *s, int b); + +unsigned sd_varlink_server_connections_max(sd_varlink_server *s); +unsigned sd_varlink_server_connections_per_uid_max(sd_varlink_server *s); + +int sd_varlink_server_set_connections_per_uid_max(sd_varlink_server *s, unsigned m); +int sd_varlink_server_set_connections_max(sd_varlink_server *s, unsigned m); + +unsigned sd_varlink_server_current_connections(sd_varlink_server *s); + +int sd_varlink_server_set_description(sd_varlink_server *s, const char *description); + +int sd_varlink_invocation(sd_varlink_invocation_flags_t flags); + +int sd_varlink_error_to_errno(const char *error, sd_json_variant *parameters); + +/* Define helpers so that __attribute__((cleanup(sd_varlink_unrefp))) and similar may be used. */ +_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_varlink, sd_varlink_unref); +_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_varlink, sd_varlink_close_unref); +_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_varlink, sd_varlink_flush_close_unref); +_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_varlink_server, sd_varlink_server_unref); + +/* These are local errors that never cross the wire, and are our own invention */ +#define SD_VARLINK_ERROR_DISCONNECTED "io.systemd.Disconnected" +#define SD_VARLINK_ERROR_TIMEOUT "io.systemd.TimedOut" +#define SD_VARLINK_ERROR_PROTOCOL "io.systemd.Protocol" + +/* This one we invented, and use for generically propagating system errors (errno) to clients */ +#define SD_VARLINK_ERROR_SYSTEM "io.systemd.System" + +/* This one we invented and is a weaker version of "org.varlink.service.PermissionDenied", and indicates that if user would allow interactive auth, we might allow access */ +#define SD_VARLINK_ERROR_INTERACTIVE_AUTHENTICATION_REQUIRED "io.systemd.InteractiveAuthenticationRequired" + +/* These are errors defined in the Varlink spec */ +#define SD_VARLINK_ERROR_INTERFACE_NOT_FOUND "org.varlink.service.InterfaceNotFound" +#define SD_VARLINK_ERROR_METHOD_NOT_FOUND "org.varlink.service.MethodNotFound" +#define SD_VARLINK_ERROR_METHOD_NOT_IMPLEMENTED "org.varlink.service.MethodNotImplemented" +#define SD_VARLINK_ERROR_INVALID_PARAMETER "org.varlink.service.InvalidParameter" +#define SD_VARLINK_ERROR_PERMISSION_DENIED "org.varlink.service.PermissionDenied" +#define SD_VARLINK_ERROR_EXPECTED_MORE "org.varlink.service.ExpectedMore" + +_SD_END_DECLARATIONS; + +#endif diff --git a/src/test/test-varlink-idl.c b/src/test/test-varlink-idl.c index c2d385eb56..4283ae7c01 100644 --- a/src/test/test-varlink-idl.c +++ b/src/test/test-varlink-idl.c @@ -2,11 +2,13 @@ #include <pthread.h> +#include "sd-varlink.h" +#include "sd-varlink-idl.h" + #include "fd-util.h" #include "pretty-print.h" #include "tests.h" -#include "varlink.h" -#include "varlink-idl.h" +#include "varlink-idl-util.h" #include "varlink-io.systemd.h" #include "varlink-io.systemd.BootControl.h" #include "varlink-io.systemd.Credentials.h" @@ -26,90 +28,90 @@ #include "varlink-io.systemd.sysext.h" #include "varlink-org.varlink.service.h" -static VARLINK_DEFINE_ENUM_TYPE( +static SD_VARLINK_DEFINE_ENUM_TYPE( EnumTest, - VARLINK_FIELD_COMMENT("piff paff"), - VARLINK_DEFINE_ENUM_VALUE(foo), - VARLINK_FIELD_COMMENT("waldo"), - VARLINK_DEFINE_ENUM_VALUE(bar), - VARLINK_FIELD_COMMENT("crux"), - VARLINK_DEFINE_ENUM_VALUE(baz)); - -static VARLINK_DEFINE_STRUCT_TYPE( + SD_VARLINK_FIELD_COMMENT("piff paff"), + SD_VARLINK_DEFINE_ENUM_VALUE(foo), + SD_VARLINK_FIELD_COMMENT("waldo"), + SD_VARLINK_DEFINE_ENUM_VALUE(bar), + SD_VARLINK_FIELD_COMMENT("crux"), + SD_VARLINK_DEFINE_ENUM_VALUE(baz)); + +static SD_VARLINK_DEFINE_STRUCT_TYPE( NestedStructTest, - VARLINK_FIELD_COMMENT("miepf"), - VARLINK_DEFINE_FIELD(x, VARLINK_INT, 0)); + SD_VARLINK_FIELD_COMMENT("miepf"), + SD_VARLINK_DEFINE_FIELD(x, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_STRUCT_TYPE( +static SD_VARLINK_DEFINE_STRUCT_TYPE( StructTest, - VARLINK_DEFINE_FIELD(bbb, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD(bbbn, VARLINK_BOOL, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(bbba, VARLINK_BOOL, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(bbbna, VARLINK_BOOL, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(bbbm, VARLINK_BOOL, VARLINK_MAP), - VARLINK_DEFINE_FIELD(bbbnm, VARLINK_BOOL, VARLINK_NULLABLE|VARLINK_MAP), - - VARLINK_FIELD_COMMENT("more from here"), - - VARLINK_DEFINE_FIELD(iii, VARLINK_INT, 0), - VARLINK_DEFINE_FIELD(iiin, VARLINK_INT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(iiia, VARLINK_INT, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(iiina, VARLINK_INT, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(iiim, VARLINK_INT, VARLINK_MAP), - VARLINK_DEFINE_FIELD(iiinm, VARLINK_INT, VARLINK_NULLABLE|VARLINK_MAP), - - VARLINK_DEFINE_FIELD(fff, VARLINK_FLOAT, 0), - VARLINK_DEFINE_FIELD(fffn, VARLINK_FLOAT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(fffa, VARLINK_FLOAT, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(fffna, VARLINK_FLOAT, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(fffm, VARLINK_FLOAT, VARLINK_MAP), - VARLINK_DEFINE_FIELD(fffnm, VARLINK_FLOAT, VARLINK_NULLABLE|VARLINK_MAP), - - VARLINK_DEFINE_FIELD(sss, VARLINK_STRING, 0), - VARLINK_DEFINE_FIELD(sssn, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(sssa, VARLINK_STRING, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(sssna, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(sssm, VARLINK_STRING, VARLINK_MAP), - VARLINK_DEFINE_FIELD(sssnm, VARLINK_STRING, VARLINK_NULLABLE|VARLINK_MAP), - - VARLINK_DEFINE_FIELD(ooo, VARLINK_OBJECT, 0), - VARLINK_DEFINE_FIELD(ooon, VARLINK_OBJECT, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD(oooa, VARLINK_OBJECT, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(ooona, VARLINK_OBJECT, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD(ooom, VARLINK_OBJECT, VARLINK_MAP), - VARLINK_DEFINE_FIELD(ooonm, VARLINK_OBJECT, VARLINK_NULLABLE|VARLINK_MAP), - - VARLINK_DEFINE_FIELD_BY_TYPE(eee, EnumTest, 0), - VARLINK_DEFINE_FIELD_BY_TYPE(eeen, EnumTest, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD_BY_TYPE(eeea, EnumTest, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD_BY_TYPE(eeena, EnumTest, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD_BY_TYPE(eeem, EnumTest, VARLINK_MAP), - VARLINK_DEFINE_FIELD_BY_TYPE(eeenm, EnumTest, VARLINK_NULLABLE|VARLINK_MAP), - - VARLINK_DEFINE_FIELD_BY_TYPE(nnn, NestedStructTest, 0), - VARLINK_DEFINE_FIELD_BY_TYPE(nnnn, NestedStructTest, VARLINK_NULLABLE), - VARLINK_DEFINE_FIELD_BY_TYPE(nnna, NestedStructTest, VARLINK_ARRAY), - VARLINK_DEFINE_FIELD_BY_TYPE(nnnna, NestedStructTest, VARLINK_NULLABLE|VARLINK_ARRAY), - VARLINK_DEFINE_FIELD_BY_TYPE(nnnm, NestedStructTest, VARLINK_MAP), - VARLINK_DEFINE_FIELD_BY_TYPE(nnnnm, NestedStructTest, VARLINK_NULLABLE|VARLINK_MAP)); - -static VARLINK_DEFINE_METHOD( + SD_VARLINK_DEFINE_FIELD(bbb, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD(bbbn, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(bbba, SD_VARLINK_BOOL, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(bbbna, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(bbbm, SD_VARLINK_BOOL, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD(bbbnm, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE|SD_VARLINK_MAP), + + SD_VARLINK_FIELD_COMMENT("more from here"), + + SD_VARLINK_DEFINE_FIELD(iii, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_FIELD(iiin, SD_VARLINK_INT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(iiia, SD_VARLINK_INT, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(iiina, SD_VARLINK_INT, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(iiim, SD_VARLINK_INT, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD(iiinm, SD_VARLINK_INT, SD_VARLINK_NULLABLE|SD_VARLINK_MAP), + + SD_VARLINK_DEFINE_FIELD(fff, SD_VARLINK_FLOAT, 0), + SD_VARLINK_DEFINE_FIELD(fffn, SD_VARLINK_FLOAT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(fffa, SD_VARLINK_FLOAT, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(fffna, SD_VARLINK_FLOAT, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(fffm, SD_VARLINK_FLOAT, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD(fffnm, SD_VARLINK_FLOAT, SD_VARLINK_NULLABLE|SD_VARLINK_MAP), + + SD_VARLINK_DEFINE_FIELD(sss, SD_VARLINK_STRING, 0), + SD_VARLINK_DEFINE_FIELD(sssn, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(sssa, SD_VARLINK_STRING, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(sssna, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(sssm, SD_VARLINK_STRING, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD(sssnm, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_MAP), + + SD_VARLINK_DEFINE_FIELD(ooo, SD_VARLINK_OBJECT, 0), + SD_VARLINK_DEFINE_FIELD(ooon, SD_VARLINK_OBJECT, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD(oooa, SD_VARLINK_OBJECT, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(ooona, SD_VARLINK_OBJECT, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD(ooom, SD_VARLINK_OBJECT, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD(ooonm, SD_VARLINK_OBJECT, SD_VARLINK_NULLABLE|SD_VARLINK_MAP), + + SD_VARLINK_DEFINE_FIELD_BY_TYPE(eee, EnumTest, 0), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(eeen, EnumTest, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(eeea, EnumTest, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(eeena, EnumTest, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(eeem, EnumTest, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(eeenm, EnumTest, SD_VARLINK_NULLABLE|SD_VARLINK_MAP), + + SD_VARLINK_DEFINE_FIELD_BY_TYPE(nnn, NestedStructTest, 0), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(nnnn, NestedStructTest, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(nnna, NestedStructTest, SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(nnnna, NestedStructTest, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(nnnm, NestedStructTest, SD_VARLINK_MAP), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(nnnnm, NestedStructTest, SD_VARLINK_NULLABLE|SD_VARLINK_MAP)); + +static SD_VARLINK_DEFINE_METHOD( MethodTest, - VARLINK_DEFINE_INPUT(x, VARLINK_BOOL, 0), - VARLINK_DEFINE_INPUT_BY_TYPE(y, EnumTest, 0), - VARLINK_DEFINE_INPUT_BY_TYPE(z, StructTest, 0), - VARLINK_DEFINE_OUTPUT(x, VARLINK_BOOL, 0), - VARLINK_DEFINE_OUTPUT_BY_TYPE(y, EnumTest, 0), - VARLINK_DEFINE_OUTPUT_BY_TYPE(z, StructTest, 0)); - -static VARLINK_DEFINE_ERROR( + SD_VARLINK_DEFINE_INPUT(x, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_INPUT_BY_TYPE(y, EnumTest, 0), + SD_VARLINK_DEFINE_INPUT_BY_TYPE(z, StructTest, 0), + SD_VARLINK_DEFINE_OUTPUT(x, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(y, EnumTest, 0), + SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(z, StructTest, 0)); + +static SD_VARLINK_DEFINE_ERROR( ErrorTest, - VARLINK_DEFINE_FIELD(x, VARLINK_BOOL, 0), - VARLINK_DEFINE_FIELD_BY_TYPE(y, EnumTest, 0), - VARLINK_DEFINE_FIELD_BY_TYPE(z, StructTest, 0)); + SD_VARLINK_DEFINE_FIELD(x, SD_VARLINK_BOOL, 0), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(y, EnumTest, 0), + SD_VARLINK_DEFINE_FIELD_BY_TYPE(z, StructTest, 0)); -static VARLINK_DEFINE_INTERFACE( +static SD_VARLINK_DEFINE_INTERFACE( xyz_test, "xyz.test", &vl_type_EnumTest, @@ -118,18 +120,18 @@ static VARLINK_DEFINE_INTERFACE( &vl_method_MethodTest, &vl_error_ErrorTest); -static void test_parse_format_one(const VarlinkInterface *iface) { - _cleanup_(varlink_interface_freep) VarlinkInterface *parsed = NULL; +static void test_parse_format_one(const sd_varlink_interface *iface) { + _cleanup_(varlink_interface_freep) sd_varlink_interface *parsed = NULL; _cleanup_free_ char *text = NULL, *text2 = NULL; assert_se(iface); - assert_se(varlink_idl_dump(stdout, /* use_colors=*/ true, /* cols= */ SIZE_MAX, iface) >= 0); + assert_se(sd_varlink_idl_dump(stdout, iface, SD_VARLINK_IDL_FORMAT_COLOR, /* cols= */ SIZE_MAX) >= 0); assert_se(varlink_idl_consistent(iface, LOG_ERR) >= 0); - assert_se(varlink_idl_format(iface, &text) >= 0); + assert_se(sd_varlink_idl_format(iface, &text) >= 0); assert_se(varlink_idl_parse(text, NULL, NULL, &parsed) >= 0); assert_se(varlink_idl_consistent(parsed, LOG_ERR) >= 0); - assert_se(varlink_idl_format(parsed, &text2) >= 0); + assert_se(sd_varlink_idl_format(parsed, &text2) >= 0); ASSERT_STREQ(text, text2); @@ -138,12 +140,12 @@ static void test_parse_format_one(const VarlinkInterface *iface) { parsed = varlink_interface_free(parsed); /* Do the same thing, but aggressively line break, and make sure this is roundtrippable as well */ - assert_se(varlink_idl_dump(stdout, /* use_colors=*/ true, 23, iface) >= 0); + assert_se(sd_varlink_idl_dump(stdout, iface, SD_VARLINK_IDL_FORMAT_COLOR, 23) >= 0); assert_se(varlink_idl_consistent(iface, LOG_ERR) >= 0); - assert_se(varlink_idl_format_full(iface, 23, &text) >= 0); + assert_se(sd_varlink_idl_format_full(iface, 0, 23, &text) >= 0); assert_se(varlink_idl_parse(text, NULL, NULL, &parsed) >= 0); assert_se(varlink_idl_consistent(parsed, LOG_ERR) >= 0); - assert_se(varlink_idl_format_full(parsed, 23, &text2) >= 0); + assert_se(sd_varlink_idl_format_full(parsed, 0, 23, &text2) >= 0); ASSERT_STREQ(text, text2); } @@ -189,7 +191,7 @@ TEST(parse_format) { } TEST(parse) { - _cleanup_(varlink_interface_freep) VarlinkInterface *parsed = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *parsed = NULL; /* This one has (nested) enonymous enums and structs */ static const char text[] = @@ -277,7 +279,7 @@ TEST(qualified_symbol_name_is_valid) { TEST(validate_json) { - _cleanup_(varlink_interface_freep) VarlinkInterface *parsed = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *parsed = NULL; /* This one has (nested) enonymous enums and structs */ static const char text[] = @@ -301,13 +303,13 @@ TEST(validate_json) { sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO, stdout, NULL); - const VarlinkSymbol* symbol = ASSERT_PTR(varlink_idl_find_symbol(parsed, VARLINK_METHOD, "Mymethod")); + const sd_varlink_symbol* symbol = ASSERT_PTR(varlink_idl_find_symbol(parsed, SD_VARLINK_METHOD, "Mymethod")); assert_se(varlink_idl_validate_method_call(symbol, v, NULL) >= 0); } static int test_recursive_one(unsigned depth) { - _cleanup_(varlink_interface_freep) VarlinkInterface *parsed = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *parsed = NULL; _cleanup_free_ char *pre = NULL, *post = NULL, *text = NULL; static const char header[] = "interface recursive.test\n" @@ -335,31 +337,31 @@ TEST(recursive) { assert_se(test_recursive_one(20000) < 0 ); } -static int test_method(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int test_method(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { sd_json_variant *foo = sd_json_variant_by_key(parameters, "foo"), *bar = sd_json_variant_by_key(parameters, "bar"); - return varlink_replyb(link, + return sd_varlink_replyb(link, SD_JSON_BUILD_OBJECT( SD_JSON_BUILD_PAIR_UNSIGNED("waldo", sd_json_variant_unsigned(foo) * sd_json_variant_unsigned(bar)), SD_JSON_BUILD_PAIR_UNSIGNED("quux", sd_json_variant_unsigned(foo) + sd_json_variant_unsigned(bar)))); } -static int done_method(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { - assert_se(sd_event_exit(varlink_get_event(link), 0) >= 0); +static int done_method(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { + assert_se(sd_event_exit(sd_varlink_get_event(link), 0) >= 0); return 0; } -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( TestMethod, - VARLINK_DEFINE_INPUT(foo, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(bar, VARLINK_INT, 0), - VARLINK_DEFINE_INPUT(optional, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_OUTPUT(waldo, VARLINK_INT, 0), - VARLINK_DEFINE_OUTPUT(quux, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(foo, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(bar, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_INPUT(optional, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_DEFINE_OUTPUT(waldo, SD_VARLINK_INT, 0), + SD_VARLINK_DEFINE_OUTPUT(quux, SD_VARLINK_INT, 0)); -static VARLINK_DEFINE_METHOD(Done); +static SD_VARLINK_DEFINE_METHOD(Done); -static VARLINK_DEFINE_INTERFACE( +static SD_VARLINK_DEFINE_INTERFACE( xyz, "xyz", &vl_method_TestMethod, @@ -367,18 +369,18 @@ static VARLINK_DEFINE_INTERFACE( static void* server_thread(void *userdata) { - _cleanup_(varlink_server_unrefp) VarlinkServer *server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *server = NULL; _cleanup_(sd_event_unrefp) sd_event *event = NULL; - assert_se(varlink_server_new(&server, 0) >= 0); - assert_se(varlink_server_add_interface(server, &vl_interface_xyz) >= 0); - assert_se(varlink_server_bind_method(server, "xyz.TestMethod", test_method) >= 0); - assert_se(varlink_server_bind_method(server, "xyz.Done", done_method) >= 0); + assert_se(sd_varlink_server_new(&server, 0) >= 0); + assert_se(sd_varlink_server_add_interface(server, &vl_interface_xyz) >= 0); + assert_se(sd_varlink_server_bind_method(server, "xyz.TestMethod", test_method) >= 0); + assert_se(sd_varlink_server_bind_method(server, "xyz.Done", done_method) >= 0); assert_se(sd_event_new(&event) >= 0); - assert_se(varlink_server_attach_event(server, event, 0) >= 0); + assert_se(sd_varlink_server_attach_event(server, event, 0) >= 0); - assert_se(varlink_server_add_connection(server, PTR_TO_FD(userdata), NULL) >= 0); + assert_se(sd_varlink_server_add_connection(server, PTR_TO_FD(userdata), NULL) >= 0); assert_se(sd_event_loop(event) >= 0); return NULL; @@ -386,16 +388,16 @@ static void* server_thread(void *userdata) { TEST(validate_method_call) { _cleanup_close_pair_ int fd[2] = EBADF_PAIR; - _cleanup_(varlink_unrefp) Varlink *v = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *v = NULL; pthread_t t; assert_se(socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0, fd) >= 0); assert_se(pthread_create(&t, NULL, server_thread, FD_TO_PTR(TAKE_FD(fd[1]))) == 0); - assert_se(varlink_connect_fd(&v, TAKE_FD(fd[0])) >= 0); + assert_se(sd_varlink_connect_fd(&v, TAKE_FD(fd[0])) >= 0); sd_json_variant *reply = NULL; const char *error_id = NULL; - assert_se(varlink_callb(v, "xyz.TestMethod", &reply, &error_id, + assert_se(sd_varlink_callb(v, "xyz.TestMethod", &reply, &error_id, SD_JSON_BUILD_OBJECT( SD_JSON_BUILD_PAIR_UNSIGNED("foo", 8), SD_JSON_BUILD_PAIR_UNSIGNED("bar", 9))) >= 0); @@ -412,7 +414,7 @@ TEST(validate_method_call) { sd_json_variant_dump(expected_reply, SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL); assert_se(sd_json_variant_equal(reply, expected_reply)); - assert_se(varlink_callb(v, "xyz.TestMethod", &reply, &error_id, + assert_se(sd_varlink_callb(v, "xyz.TestMethod", &reply, &error_id, SD_JSON_BUILD_OBJECT( SD_JSON_BUILD_PAIR_UNSIGNED("foo", 9), SD_JSON_BUILD_PAIR_UNSIGNED("bar", 8), @@ -421,21 +423,21 @@ TEST(validate_method_call) { assert_se(!error_id); assert_se(sd_json_variant_equal(reply, expected_reply)); - assert_se(varlink_callb(v, "xyz.TestMethod", &reply, &error_id, + assert_se(sd_varlink_callb(v, "xyz.TestMethod", &reply, &error_id, SD_JSON_BUILD_OBJECT( SD_JSON_BUILD_PAIR_UNSIGNED("foo", 8), SD_JSON_BUILD_PAIR_UNSIGNED("bar", 9), SD_JSON_BUILD_PAIR_STRING("zzz", "pfft"))) >= 0); - ASSERT_STREQ(error_id, VARLINK_ERROR_INVALID_PARAMETER); + ASSERT_STREQ(error_id, SD_VARLINK_ERROR_INVALID_PARAMETER); - assert_se(varlink_callb(v, "xyz.TestMethod", &reply, &error_id, + assert_se(sd_varlink_callb(v, "xyz.TestMethod", &reply, &error_id, SD_JSON_BUILD_OBJECT( SD_JSON_BUILD_PAIR_BOOLEAN("foo", true), SD_JSON_BUILD_PAIR_UNSIGNED("bar", 9))) >= 0); - ASSERT_STREQ(error_id, VARLINK_ERROR_INVALID_PARAMETER); + ASSERT_STREQ(error_id, SD_VARLINK_ERROR_INVALID_PARAMETER); - assert_se(varlink_send(v, "xyz.Done", NULL) >= 0); - assert_se(varlink_flush(v) >= 0); + assert_se(sd_varlink_send(v, "xyz.Done", NULL) >= 0); + assert_se(sd_varlink_flush(v) >= 0); assert_se(pthread_join(t, NULL) == 0); } diff --git a/src/test/test-varlink.c b/src/test/test-varlink.c index 48fc4a7e7f..a80344bcd1 100644 --- a/src/test/test-varlink.c +++ b/src/test/test-varlink.c @@ -6,6 +6,7 @@ #include "sd-event.h" #include "sd-json.h" +#include "sd-varlink.h" #include "data-fd-util.h" #include "fd-util.h" @@ -15,7 +16,6 @@ #include "tests.h" #include "tmpfile-util.h" #include "user-util.h" -#include "varlink.h" /* Let's pick some high value, that is higher than the largest listen() backlog, but leaves enough room below the typical RLIMIT_NOFILE value of 1024 so that we can process both sides of each socket in our @@ -26,7 +26,7 @@ static int n_done = 0; static int block_write_fd = -EBADF; -static int method_something(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int method_something(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *ret = NULL; sd_json_variant *a, *b; int64_t x, y; @@ -34,13 +34,13 @@ static int method_something(Varlink *link, sd_json_variant *parameters, VarlinkM a = sd_json_variant_by_key(parameters, "a"); if (!a) - return varlink_error(link, "io.test.BadParameters", NULL); + return sd_varlink_error(link, "io.test.BadParameters", NULL); x = sd_json_variant_integer(a); b = sd_json_variant_by_key(parameters, "b"); if (!b) - return varlink_error(link, "io.test.BadParameters", NULL); + return sd_varlink_error(link, "io.test.BadParameters", NULL); y = sd_json_variant_integer(b); @@ -48,10 +48,10 @@ static int method_something(Varlink *link, sd_json_variant *parameters, VarlinkM if (r < 0) return r; - return varlink_reply(link, ret); + return sd_varlink_reply(link, ret); } -static int method_something_more(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int method_something_more(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *ret = NULL; int r; @@ -67,7 +67,7 @@ static int method_something_more(Varlink *link, sd_json_variant *parameters, Var }; struct Something s = {}; - r = varlink_dispatch(link, parameters, dispatch_table, &s); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &s); if (r != 0) return r; @@ -78,7 +78,7 @@ static int method_something_more(Varlink *link, sd_json_variant *parameters, Var if (r < 0) return r; - r = varlink_notify(link, w); + r = sd_varlink_notify(link, w); if (r < 0) return r; } @@ -87,7 +87,7 @@ static int method_something_more(Varlink *link, sd_json_variant *parameters, Var if (r < 0) return r; - return varlink_reply(link, ret); + return sd_varlink_reply(link, ret); } static void test_fd(int fd, const void *buf, size_t n) { @@ -99,20 +99,20 @@ static void test_fd(int fd, const void *buf, size_t n) { assert_se(memcmp_nn(buf, n, rbuf, m) == 0); } -static int method_passfd(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int method_passfd(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *ret = NULL; sd_json_variant *a; int r; a = sd_json_variant_by_key(parameters, "fd"); if (!a) - return varlink_error(link, "io.test.BadParameters", NULL); + return sd_varlink_error(link, "io.test.BadParameters", NULL); ASSERT_STREQ(sd_json_variant_string(a), "whoop"); - int xx = varlink_peek_fd(link, 0), - yy = varlink_peek_fd(link, 1), - zz = varlink_peek_fd(link, 2); + int xx = sd_varlink_peek_fd(link, 0), + yy = sd_varlink_peek_fd(link, 1), + zz = sd_varlink_peek_fd(link, 2); log_info("%i %i %i", xx, yy, zz); @@ -134,24 +134,24 @@ static int method_passfd(Varlink *link, sd_json_variant *parameters, VarlinkMeth if (r < 0) return r; - assert_se(varlink_push_fd(link, vv) == 0); - assert_se(varlink_push_fd(link, ww) == 1); + assert_se(sd_varlink_push_fd(link, vv) == 0); + assert_se(sd_varlink_push_fd(link, ww) == 1); TAKE_FD(vv); TAKE_FD(ww); - return varlink_reply(link, ret); + return sd_varlink_reply(link, ret); } -static int method_done(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int method_done(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { if (++n_done == 2) - sd_event_exit(varlink_get_event(link), EXIT_FAILURE); + sd_event_exit(sd_varlink_get_event(link), EXIT_FAILURE); return 0; } -static int reply(Varlink *link, sd_json_variant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) { +static int reply(sd_varlink *link, sd_json_variant *parameters, const char *error_id, sd_varlink_reply_flags_t flags, void *userdata) { sd_json_variant *sum; sum = sd_json_variant_by_key(parameters, "sum"); @@ -159,41 +159,41 @@ static int reply(Varlink *link, sd_json_variant *parameters, const char *error_i assert_se(sd_json_variant_integer(sum) == 7+22); if (++n_done == 2) - sd_event_exit(varlink_get_event(link), EXIT_FAILURE); + sd_event_exit(sd_varlink_get_event(link), EXIT_FAILURE); return 0; } -static int on_connect(VarlinkServer *s, Varlink *link, void *userdata) { +static int on_connect(sd_varlink_server *s, sd_varlink *link, void *userdata) { uid_t uid = UID_INVALID; assert_se(s); assert_se(link); - assert_se(varlink_get_peer_uid(link, &uid) >= 0); + assert_se(sd_varlink_get_peer_uid(link, &uid) >= 0); assert_se(getuid() == uid); - assert_se(varlink_set_allow_fd_passing_input(link, true) >= 0); - assert_se(varlink_set_allow_fd_passing_output(link, true) >= 0); + assert_se(sd_varlink_set_allow_fd_passing_input(link, true) >= 0); + assert_se(sd_varlink_set_allow_fd_passing_output(link, true) >= 0); return 0; } -static int overload_reply(Varlink *link, sd_json_variant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) { +static int overload_reply(sd_varlink *link, sd_json_variant *parameters, const char *error_id, sd_varlink_reply_flags_t flags, void *userdata) { /* This method call reply should always be called with a disconnection, since the method call should * be talking to an overloaded server */ log_debug("Over reply triggered with error: %s", strna(error_id)); - ASSERT_STREQ(error_id, VARLINK_ERROR_DISCONNECTED); - sd_event_exit(varlink_get_event(link), 0); + ASSERT_STREQ(error_id, SD_VARLINK_ERROR_DISCONNECTED); + sd_event_exit(sd_varlink_get_event(link), 0); return 0; } static void flood_test(const char *address) { - _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *c = NULL; _cleanup_(sd_event_unrefp) sd_event *e = NULL; - _cleanup_free_ Varlink **connections = NULL; + _cleanup_free_ sd_varlink **connections = NULL; size_t k; char x = 'x'; @@ -205,25 +205,25 @@ static void flood_test(const char *address) { assert_se(sd_event_default(&e) >= 0); /* Flood the server with connections */ - assert_se(connections = new0(Varlink*, OVERLOAD_CONNECTIONS)); + assert_se(connections = new0(sd_varlink*, OVERLOAD_CONNECTIONS)); for (k = 0; k < OVERLOAD_CONNECTIONS; k++) { _cleanup_free_ char *t = NULL; log_debug("connection %zu", k); - assert_se(varlink_connect_address(connections + k, address) >= 0); + assert_se(sd_varlink_connect_address(connections + k, address) >= 0); assert_se(asprintf(&t, "flood-%zu", k) >= 0); - assert_se(varlink_set_description(connections[k], t) >= 0); - assert_se(varlink_attach_event(connections[k], e, k) >= 0); - assert_se(varlink_sendb(connections[k], "io.test.Rubbish", SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("id", SD_JSON_BUILD_INTEGER(k)))) >= 0); + assert_se(sd_varlink_set_description(connections[k], t) >= 0); + assert_se(sd_varlink_attach_event(connections[k], e, k) >= 0); + assert_se(sd_varlink_sendb(connections[k], "io.test.Rubbish", SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("id", SD_JSON_BUILD_INTEGER(k)))) >= 0); } /* Then, create one more, which should fail */ log_debug("Creating overload connection..."); - assert_se(varlink_connect_address(&c, address) >= 0); - assert_se(varlink_set_description(c, "overload-client") >= 0); - assert_se(varlink_attach_event(c, e, k) >= 0); - assert_se(varlink_bind_reply(c, overload_reply) >= 0); - assert_se(varlink_invokeb(c, "io.test.Overload", SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("foo", JSON_BUILD_CONST_STRING("bar")))) >= 0); + assert_se(sd_varlink_connect_address(&c, address) >= 0); + assert_se(sd_varlink_set_description(c, "overload-client") >= 0); + assert_se(sd_varlink_attach_event(c, e, k) >= 0); + assert_se(sd_varlink_bind_reply(c, overload_reply) >= 0); + assert_se(sd_varlink_invokeb(c, "io.test.Overload", SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("foo", JSON_BUILD_CONST_STRING("bar")))) >= 0); /* Unblock it */ log_debug("Unblocking server..."); @@ -234,11 +234,11 @@ static void flood_test(const char *address) { /* And close all connections again */ for (k = 0; k < OVERLOAD_CONNECTIONS; k++) - connections[k] = varlink_unref(connections[k]); + connections[k] = sd_varlink_unref(connections[k]); } static void *thread(void *arg) { - _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *c = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *i = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *wrong = NULL; sd_json_variant *o = NULL, *k = NULL, *j = NULL; @@ -249,19 +249,19 @@ static void *thread(void *arg) { assert_se(sd_json_build(&i, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("a", SD_JSON_BUILD_INTEGER(88)), SD_JSON_BUILD_PAIR("b", SD_JSON_BUILD_INTEGER(99)))) >= 0); - assert_se(varlink_connect_address(&c, arg) >= 0); - assert_se(varlink_set_description(c, "thread-client") >= 0); - assert_se(varlink_set_allow_fd_passing_input(c, true) >= 0); - assert_se(varlink_set_allow_fd_passing_output(c, true) >= 0); + assert_se(sd_varlink_connect_address(&c, arg) >= 0); + assert_se(sd_varlink_set_description(c, "thread-client") >= 0); + assert_se(sd_varlink_set_allow_fd_passing_input(c, true) >= 0); + assert_se(sd_varlink_set_allow_fd_passing_output(c, true) >= 0); - /* Test that client is able to perform two sequential varlink_collect calls if first resulted in an error */ + /* Test that client is able to perform two sequential sd_varlink_collect calls if first resulted in an error */ assert_se(sd_json_build(&wrong, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("a", SD_JSON_BUILD_INTEGER(88)), SD_JSON_BUILD_PAIR("c", SD_JSON_BUILD_INTEGER(99)))) >= 0); - assert_se(varlink_collect(c, "io.test.DoSomethingMore", wrong, &j, &error_id) >= 0); + assert_se(sd_varlink_collect(c, "io.test.DoSomethingMore", wrong, &j, &error_id) >= 0); assert_se(strcmp_ptr(error_id, "org.varlink.service.InvalidParameter") == 0); - assert_se(varlink_collect(c, "io.test.DoSomethingMore", i, &j, &error_id) >= 0); + assert_se(sd_varlink_collect(c, "io.test.DoSomethingMore", i, &j, &error_id) >= 0); assert_se(!error_id); assert_se(sd_json_variant_is_array(j) && !sd_json_variant_is_blank_array(j)); @@ -272,7 +272,7 @@ static void *thread(void *arg) { } assert_se(x == 6); - assert_se(varlink_call(c, "io.test.DoSomething", i, &o, &e) >= 0); + assert_se(sd_varlink_call(c, "io.test.DoSomething", i, &o, &e) >= 0); assert_se(sd_json_variant_integer(sd_json_variant_by_key(o, "sum")) == 88 + 99); assert_se(!e); @@ -284,14 +284,14 @@ static void *thread(void *arg) { assert_se(fd2 >= 0); assert_se(fd3 >= 0); - assert_se(varlink_push_fd(c, fd1) == 0); - assert_se(varlink_push_fd(c, fd2) == 1); - assert_se(varlink_push_fd(c, fd3) == 2); + assert_se(sd_varlink_push_fd(c, fd1) == 0); + assert_se(sd_varlink_push_fd(c, fd2) == 1); + assert_se(sd_varlink_push_fd(c, fd3) == 2); - assert_se(varlink_callb(c, "io.test.PassFD", &o, &e, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("fd", SD_JSON_BUILD_STRING("whoop")))) >= 0); + assert_se(sd_varlink_callb(c, "io.test.PassFD", &o, &e, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("fd", SD_JSON_BUILD_STRING("whoop")))) >= 0); - int fd4 = varlink_peek_fd(c, 0); - int fd5 = varlink_peek_fd(c, 1); + int fd4 = sd_varlink_peek_fd(c, 0); + int fd5 = sd_varlink_peek_fd(c, 1); assert_se(fd4 >= 0); assert_se(fd5 >= 0); @@ -299,13 +299,13 @@ static void *thread(void *arg) { test_fd(fd4, "miau", 4); test_fd(fd5, "wuff", 4); - assert_se(varlink_callb(c, "io.test.IDontExist", &o, &e, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("x", SD_JSON_BUILD_REAL(5.5)))) >= 0); + assert_se(sd_varlink_callb(c, "io.test.IDontExist", &o, &e, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("x", SD_JSON_BUILD_REAL(5.5)))) >= 0); ASSERT_STREQ(sd_json_variant_string(sd_json_variant_by_key(o, "method")), "io.test.IDontExist"); - ASSERT_STREQ(e, VARLINK_ERROR_METHOD_NOT_FOUND); + ASSERT_STREQ(e, SD_VARLINK_ERROR_METHOD_NOT_FOUND); flood_test(arg); - assert_se(varlink_send(c, "io.test.Done", NULL) >= 0); + assert_se(sd_varlink_send(c, "io.test.Done", NULL) >= 0); return NULL; } @@ -329,8 +329,8 @@ static int block_fd_handler(sd_event_source *s, int fd, uint32_t revents, void * int main(int argc, char *argv[]) { _cleanup_(sd_event_source_unrefp) sd_event_source *block_event = NULL; - _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; - _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *s = NULL; + _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *c = NULL; _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_(sd_event_unrefp) sd_event *e = NULL; @@ -350,28 +350,28 @@ int main(int argc, char *argv[]) { assert_se(sd_event_source_set_priority(block_event, SD_EVENT_PRIORITY_IMPORTANT) >= 0); block_write_fd = TAKE_FD(block_fds[1]); - assert_se(varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID) >= 0); - assert_se(varlink_server_set_description(s, "our-server") >= 0); + assert_se(sd_varlink_server_new(&s, SD_VARLINK_SERVER_ACCOUNT_UID) >= 0); + assert_se(sd_varlink_server_set_description(s, "our-server") >= 0); - assert_se(varlink_server_bind_method(s, "io.test.PassFD", method_passfd) >= 0); - assert_se(varlink_server_bind_method(s, "io.test.DoSomething", method_something) >= 0); - assert_se(varlink_server_bind_method(s, "io.test.DoSomethingMore", method_something_more) >= 0); - assert_se(varlink_server_bind_method(s, "io.test.Done", method_done) >= 0); - assert_se(varlink_server_bind_connect(s, on_connect) >= 0); - assert_se(varlink_server_listen_address(s, sp, 0600) >= 0); - assert_se(varlink_server_attach_event(s, e, 0) >= 0); - assert_se(varlink_server_set_connections_max(s, OVERLOAD_CONNECTIONS) >= 0); + assert_se(sd_varlink_server_bind_method(s, "io.test.PassFD", method_passfd) >= 0); + assert_se(sd_varlink_server_bind_method(s, "io.test.DoSomething", method_something) >= 0); + assert_se(sd_varlink_server_bind_method(s, "io.test.DoSomethingMore", method_something_more) >= 0); + assert_se(sd_varlink_server_bind_method(s, "io.test.Done", method_done) >= 0); + assert_se(sd_varlink_server_bind_connect(s, on_connect) >= 0); + assert_se(sd_varlink_server_listen_address(s, sp, 0600) >= 0); + assert_se(sd_varlink_server_attach_event(s, e, 0) >= 0); + assert_se(sd_varlink_server_set_connections_max(s, OVERLOAD_CONNECTIONS) >= 0); assert_se(sd_json_build(&v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("a", SD_JSON_BUILD_INTEGER(7)), SD_JSON_BUILD_PAIR("b", SD_JSON_BUILD_INTEGER(22)))) >= 0); - assert_se(varlink_connect_address(&c, sp) >= 0); - assert_se(varlink_set_description(c, "main-client") >= 0); - assert_se(varlink_bind_reply(c, reply) >= 0); + assert_se(sd_varlink_connect_address(&c, sp) >= 0); + assert_se(sd_varlink_set_description(c, "main-client") >= 0); + assert_se(sd_varlink_bind_reply(c, reply) >= 0); - assert_se(varlink_invoke(c, "io.test.DoSomething", v) >= 0); + assert_se(sd_varlink_invoke(c, "io.test.DoSomething", v) >= 0); - assert_se(varlink_attach_event(c, e, 0) >= 0); + assert_se(sd_varlink_attach_event(c, e, 0) >= 0); assert_se(pthread_create(&t, NULL, thread, (void*) sp) == 0); diff --git a/src/userdb/userwork.c b/src/userdb/userwork.c index 8257acc473..5781d8c788 100644 --- a/src/userdb/userwork.c +++ b/src/userdb/userwork.c @@ -4,6 +4,7 @@ #include <sys/wait.h> #include "sd-daemon.h" +#include "sd-varlink.h" #include "env-util.h" #include "fd-util.h" @@ -17,7 +18,6 @@ #include "user-record.h" #include "user-util.h" #include "userdb.h" -#include "varlink.h" #include "varlink-io.systemd.UserDatabase.h" #define ITERATIONS_MAX 64U @@ -70,7 +70,7 @@ static int add_nss_service(sd_json_variant **v) { return sd_json_variant_set_field(v, "status", status); } -static int build_user_json(Varlink *link, UserRecord *ur, sd_json_variant **ret) { +static int build_user_json(sd_varlink *link, UserRecord *ur, sd_json_variant **ret) { _cleanup_(user_record_unrefp) UserRecord *stripped = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; UserRecordLoadFlags flags; @@ -81,7 +81,7 @@ static int build_user_json(Varlink *link, UserRecord *ur, sd_json_variant **ret) assert(ur); assert(ret); - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) { log_debug_errno(r, "Unable to query peer UID, ignoring: %m"); trusted = false; @@ -114,7 +114,7 @@ static int build_user_json(Varlink *link, UserRecord *ur, sd_json_variant **ret) SD_JSON_BUILD_PAIR("incomplete", SD_JSON_BUILD_BOOLEAN(stripped->incomplete))); } -static int userdb_flags_from_service(Varlink *link, const char *service, UserDBFlags *ret) { +static int userdb_flags_from_service(sd_varlink *link, const char *service, UserDBFlags *ret) { assert(link); assert(ret); @@ -125,12 +125,12 @@ static int userdb_flags_from_service(Varlink *link, const char *service, UserDBF else if (streq_ptr(service, "io.systemd.Multiplexer")) *ret = USERDB_AVOID_MULTIPLEXER; else - return varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.BadService", NULL); return 0; } -static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, @@ -149,7 +149,7 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -174,7 +174,7 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, * implementation detail and always return NoRecordFound in this case, since from a * client's perspective it's irrelevant if there was no entry at all or just not on * the service that the query was limited to. */ - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -188,7 +188,7 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, return r; if (last) { - r = varlink_notify(link, last); + r = sd_varlink_notify(link, last); if (r < 0) return r; @@ -201,29 +201,29 @@ static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, } if (!last) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_reply(link, last); + return sd_varlink_reply(link, last); } if (r == -ESRCH) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) { log_debug_errno(r, "User lookup failed abnormally: %m"); - return varlink_error(link, "io.systemd.UserDatabase.ServiceNotAvailable", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ServiceNotAvailable", NULL); } if ((uid_is_valid(p.uid) && hr->uid != p.uid) || (p.user_name && !streq(hr->user_name, p.user_name))) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_user_json(link, hr, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } -static int build_group_json(Varlink *link, GroupRecord *gr, sd_json_variant **ret) { +static int build_group_json(sd_varlink *link, GroupRecord *gr, sd_json_variant **ret) { _cleanup_(group_record_unrefp) GroupRecord *stripped = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; UserRecordLoadFlags flags; @@ -234,7 +234,7 @@ static int build_group_json(Varlink *link, GroupRecord *gr, sd_json_variant **re assert(gr); assert(ret); - r = varlink_get_peer_uid(link, &peer_uid); + r = sd_varlink_get_peer_uid(link, &peer_uid); if (r < 0) { log_debug_errno(r, "Unable to query peer UID, ignoring: %m"); trusted = false; @@ -267,7 +267,7 @@ static int build_group_json(Varlink *link, GroupRecord *gr, sd_json_variant **re SD_JSON_BUILD_PAIR("incomplete", SD_JSON_BUILD_BOOLEAN(stripped->incomplete))); } -static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, @@ -286,7 +286,7 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -304,7 +304,7 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters r = groupdb_all(userdb_flags, &iterator); if (IN_SET(r, -ESRCH, -ENOLINK)) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -318,7 +318,7 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters return r; if (last) { - r = varlink_notify(link, last); + r = sd_varlink_notify(link, last); if (r < 0) return r; @@ -331,29 +331,29 @@ static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters } if (!last) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); - return varlink_reply(link, last); + return sd_varlink_reply(link, last); } if (r == -ESRCH) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) { log_debug_errno(r, "Group lookup failed abnormally: %m"); - return varlink_error(link, "io.systemd.UserDatabase.ServiceNotAvailable", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ServiceNotAvailable", NULL); } if ((uid_is_valid(p.gid) && g->gid != p.gid) || (p.group_name && !streq(g->group_name, p.group_name))) - return varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.ConflictingRecordFound", NULL); r = build_group_json(link, g, &v); if (r < 0) return r; - return varlink_reply(link, v); + return sd_varlink_reply(link, v); } -static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_memberships(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), 0 }, { "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), 0 }, @@ -369,7 +369,7 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, assert(parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &p); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); if (r != 0) return r; @@ -384,7 +384,7 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, else r = membershipdb_all(userdb_flags, &iterator); if (IN_SET(r, -ESRCH, -ENOLINK)) - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); if (r < 0) return r; @@ -404,7 +404,7 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, if (last_user_name) { assert(last_group_name); - r = varlink_notifybo( + r = sd_varlink_notifybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last_user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last_group_name))); @@ -418,31 +418,34 @@ static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, if (!last_user_name) { assert(!last_group_name); - return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); + return sd_varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL); } assert(last_group_name); - return varlink_replybo( + return sd_varlink_replybo( link, SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last_user_name)), SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last_group_name))); } -static int process_connection(VarlinkServer *server, int _fd) { +static int process_connection(sd_varlink_server *server, int _fd) { _cleanup_close_ int fd = TAKE_FD(_fd); /* always take possession */ - _cleanup_(varlink_close_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_close_unrefp) sd_varlink *vl = NULL; int r; - r = varlink_server_add_connection(server, fd, &vl); + assert(server); + assert(fd >= 0); + + r = sd_varlink_server_add_connection(server, fd, &vl); if (r < 0) return log_error_errno(r, "Failed to add connection: %m"); TAKE_FD(fd); - vl = varlink_ref(vl); + vl = sd_varlink_ref(vl); for (;;) { - r = varlink_process(vl); + r = sd_varlink_process(vl); if (r == -ENOTCONN) { log_debug("Connection terminated."); break; @@ -452,7 +455,7 @@ static int process_connection(VarlinkServer *server, int _fd) { if (r > 0) continue; - r = varlink_wait(vl, CONNECTION_IDLE_USEC); + r = sd_varlink_wait(vl, CONNECTION_IDLE_USEC); if (r < 0) return log_error_errno(r, "Failed to wait for connection events: %m"); if (r == 0) @@ -464,7 +467,7 @@ static int process_connection(VarlinkServer *server, int _fd) { static int run(int argc, char *argv[]) { usec_t start_time, listen_idle_usec, last_busy_usec = USEC_INFINITY; - _cleanup_(varlink_server_unrefp) VarlinkServer *server = NULL; + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *server = NULL; _cleanup_(pidref_done) PidRef parent = PIDREF_NULL; unsigned n_iterations = 0; int m, listen_fd, r; @@ -485,15 +488,15 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to turn off non-blocking mode for listening socket: %m"); - r = varlink_server_new(&server, 0); + r = sd_varlink_server_new(&server, 0); if (r < 0) return log_error_errno(r, "Failed to allocate server: %m"); - r = varlink_server_add_interface(server, &vl_interface_io_systemd_UserDatabase); + r = sd_varlink_server_add_interface(server, &vl_interface_io_systemd_UserDatabase); if (r < 0) return log_error_errno(r, "Failed to add UserDatabase interface to varlink server: %m"); - r = varlink_server_bind_method_many( + r = sd_varlink_server_bind_method_many( server, "io.systemd.UserDatabase.GetUserRecord", vl_method_get_user_record, "io.systemd.UserDatabase.GetGroupRecord", vl_method_get_group_record, diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index f4e5cc2cbf..aae6032da5 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -2,6 +2,8 @@ #include <getopt.h> +#include "sd-varlink.h" + #include "build.h" #include "fd-util.h" #include "fileio.h" @@ -13,13 +15,14 @@ #include "path-util.h" #include "pretty-print.h" #include "terminal-util.h" -#include "varlink.h" +#include "varlink-idl-util.h" +#include "varlink-util.h" #include "verbs.h" #include "version.h" static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF; static PagerFlags arg_pager_flags = 0; -static VarlinkMethodFlags arg_method_flags = 0; +static sd_varlink_method_flags_t arg_method_flags = 0; static bool arg_collect = false; static bool arg_quiet = false; static char **arg_graceful = NULL; @@ -122,11 +125,11 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_MORE: - arg_method_flags = (arg_method_flags & ~VARLINK_METHOD_ONEWAY) | VARLINK_METHOD_MORE; + arg_method_flags = (arg_method_flags & ~SD_VARLINK_METHOD_ONEWAY) | SD_VARLINK_METHOD_MORE; break; case ARG_ONEWAY: - arg_method_flags = (arg_method_flags & ~VARLINK_METHOD_MORE) | VARLINK_METHOD_ONEWAY; + arg_method_flags = (arg_method_flags & ~SD_VARLINK_METHOD_MORE) | SD_VARLINK_METHOD_ONEWAY; break; case ARG_COLLECT: @@ -168,7 +171,7 @@ static int parse_argv(int argc, char *argv[]) { } /* If more than one reply is expected, imply JSON-SEQ output */ - if (FLAGS_SET(arg_method_flags, VARLINK_METHOD_MORE)) + if (FLAGS_SET(arg_method_flags, SD_VARLINK_METHOD_MORE)) arg_json_format_flags |= SD_JSON_FORMAT_SEQ; strv_sort_uniq(arg_graceful); @@ -176,7 +179,7 @@ static int parse_argv(int argc, char *argv[]) { return 1; } -static int varlink_connect_auto(Varlink **ret, const char *where) { +static int varlink_connect_auto(sd_varlink **ret, const char *where) { int r; assert(ret); @@ -195,7 +198,7 @@ static int varlink_connect_auto(Varlink **ret, const char *where) { /* Is this a socket in the fs? Then connect() to it. */ if (S_ISSOCK(st.st_mode)) { - r = varlink_connect_address(ret, FORMAT_PROC_FD_PATH(fd)); + r = sd_varlink_connect_address(ret, FORMAT_PROC_FD_PATH(fd)); if (r < 0) return log_error_errno(r, "Failed to connect to '%s': %m", where); @@ -204,7 +207,7 @@ static int varlink_connect_auto(Varlink **ret, const char *where) { /* Is this an executable binary? Then fork it off. */ if (S_ISREG(st.st_mode) && (st.st_mode & 0111)) { - r = varlink_connect_exec(ret, where, STRV_MAKE(where)); /* Ideally we'd use FORMAT_PROC_FD_PATH(fd) here too, but that breaks the #! logic */ + r = sd_varlink_connect_exec(ret, where, STRV_MAKE(where)); /* Ideally we'd use FORMAT_PROC_FD_PATH(fd) here too, but that breaks the #! logic */ if (r < 0) return log_error_errno(r, "Failed to spawn '%s' process: %m", where); @@ -215,7 +218,7 @@ static int varlink_connect_auto(Varlink **ret, const char *where) { } /* Otherwise assume this is an URL */ - r = varlink_connect_url(ret, where); + r = sd_varlink_connect_url(ret, where); if (r < 0) return log_error_errno(r, "Failed to connect to URL '%s': %m", where); @@ -237,7 +240,7 @@ static void get_info_data_done(GetInfoData *d) { } static int verb_info(int argc, char *argv[], void *userdata) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; const char *url; int r; @@ -319,7 +322,7 @@ typedef struct GetInterfaceDescriptionData { } GetInterfaceDescriptionData; static int verb_introspect(int argc, char *argv[], void *userdata) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; _cleanup_strv_free_ char **auto_interfaces = NULL; char **interfaces; const char *url; @@ -380,7 +383,7 @@ static int verb_introspect(int argc, char *argv[], void *userdata) { { "description", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, 0, SD_JSON_MANDATORY }, {} }; - _cleanup_(varlink_interface_freep) VarlinkInterface *vi = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *vi = NULL; const char *description = NULL; unsigned line = 0, column = 0; @@ -402,8 +405,8 @@ static int verb_introspect(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); fputs_with_newline(stdout, description); } else if (list_methods) { - for (const VarlinkSymbol *const *y = vi->symbols, *symbol; (symbol = *y); y++) { - if (symbol->symbol_type != VARLINK_METHOD) + for (const sd_varlink_symbol *const *y = vi->symbols, *symbol; (symbol = *y); y++) { + if (symbol->symbol_type != SD_VARLINK_METHOD) continue; r = strv_extendf(&methods, "%s.%s", vi->name, symbol->name); @@ -412,7 +415,7 @@ static int verb_introspect(int argc, char *argv[], void *userdata) { } } else { pager_open(arg_pager_flags); - r = varlink_idl_dump(stdout, /* use_colors= */ -1, on_tty() ? columns() : SIZE_MAX, vi); + r = sd_varlink_idl_dump(stdout, vi, SD_VARLINK_IDL_FORMAT_COLOR_AUTO, on_tty() ? columns() : SIZE_MAX); if (r < 0) return log_error_errno(r, "Failed to format parsed interface description: %m"); } @@ -444,10 +447,10 @@ static int verb_introspect(int argc, char *argv[], void *userdata) { } static int reply_callback( - Varlink *link, + sd_varlink *link, sd_json_variant *parameters, const char *error, - VarlinkReplyFlags flags, + sd_varlink_reply_flags_t flags, void *userdata) { int *ret = ASSERT_PTR(userdata), r; @@ -476,7 +479,7 @@ static int reply_callback( static int verb_call(int argc, char *argv[], void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *jp = NULL; - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; const char *url, *method, *parameter, *source; unsigned line = 0, column = 0; int r; @@ -524,7 +527,7 @@ static int verb_call(int argc, char *argv[], void *userdata) { sd_json_variant *reply = NULL; const char *error = NULL; - r = varlink_collect(vl, method, jp, &reply, &error); + r = sd_varlink_collect(vl, method, jp, &reply, &error); if (r < 0) return log_error_errno(r, "Failed to issue %s() call: %m", method); if (error) { @@ -548,42 +551,42 @@ static int verb_call(int argc, char *argv[], void *userdata) { sd_json_variant_dump(reply, arg_json_format_flags, stdout, NULL); return r; - } else if (arg_method_flags & VARLINK_METHOD_ONEWAY) { - r = varlink_send(vl, method, jp); + } else if (arg_method_flags & SD_VARLINK_METHOD_ONEWAY) { + r = sd_varlink_send(vl, method, jp); if (r < 0) return log_error_errno(r, "Failed to issue %s() call: %m", method); - r = varlink_flush(vl); + r = sd_varlink_flush(vl); if (r < 0) return log_error_errno(r, "Failed to flush Varlink connection: %m"); - } else if (arg_method_flags & VARLINK_METHOD_MORE) { + } else if (arg_method_flags & SD_VARLINK_METHOD_MORE) { int ret = 0; - varlink_set_userdata(vl, &ret); + sd_varlink_set_userdata(vl, &ret); - r = varlink_bind_reply(vl, reply_callback); + r = sd_varlink_bind_reply(vl, reply_callback); if (r < 0) return log_error_errno(r, "Failed to bind reply callback: %m"); - r = varlink_observe(vl, method, jp); + r = sd_varlink_observe(vl, method, jp); if (r < 0) return log_error_errno(r, "Failed to issue %s() call: %m", method); for (;;) { - r = varlink_is_idle(vl); + r = sd_varlink_is_idle(vl); if (r < 0) return log_error_errno(r, "Failed to check if varlink connection is idle: %m"); if (r > 0) break; - r = varlink_process(vl); + r = sd_varlink_process(vl); if (r < 0) return log_error_errno(r, "Failed to process varlink connection: %m"); if (r != 0) continue; - r = varlink_wait(vl, USEC_INFINITY); + r = sd_varlink_wait(vl, USEC_INFINITY); if (r < 0) return log_error_errno(r, "Failed to wait for varlink connection events: %m"); } @@ -593,7 +596,7 @@ static int verb_call(int argc, char *argv[], void *userdata) { sd_json_variant *reply = NULL; const char *error = NULL; - r = varlink_call(vl, method, jp, &reply, &error); + r = sd_varlink_call(vl, method, jp, &reply, &error); if (r < 0) return log_error_errno(r, "Failed to issue %s() call: %m", method); @@ -625,7 +628,7 @@ static int verb_call(int argc, char *argv[], void *userdata) { } static int verb_validate_idl(int argc, char *argv[], void *userdata) { - _cleanup_(varlink_interface_freep) VarlinkInterface *vi = NULL; + _cleanup_(varlink_interface_freep) sd_varlink_interface *vi = NULL; _cleanup_free_ char *text = NULL; const char *fname; unsigned line = 1, column = 1; @@ -666,7 +669,7 @@ static int verb_validate_idl(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); - r = varlink_idl_dump(stdout, /* use_colors= */ -1, on_tty() ? columns() : SIZE_MAX, vi); + r = sd_varlink_idl_dump(stdout, vi, SD_VARLINK_IDL_FORMAT_COLOR_AUTO, on_tty() ? columns() : SIZE_MAX); if (r < 0) return log_error_errno(r, "Failed to format parsed interface description: %m"); diff --git a/src/vmspawn/vmspawn-register.c b/src/vmspawn/vmspawn-register.c index 124ee111b2..474cbd5df9 100644 --- a/src/vmspawn/vmspawn-register.c +++ b/src/vmspawn/vmspawn-register.c @@ -3,6 +3,7 @@ #include "sd-bus.h" #include "sd-id128.h" #include "sd-json.h" +#include "sd-varlink.h" #include "bus-error.h" #include "bus-locator.h" @@ -11,8 +12,8 @@ #include "process-util.h" #include "socket-util.h" #include "string-util.h" -#include "varlink.h" #include "vmspawn-register.h" +#include "varlink-util.h" int register_machine( sd_bus *bus, @@ -25,14 +26,14 @@ int register_machine( const char *key_path, bool keep_unit) { - _cleanup_(varlink_unrefp) Varlink *vl = NULL; + _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; int r; assert(machine_name); assert(service); /* First try to use varlink, as it provides more features (such as SSH support). */ - r = varlink_connect_address(&vl, "/run/systemd/machine/io.systemd.Machine"); + r = sd_varlink_connect_address(&vl, "/run/systemd/machine/io.systemd.Machine"); if (r == -ENOENT || ERRNO_IS_DISCONNECT(r)) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |