From: Zbigniew Jędrzejewski-Szmek Date: Thu, 17 Nov 2022 14:40:54 +0000 (+0100) Subject: bootctl: use output mode where "[]" is written instead for empty output X-Git-Tag: v253-rc1~334^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3f0bff9456dcb79f5c929f3d9b15a1a884735df;p=thirdparty%2Fsystemd.git bootctl: use output mode where "[]" is written instead for empty output It's easier for the caller if output is always a list, even if there are no entries. --- diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 435fa4c1bb1..8ae891e8a09 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -1448,7 +1448,7 @@ int show_boot_entries(const BootConfig *config, JsonFormatFlags json_format) { return log_oom(); } - json_variant_dump(array, json_format, NULL, NULL); + json_variant_dump(array, json_format | JSON_FORMAT_EMPTY_ARRAY, NULL, NULL); } else { for (size_t n = 0; n < config->n_entries; n++) { diff --git a/src/shared/json.c b/src/shared/json.c index fe03f230469..b1ef0ed3499 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -1810,8 +1810,12 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) { } int json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const char *prefix) { - if (!v) - return 0; + if (!v) { + if (flags & JSON_FORMAT_EMPTY_ARRAY) + v = JSON_VARIANT_MAGIC_EMPTY_ARRAY; + else + return 0; + } if (!f) f = stdout; diff --git a/src/shared/json.h b/src/shared/json.h index b1658b5f4bd..8d060e78777 100644 --- a/src/shared/json.h +++ b/src/shared/json.h @@ -194,7 +194,8 @@ typedef enum JsonFormatFlags { JSON_FORMAT_SSE = 1 << 6, /* prefix/suffix with W3C server-sent events */ JSON_FORMAT_SEQ = 1 << 7, /* prefix/suffix with RFC 7464 application/json-seq */ JSON_FORMAT_FLUSH = 1 << 8, /* call fflush() after dumping JSON */ - JSON_FORMAT_OFF = 1 << 9, /* make json_variant_format() fail with -ENOEXEC */ + JSON_FORMAT_EMPTY_ARRAY = 1 << 9, /* output "[]" for empty input */ + JSON_FORMAT_OFF = 1 << 10, /* make json_variant_format() fail with -ENOEXEC */ } JsonFormatFlags; int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);