diff options
Diffstat (limited to 'src/machine')
-rw-r--r-- | src/machine/machine-varlink.c | 57 | ||||
-rw-r--r-- | src/machine/machine-varlink.h | 2 | ||||
-rw-r--r-- | src/machine/machinectl.c | 3 | ||||
-rw-r--r-- | src/machine/machined-varlink.c | 75 |
4 files changed, 70 insertions, 67 deletions
diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c index 3f95388abc..a6bf6528c4 100644 --- a/src/machine/machine-varlink.c +++ b/src/machine/machine-varlink.c @@ -3,9 +3,10 @@ #include <limits.h> #include "sd-id128.h" +#include "sd-json.h" #include "hostname-util.h" -#include "json.h" +#include "json-util.h" #include "machine-varlink.h" #include "machine.h" #include "path-util.h" @@ -17,17 +18,17 @@ static JSON_DISPATCH_ENUM_DEFINE(dispatch_machine_class, MachineClass, machine_class_from_string); -static int machine_name(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { char **m = ASSERT_PTR(userdata); const char *hostname; int r; assert(variant); - if (!json_variant_is_string(variant)) + if (!sd_json_variant_is_string(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); - hostname = json_variant_string(variant); + hostname = sd_json_variant_string(variant); if (!hostname_is_valid(hostname, /* flags= */ 0)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Invalid machine name"); @@ -38,16 +39,16 @@ static int machine_name(const char *name, JsonVariant *variant, JsonDispatchFlag return 0; } -static int machine_leader(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_leader(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { PidRef *leader = ASSERT_PTR(userdata); _cleanup_(pidref_done) PidRef temp = PIDREF_NULL; uint64_t k; int r; - if (!json_variant_is_unsigned(variant)) + if (!sd_json_variant_is_unsigned(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name)); - k = json_variant_unsigned(variant); + k = sd_json_variant_unsigned(variant); if (k > PID_T_MAX || !pid_is_valid(k)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid PID.", strna(name)); @@ -65,30 +66,30 @@ static int machine_leader(const char *name, JsonVariant *variant, JsonDispatchFl return 0; } -static int machine_ifindices(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_ifindices(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { Machine *m = ASSERT_PTR(userdata); _cleanup_free_ int *netif = NULL; size_t n_netif, k = 0; assert(variant); - if (!json_variant_is_array(variant)) + if (!sd_json_variant_is_array(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name)); - n_netif = json_variant_elements(variant); + n_netif = sd_json_variant_elements(variant); netif = new(int, n_netif); if (!netif) return json_log_oom(variant, flags); - JsonVariant *i; + sd_json_variant *i; JSON_VARIANT_ARRAY_FOREACH(i, variant) { uint64_t b; - if (!json_variant_is_unsigned(i)) + if (!sd_json_variant_is_unsigned(i)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Element %zu of JSON field '%s' is not an unsigned integer.", k, strna(name)); - b = json_variant_unsigned(i); + b = sd_json_variant_unsigned(i); if (b > INT_MAX || b <= 0) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Invalid network interface index %"PRIu64, b); @@ -102,15 +103,15 @@ static int machine_ifindices(const char *name, JsonVariant *variant, JsonDispatc return 0; } -static int machine_cid(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_cid(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { unsigned cid, *c = ASSERT_PTR(userdata); assert(variant); - if (!json_variant_is_unsigned(variant)) + if (!sd_json_variant_is_unsigned(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); - cid = json_variant_unsigned(variant); + cid = sd_json_variant_unsigned(variant); if (!VSOCK_CID_IS_REGULAR(cid)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a regular VSOCK CID.", strna(name)); @@ -119,22 +120,22 @@ static int machine_cid(const char *name, JsonVariant *variant, JsonDispatchFlags return 0; } -int vl_method_register(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { Manager *manager = ASSERT_PTR(userdata); _cleanup_(machine_freep) Machine *machine = NULL; int r; - static const JsonDispatch dispatch_table[] = { - { "name", JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), JSON_MANDATORY }, - { "id", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(Machine, id), 0 }, - { "service", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Machine, service), 0 }, - { "class", JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), JSON_MANDATORY }, - { "leader", JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 }, - { "rootDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 }, - { "ifIndices", JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 }, - { "vSockCid", JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, - { "sshAddress", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Machine, ssh_address), JSON_SAFE }, - { "sshPrivateKeyPath", JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "name", SD_JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), SD_JSON_MANDATORY }, + { "id", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(Machine, id), 0 }, + { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, service), 0 }, + { "class", SD_JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), SD_JSON_MANDATORY }, + { "leader", SD_JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 }, + { "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 }, + { "ifIndices", SD_JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 }, + { "vSockCid", SD_JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, + { "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_SAFE }, + { "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, {} }; diff --git a/src/machine/machine-varlink.h b/src/machine/machine-varlink.h index ce4ec54dc1..f9df0ed2a9 100644 --- a/src/machine/machine-varlink.h +++ b/src/machine/machine-varlink.h @@ -3,4 +3,4 @@ #include "varlink.h" -int vl_method_register(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata); +int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 1b63e6d203..5572115a54 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -34,6 +34,7 @@ #include "format-table.h" #include "hostname-util.h" #include "import-util.h" +#include "in-addr-util.h" #include "locale-util.h" #include "log.h" #include "logs-show.h" @@ -261,7 +262,7 @@ static int show_table(Table *table, const char *word) { table_set_header(table, arg_legend); if (OUTPUT_MODE_IS_JSON(arg_output)) - r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO); + r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | SD_JSON_FORMAT_COLOR_AUTO); else r = table_print(table, NULL); if (r < 0) diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c index 0d3ae627c1..3c1f20eff8 100644 --- a/src/machine/machined-varlink.c +++ b/src/machine/machined-varlink.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "format-util.h" +#include "json-util.h" #include "machine-varlink.h" #include "machined-varlink.h" #include "mkdir.h" @@ -19,22 +20,22 @@ typedef struct LookupParameters { const char *service; } LookupParameters; -static int build_user_json(const char *user_name, uid_t uid, const char *real_name, JsonVariant **ret) { +static int build_user_json(const char *user_name, uid_t uid, const char *real_name, sd_json_variant **ret) { assert(user_name); assert(uid_is_valid(uid)); assert(ret); - return json_build(ret, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("record", JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(user_name)), - JSON_BUILD_PAIR("uid", JSON_BUILD_UNSIGNED(uid)), - JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(GID_NOBODY)), - JSON_BUILD_PAIR_CONDITION(!isempty(real_name), "realName", JSON_BUILD_STRING(real_name)), - JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/")), - JSON_BUILD_PAIR("shell", JSON_BUILD_STRING(NOLOGIN)), - JSON_BUILD_PAIR("locked", JSON_BUILD_BOOLEAN(true)), - JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")), - JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container")))))); + return sd_json_build(ret, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(user_name)), + SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(uid)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(GID_NOBODY)), + SD_JSON_BUILD_PAIR_CONDITION(!isempty(real_name), "realName", SD_JSON_BUILD_STRING(real_name)), + SD_JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/")), + SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)), + SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)), + SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container")))))); } static bool user_match_lookup_parameters(LookupParameters *p, const char *name, uid_t uid) { @@ -138,16 +139,16 @@ 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, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { - static const JsonDispatch dispatch_table[] = { - { "uid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, - { "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE }, - { "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 }, + { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE }, + { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, {} }; - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; LookupParameters p = { .uid = UID_INVALID, }; @@ -190,18 +191,18 @@ static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, Var return varlink_reply(link, v); } -static int build_group_json(const char *group_name, gid_t gid, const char *description, JsonVariant **ret) { +static int build_group_json(const char *group_name, gid_t gid, const char *description, sd_json_variant **ret) { assert(group_name); assert(gid_is_valid(gid)); assert(ret); - return json_build(ret, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("record", JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(group_name)), - JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(gid)), - JSON_BUILD_PAIR_CONDITION(!isempty(description), "description", JSON_BUILD_STRING(description)), - JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")), - JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container")))))); + return sd_json_build(ret, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(group_name)), + SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(gid)), + SD_JSON_BUILD_PAIR_CONDITION(!isempty(description), "description", SD_JSON_BUILD_STRING(description)), + SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")), + SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container")))))); } static bool group_match_lookup_parameters(LookupParameters *p, const char *name, gid_t gid) { @@ -303,16 +304,16 @@ 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, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { - static const JsonDispatch dispatch_table[] = { - { "gid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, - { "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE }, - { "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 }, + { "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE }, + { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, {} }; - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; LookupParameters p = { .gid = GID_INVALID, }; @@ -355,12 +356,12 @@ static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, Va return varlink_reply(link, v); } -static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { - static const JsonDispatch dispatch_table[] = { - { "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE }, - { "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE }, - { "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE }, + { "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE }, + { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, {} }; |