diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-10-25 19:09:01 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-10-31 03:02:35 +0100 |
commit | dbceb0507ffa4745d9d73db2316473055fc98834 (patch) | |
tree | 079d7eceacfa74bdf9b72b669f7f23a755ad328a /src | |
parent | sd-json: use strv_env_get_merged() (diff) | |
download | systemd-dbceb0507ffa4745d9d73db2316473055fc98834.tar.xz systemd-dbceb0507ffa4745d9d73db2316473055fc98834.zip |
sd-json: introduce JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY() macro
It is similar to JSON_BUILD_PAIR_STRV_NON_EMPTY, but takes the
list of environment variables.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/sd-json/json-util.h | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-json/sd-json.c | 13 |
2 files changed, 13 insertions, 2 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 293df301a2..f0a9470a17 100644 --- a/src/libsystemd/sd-json/sd-json.c +++ b/src/libsystemd/sd-json/sd-json.c @@ -4533,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; @@ -4546,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; } |