diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-31 21:43:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-31 21:43:18 +0100 |
commit | 5ca96e27176975c0054f05b3c11acf852a065b50 (patch) | |
tree | f3835a1801cf3138764cba4cec006919f041bc28 /src/libsystemd | |
parent | sd-json: don't accidentally convert between unsigned/signed when parsing signal (diff) | |
parent | machine: lookup_machine_by_name_or_pidref() returns negative errno on failure (diff) | |
download | systemd-5ca96e27176975c0054f05b3c11acf852a065b50.tar.xz systemd-5ca96e27176975c0054f05b3c11acf852a065b50.zip |
machine: several follow-ups for recent change (#34882)
Follow-ups for #34761.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-json/json-util.h | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-json/sd-json.c | 29 |
2 files changed, 17 insertions, 14 deletions
diff --git a/src/libsystemd/sd-json/json-util.h b/src/libsystemd/sd-json/json-util.h index 2aeb076823..81c0fd02a6 100644 --- a/src/libsystemd/sd-json/json-util.h +++ b/src/libsystemd/sd-json/json-util.h @@ -157,6 +157,7 @@ enum { _JSON_BUILD_PAIR_FINITE_USEC, _JSON_BUILD_PAIR_STRING_NON_EMPTY, _JSON_BUILD_PAIR_STRV_NON_EMPTY, + _JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY, _JSON_BUILD_PAIR_VARIANT_NON_NULL, /* _SD_JSON_BUILD_PAIR_VARIANT_ARRAY_NON_EMPTY, */ _JSON_BUILD_PAIR_BYTE_ARRAY_NON_EMPTY, @@ -204,6 +205,7 @@ enum { #define JSON_BUILD_PAIR_FINITE_USEC(name, u) _JSON_BUILD_PAIR_FINITE_USEC, (const char*) { name }, (usec_t) { u } #define JSON_BUILD_PAIR_STRING_NON_EMPTY(name, s) _JSON_BUILD_PAIR_STRING_NON_EMPTY, (const char*) { name }, (const char*) { s } #define JSON_BUILD_PAIR_STRV_NON_EMPTY(name, l) _JSON_BUILD_PAIR_STRV_NON_EMPTY, (const char*) { name }, (char**) { l } +#define JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY(name, l) _JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY, (const char*) { name }, (char**) { l } #define JSON_BUILD_PAIR_VARIANT_NON_NULL(name, v) _JSON_BUILD_PAIR_VARIANT_NON_NULL, (const char*) { name }, (sd_json_variant*) { v } #define JSON_BUILD_PAIR_BYTE_ARRAY_NON_EMPTY(name, v, n) _JSON_BUILD_PAIR_BYTE_ARRAY_NON_EMPTY, (const char*) { name }, (const void*) { v }, (size_t) { n } #define JSON_BUILD_PAIR_IN4_ADDR_NON_NULL(name, v) _JSON_BUILD_PAIR_IN4_ADDR_NON_NULL, (const char*) { name }, (const struct in_addr*) { v } diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c index c3d74df9e6..a8a5e47761 100644 --- a/src/libsystemd/sd-json/sd-json.c +++ b/src/libsystemd/sd-json/sd-json.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "ansi-color.h" +#include "env-util.h" #include "errno-util.h" #include "escape.h" #include "ether-addr-util.h" @@ -3867,22 +3868,13 @@ _public_ int sd_json_buildv(sd_json_variant **ret, va_list ap) { l = va_arg(ap, char **); - _cleanup_strv_free_ char **el = NULL; - STRV_FOREACH_PAIR(x, y, l) { - char *n = NULL; - - n = strjoin(*x, "=", *y); - if (!n) { - r = -ENOMEM; - goto finish; - } + if (current->n_suppress == 0) { + _cleanup_strv_free_ char **el = NULL; - r = strv_consume(&el, n); + r = strv_env_get_merged(l, &el); if (r < 0) goto finish; - } - if (current->n_suppress == 0) { r = sd_json_variant_new_array_strv(&add, el); if (r < 0) goto finish; @@ -4541,7 +4533,8 @@ _public_ int sd_json_buildv(sd_json_variant **ret, va_list ap) { break; } - case _JSON_BUILD_PAIR_STRV_NON_EMPTY: { + case _JSON_BUILD_PAIR_STRV_NON_EMPTY: + case _JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY: { const char *n; char **l; @@ -4554,11 +4547,19 @@ _public_ int sd_json_buildv(sd_json_variant **ret, va_list ap) { l = va_arg(ap, char **); if (!strv_isempty(l) && current->n_suppress == 0) { + _cleanup_strv_free_ char **el = NULL; + + if (command == _JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY) { + r = strv_env_get_merged(l, &el); + if (r < 0) + goto finish; + } + r = sd_json_variant_new_string(&add, n); if (r < 0) goto finish; - r = sd_json_variant_new_array_strv(&add_more, l); + r = sd_json_variant_new_array_strv(&add_more, el ?: l); if (r < 0) goto finish; } |