summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-28 19:29:03 +0100
committerGitHub <noreply@github.com>2024-10-28 19:29:03 +0100
commitfeb9ccb56eb8968356a435ce3f59fcf35e4bcb65 (patch)
tree42dd15c82982b156628f7e143e63bddae568c460
parentMerge pull request #34806 from ryantimwilson/protect-control-groups (diff)
parentsd-json,tree-wide: add sd_json_format_enabled() and use it everwhere (diff)
downloadsystemd-feb9ccb56eb8968356a435ce3f59fcf35e4bcb65.tar.xz
systemd-feb9ccb56eb8968356a435ce3f59fcf35e4bcb65.zip
Merge pull request #34633 from keszybz/sd-json-enum-formatting
Add sd_json_format_enabled() helper
-rw-r--r--src/analyze/analyze-fdstore.c2
-rw-r--r--src/analyze/analyze-inspect-elf.c7
-rw-r--r--src/analyze/analyze-plot.c4
-rw-r--r--src/analyze/analyze-security.c4
-rw-r--r--src/analyze/analyze.c6
-rw-r--r--src/boot/bootctl-status.c2
-rw-r--r--src/boot/measure.c8
-rw-r--r--src/busctl/busctl.c14
-rw-r--r--src/creds/creds.c4
-rw-r--r--src/dissect/dissect.c10
-rw-r--r--src/home/homectl.c6
-rw-r--r--src/hostname/hostnamectl.c2
-rw-r--r--src/import/importctl.c2
-rw-r--r--src/journal/journalctl-misc.c2
-rw-r--r--src/kernel-install/kernel-install.c2
-rw-r--r--src/libsystemd/sd-json/sd-json.c2
-rw-r--r--src/login/loginctl.c2
-rw-r--r--src/network/networkctl-description.c2
-rw-r--r--src/network/networkctl-lldp.c2
-rw-r--r--src/partition/repart.c14
-rw-r--r--src/pcrlock/pcrlock.c18
-rw-r--r--src/resolve/resolvectl.c24
-rw-r--r--src/run/run.c2
-rw-r--r--src/shared/bootspec.c2
-rw-r--r--src/shared/format-table.c2
-rw-r--r--src/sysext/sysext.c2
-rw-r--r--src/systemd/_sd-common.h4
-rw-r--r--src/systemd/sd-id128.h10
-rw-r--r--src/systemd/sd-json.h5
-rw-r--r--src/sysupdate/sysupdate.c12
-rw-r--r--src/udev/udevadm-info.c20
-rw-r--r--src/userdb/userdbctl.c2
-rw-r--r--src/varlinkctl/varlinkctl.c8
33 files changed, 108 insertions, 100 deletions
diff --git a/src/analyze/analyze-fdstore.c b/src/analyze/analyze-fdstore.c
index 4cf015ab44..e7e273e218 100644
--- a/src/analyze/analyze-fdstore.c
+++ b/src/analyze/analyze-fdstore.c
@@ -81,7 +81,7 @@ static int dump_fdstore(sd_bus *bus, const char *arg) {
if (r < 0)
return r;
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && table_isempty(table))
+ if (table_isempty(table) && !sd_json_format_enabled(arg_json_format_flags))
log_info("No file descriptors in fdstore of '%s'.", unit);
else {
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */true);
diff --git a/src/analyze/analyze-inspect-elf.c b/src/analyze/analyze-inspect-elf.c
index 1ae7304163..01824d5eab 100644
--- a/src/analyze/analyze-inspect-elf.c
+++ b/src/analyze/analyze-inspect-elf.c
@@ -118,12 +118,13 @@ static int analyze_elf(char **filenames, sd_json_format_flags_t json_flags) {
return table_log_add_error(r);
}
- if (json_flags & SD_JSON_FORMAT_OFF) {
+ if (sd_json_format_enabled(json_flags))
+ sd_json_variant_dump(package_metadata, json_flags, stdout, NULL);
+ else {
r = table_print(t, NULL);
if (r < 0)
return table_log_print_error(r);
- } else
- sd_json_variant_dump(package_metadata, json_flags, stdout, NULL);
+ }
}
return 0;
diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c
index 78aeff1b62..d3316651c9 100644
--- a/src/analyze/analyze-plot.c
+++ b/src/analyze/analyze-plot.c
@@ -417,7 +417,7 @@ static int show_table(Table *table, const char *word) {
if (!table_isempty(table)) {
table_set_header(table, arg_legend);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
r = table_print_json(table, NULL, arg_json_format_flags | SD_JSON_FORMAT_COLOR_AUTO);
else
r = table_print(table, NULL);
@@ -494,7 +494,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
typesafe_qsort(times, n, compare_unit_start);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) || arg_table)
+ if (sd_json_format_enabled(arg_json_format_flags) || arg_table)
r = produce_plot_as_text(times, boot);
else
r = produce_plot_as_svg(times, host, boot, pretty_times);
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c
index 874fff14b4..aefd4f6122 100644
--- a/src/analyze/analyze-security.c
+++ b/src/analyze/analyze-security.c
@@ -1872,7 +1872,7 @@ static int assess(const SecurityInfo *info,
return log_error_errno(r, "Failed to update cell in table: %m");
}
- if (json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(json_format_flags)) {
r = table_hide_column_from_display(details_table, (size_t) 2);
if (r < 0)
return log_error_errno(r, "Failed to set columns to display: %m");
@@ -1891,7 +1891,7 @@ static int assess(const SecurityInfo *info,
assert(i < ELEMENTSOF(badness_table));
- if (details_table && (json_format_flags & SD_JSON_FORMAT_OFF)) {
+ if (details_table && !sd_json_format_enabled(json_format_flags)) {
_cleanup_free_ char *clickable = NULL;
const char *name;
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 5aba273ca6..0db3547a49 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -592,7 +592,7 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Option --offline= requires one or more units to perform a security review.");
- if (arg_json_format_flags != SD_JSON_FORMAT_OFF && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs", "architectures", "capability", "exit-status"))
+ if (sd_json_format_enabled(arg_json_format_flags) && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs", "architectures", "capability", "exit-status"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Option --json= is only supported for security, inspect-elf, plot, fdstore, pcrs, architectures, capability, exit-status right now.");
@@ -631,13 +631,13 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No conditions can be passed if --unit= is used.");
if ((!arg_legend && !STRPTR_IN_SET(argv[optind], "plot", "architectures")) ||
- (streq_ptr(argv[optind], "plot") && !arg_legend && !arg_table && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)))
+ (streq_ptr(argv[optind], "plot") && !arg_legend && !arg_table && !sd_json_format_enabled(arg_json_format_flags)))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --no-legend is only supported for plot with either --table or --json=.");
if (arg_table && !streq_ptr(argv[optind], "plot"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --table is only supported for plot right now.");
- if (arg_table && !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (arg_table && sd_json_format_enabled(arg_json_format_flags))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--table and --json= are mutually exclusive.");
if (arg_capability != CAPABILITY_LITERAL && !streq_ptr(argv[optind], "capability"))
diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c
index 61d76dd679..c548ddcee5 100644
--- a/src/boot/bootctl-status.c
+++ b/src/boot/bootctl-status.c
@@ -843,7 +843,7 @@ int verb_list(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
- if (config.n_entries == 0 && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (config.n_entries == 0 && !sd_json_format_enabled(arg_json_format_flags)) {
log_info("No boot loader entries found.");
return 0;
}
diff --git a/src/boot/measure.c b/src/boot/measure.c
index 38bc2afda5..3ad49e9d74 100644
--- a/src/boot/measure.c
+++ b/src/boot/measure.c
@@ -748,7 +748,7 @@ static int verb_calculate(int argc, char *argv[], void *userdata) {
return r;
for (size_t i = 0; i < n; i++) {
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_free_ char *hd = NULL;
if (i == 0) {
@@ -789,7 +789,7 @@ static int verb_calculate(int argc, char *argv[], void *userdata) {
pcr_states_restore(pcr_states, n);
}
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
pager_open(arg_pager_flags);
@@ -1106,7 +1106,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to decode PCR value '%s': %m", s);
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_free_ char *f = NULL;
f = hexmem(h, l);
@@ -1150,7 +1150,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
}
}
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
pager_open(arg_pager_flags);
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index 1e352a3729..4eeb4a98e5 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -1331,7 +1331,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
if (r < 0)
return log_error_errno(r, "Failed to get unique name: %m");
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Monitoring bus message stream.");
(void) sd_notify(/* unset_environment=false */ false, "READY=1");
@@ -1365,13 +1365,13 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
fflush(stdout);
if (arg_num_matches != UINT64_MAX && --arg_num_matches == 0) {
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Received requested number of matching messages, exiting.");
return 0;
}
if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected") > 0) {
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Connection terminated, exiting.");
return 0;
}
@@ -1384,7 +1384,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
r = sd_bus_wait(bus, arg_timeout > 0 ? arg_timeout : UINT64_MAX);
if (r == 0 && arg_timeout > 0) {
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Timed out waiting for messages, exiting.");
return 0;
}
@@ -1394,7 +1394,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
}
static int verb_monitor(int argc, char **argv, void *userdata) {
- return monitor(argc, argv, (arg_json_format_flags & SD_JSON_FORMAT_OFF) ? message_dump : message_json);
+ return monitor(argc, argv, sd_json_format_enabled(arg_json_format_flags) ? message_json : message_dump);
}
static int verb_capture(int argc, char **argv, void *userdata) {
@@ -2146,7 +2146,7 @@ static int call(int argc, char **argv, void *userdata) {
if (r > 0 || arg_quiet)
return 0;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
@@ -2256,7 +2256,7 @@ static int get_property(int argc, char **argv, void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
diff --git a/src/creds/creds.c b/src/creds/creds.c
index bb59db37fc..b24a84eaa6 100644
--- a/src/creds/creds.c
+++ b/src/creds/creds.c
@@ -273,7 +273,7 @@ static int verb_list(int argc, char **argv, void *userdata) {
return log_error_errno(SYNTHETIC_ERRNO(ENXIO), "No credentials passed. (i.e. $CREDENTIALS_DIRECTORY not set.)");
}
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && table_isempty(t)) {
+ if (table_isempty(t) && !sd_json_format_enabled(arg_json_format_flags)) {
log_info("No credentials");
return 0;
}
@@ -370,7 +370,7 @@ static int write_blob(FILE *f, const void *data, size_t size) {
int r;
if (arg_transcode == TRANSCODE_OFF &&
- arg_json_format_flags != SD_JSON_FORMAT_OFF) {
+ sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(erase_and_freep) char *suffixed = NULL;
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index 1cad45c8ff..78a830d574 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -877,7 +877,7 @@ static int action_dissect(
if (arg_json_format_flags & (SD_JSON_FORMAT_OFF|SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
pager_open(arg_pager_flags);
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
printf(" File Name: %s%s%s\n",
ansi_highlight(), bn, ansi_normal());
@@ -907,7 +907,7 @@ static int action_dissect(
log_warning_errno(r, "OS image is currently in use, proceeding without showing OS image metadata.");
else if (r < 0)
return log_error_errno(r, "Failed to acquire image metadata: %m");
- else if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ else if (!sd_json_format_enabled(arg_json_format_flags)) {
if (m->image_name && !streq(m->image_name, bn))
printf("Image Name: %s\n", m->image_name);
@@ -1017,7 +1017,7 @@ static int action_dissect(
/* Hide the device path if this is a loopback device that is not relinquished, since that means the
* device node is not going to be useful the instant our command exits */
- if ((!d || d->created) && (arg_json_format_flags & SD_JSON_FORMAT_OFF))
+ if ((!d || d->created) && !sd_json_format_enabled(arg_json_format_flags))
table_hide_column_from_display(t, 8);
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
@@ -1080,7 +1080,7 @@ static int action_dissect(
return table_log_add_error(r);
}
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
(void) table_set_header(t, arg_legend);
r = table_print(t, NULL);
@@ -1856,7 +1856,7 @@ static int action_discover(void) {
return log_error_errno(r, "Failed to discover images: %m");
}
- if ((arg_json_format_flags & SD_JSON_FORMAT_OFF) && hashmap_isempty(images)) {
+ if (hashmap_isempty(images) && !sd_json_format_enabled(arg_json_format_flags)) {
log_info("No images found.");
return 0;
}
diff --git a/src/home/homectl.c b/src/home/homectl.c
index 11270d7edb..b3aacbcbcf 100644
--- a/src/home/homectl.c
+++ b/src/home/homectl.c
@@ -203,7 +203,7 @@ static int list_homes(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
- if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!table_isempty(table) || sd_json_format_enabled(arg_json_format_flags)) {
r = table_set_sort(table, (size_t) 0);
if (r < 0)
return table_log_sort_error(r);
@@ -213,7 +213,7 @@ static int list_homes(int argc, char *argv[], void *userdata) {
return r;
}
- if (arg_legend && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (arg_legend && !sd_json_format_enabled(arg_json_format_flags)) {
if (table_isempty(table))
printf("No home areas.\n");
else
@@ -671,7 +671,7 @@ static void dump_home_record(UserRecord *hr) {
log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr->user_name);
}
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF)
+ if (!sd_json_format_enabled(arg_json_format_flags))
user_record_show(hr, true);
else {
_cleanup_(user_record_unrefp) UserRecord *stripped = NULL;
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 4bbfa670b7..a537312d25 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -491,7 +491,7 @@ static int show_status(int argc, char **argv, void *userdata) {
sd_bus *bus = userdata;
int r;
- if (arg_json_format_flags != SD_JSON_FORMAT_OFF) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
diff --git a/src/import/importctl.c b/src/import/importctl.c
index 0ddfa988a6..1ddba76b09 100644
--- a/src/import/importctl.c
+++ b/src/import/importctl.c
@@ -936,7 +936,7 @@ static int list_images(int argc, char *argv[], void *userdata) {
if (r < 0)
return table_log_add_error(r);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (!sd_json_format_enabled(arg_json_format_flags))
r = table_add_many(
t,
TABLE_STRING, read_only ? "ro" : "rw",
diff --git a/src/journal/journalctl-misc.c b/src/journal/journalctl-misc.c
index 5a1f311221..3dea69d9fb 100644
--- a/src/journal/journalctl-misc.c
+++ b/src/journal/journalctl-misc.c
@@ -333,7 +333,7 @@ int action_list_namespaces(void) {
}
}
- if (table_isempty(table) && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (table_isempty(table) && !sd_json_format_enabled(arg_json_format_flags)) {
if (!arg_quiet)
log_notice("No namespaces found.");
} else {
diff --git a/src/kernel-install/kernel-install.c b/src/kernel-install/kernel-install.c
index f4f30df07d..f059f5dc76 100644
--- a/src/kernel-install/kernel-install.c
+++ b/src/kernel-install/kernel-install.c
@@ -1370,7 +1370,7 @@ static int verb_inspect(int argc, char *argv[], void *userdata) {
if (r < 0)
return table_log_add_error(r);
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
r = table_add_many(t,
TABLE_FIELD, "Plugin Arguments",
TABLE_STRV, strv_skip(c->argv, 1));
diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c
index 297052bdb4..5e9c1ba15b 100644
--- a/src/libsystemd/sd-json/sd-json.c
+++ b/src/libsystemd/sd-json/sd-json.c
@@ -1877,7 +1877,7 @@ _public_ int sd_json_variant_format(sd_json_variant *v, sd_json_format_flags_t f
assert_return(v, -EINVAL);
assert_return(ret, -EINVAL);
- if (flags & SD_JSON_FORMAT_OFF)
+ if (!sd_json_format_enabled(flags))
return -ENOEXEC;
f = memstream_init(&m);
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index cdb017a931..bda69de076 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -1628,7 +1628,7 @@ static int parse_argv(int argc, char *argv[]) {
if (r <= 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
arg_legend = false;
break;
diff --git a/src/network/networkctl-description.c b/src/network/networkctl-description.c
index 14ce55bfae..410751f9e7 100644
--- a/src/network/networkctl-description.c
+++ b/src/network/networkctl-description.c
@@ -122,7 +122,7 @@ int dump_description(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
- if (arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!sd_json_format_enabled(arg_json_format_flags))
return 0;
r = acquire_bus(&bus);
diff --git a/src/network/networkctl-lldp.c b/src/network/networkctl-lldp.c
index 7836cb5ccf..8a10562b0d 100644
--- a/src/network/networkctl-lldp.c
+++ b/src/network/networkctl-lldp.c
@@ -231,7 +231,7 @@ int link_lldp_status(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
- if (arg_json_format_flags != SD_JSON_FORMAT_OFF)
+ if (sd_json_format_enabled(arg_json_format_flags))
return dump_lldp_neighbors_json(reply, strv_skip(argv, 1));
pager_open(arg_pager_flags);
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 65b50e346f..1acd5af38c 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -3511,7 +3511,7 @@ static int context_dump_partitions(Context *context) {
const size_t roothash_col = 14, dropin_files_col = 15, split_path_col = 16;
bool has_roothash = false, has_dropin_files = false, has_split_path = false;
- if ((arg_json_format_flags & SD_JSON_FORMAT_OFF) && context->n_partitions == 0) {
+ if (context->n_partitions == 0 && !sd_json_format_enabled(arg_json_format_flags)) {
log_info("Empty partition table.");
return 0;
}
@@ -3541,7 +3541,7 @@ static int context_dump_partitions(Context *context) {
table_set_json_field_name(t, 15, "drop-in_files");
if (!DEBUG_LOGGING) {
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF)
+ if (!sd_json_format_enabled(arg_json_format_flags))
(void) table_set_display(t, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 4,
(size_t) 8, (size_t) 9, (size_t) 12, roothash_col, dropin_files_col,
split_path_col);
@@ -3624,7 +3624,7 @@ static int context_dump_partitions(Context *context) {
has_split_path = has_split_path || !isempty(p->split_path);
}
- if ((arg_json_format_flags & SD_JSON_FORMAT_OFF) && (sum_padding > 0 || sum_size > 0)) {
+ if (!sd_json_format_enabled(arg_json_format_flags) && (sum_padding > 0 || sum_size > 0)) {
const char *a, *b;
a = strjoina(special_glyph(SPECIAL_GLYPH_SIGMA), " = ", FORMAT_BYTES(sum_size));
@@ -3891,17 +3891,17 @@ static int context_dump(Context *context, bool late) {
assert(context);
- if (arg_pretty == 0 && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (arg_pretty == 0 && !sd_json_format_enabled(arg_json_format_flags))
return 0;
/* If we're outputting JSON, only dump after doing all operations so we can include the roothashes
* in the output. */
- if (!late && !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (!late && sd_json_format_enabled(arg_json_format_flags))
return 0;
/* If we're not outputting JSON, only dump again after doing all operations if there are any
* roothashes that we need to communicate to the user. */
- if (late && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && !context_has_roothash(context))
+ if (late && !sd_json_format_enabled(arg_json_format_flags) && !context_has_roothash(context))
return 0;
r = context_dump_partitions(context);
@@ -3910,7 +3910,7 @@ static int context_dump(Context *context, bool late) {
/* Only write the partition bar once, even if we're writing the partition table twice to communicate
* roothashes. */
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && !late) {
+ if (!sd_json_format_enabled(arg_json_format_flags) && !late) {
putc('\n', stdout);
r = context_dump_partition_bar(context);
diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c
index 46f285d54a..c1915761ee 100644
--- a/src/pcrlock/pcrlock.c
+++ b/src/pcrlock/pcrlock.c
@@ -2045,7 +2045,7 @@ static int add_algorithm_columns(
if (r < 0)
return table_log_add_error(r);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) &&
+ if (!sd_json_format_enabled(arg_json_format_flags) &&
el->primary_algorithm != UINT16_MAX &&
*alg != el->primary_algorithm)
(void) table_hide_column_from_display(table, c);
@@ -2106,7 +2106,7 @@ static int show_log_table(EventLog *el, sd_json_variant **ret_variant) {
(void) table_hide_column_from_display(table, table_get_columns(table) - 3); /* hide source */
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
(void) table_hide_column_from_display(table, (size_t) 1); /* hide color block column */
(void) table_set_json_field_name(table, phase_column, "phase");
@@ -2242,7 +2242,7 @@ static int show_pcr_table(EventLog *el, sd_json_variant **ret_variant) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
(void) table_hide_column_from_display(table, (size_t) 1, (size_t) 2); /* hide color block and emoji column */
else if (!emoji_enabled())
(void) table_hide_column_from_display(table, (size_t) 2);
@@ -2347,7 +2347,7 @@ static int show_pcr_table(EventLog *el, sd_json_variant **ret_variant) {
if (r < 0)
return log_error_errno(r, "Failed to output table: %m");
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (!sd_json_format_enabled(arg_json_format_flags))
printf("\n"
"%sLegend: H → PCR hash value matches event log%s\n"
"%s R → All event log records for this PCR have a matching component%s\n"
@@ -2431,7 +2431,7 @@ static int event_log_load_and_process(EventLog **ret) {
static int verb_show_log(int argc, char *argv[], void *userdata) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *log_table = NULL, *pcr_table = NULL;
_cleanup_(event_log_freep) EventLog *el = NULL;
- bool want_json = !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF);
+ bool want_json = sd_json_format_enabled(arg_json_format_flags);
int r;
r = event_log_load_and_process(&el);
@@ -2607,7 +2607,7 @@ static int verb_list_components(int argc, char *argv[], void *userdata) {
FOREACH_ARRAY(c, el->components, el->n_components) {
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_free_ char *marker = NULL;
switch (loc) {
@@ -2653,13 +2653,13 @@ static int verb_list_components(int argc, char *argv[], void *userdata) {
}
}
- if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!table_isempty(table) || sd_json_format_enabled(arg_json_format_flags)) {
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */ true);
if (r < 0)
return log_error_errno(r, "Failed to output table: %m");
}
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
if (table_isempty(table))
printf("No components defined.\n");
else
@@ -4154,7 +4154,7 @@ static int event_log_show_predictions(Tpm2PCRPrediction *context, uint16_t alg)
pager_open(arg_pager_flags);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
for (size_t i = 0; i < TPM2_N_HASH_ALGORITHMS; i++) {
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c
index 0204fdf16f..62354b4784 100644
--- a/src/resolve/resolvectl.c
+++ b/src/resolve/resolvectl.c
@@ -204,7 +204,7 @@ static void print_source(uint64_t flags, usec_t rtt) {
if (!arg_legend)
return;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return;
if (flags == 0)
@@ -273,7 +273,7 @@ static int resolve_host(sd_bus *bus, const char *name) {
assert(name);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type=A or --type=AAAA to acquire address record information in JSON format.");
log_debug("Resolving %s (family %s, interface %s).", name, af_to_name(arg_family) ?: "*", isempty(arg_ifname) ? "*" : arg_ifname);
@@ -374,7 +374,7 @@ static int resolve_address(sd_bus *bus, int family, const union in_addr_union *a
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
if (ifindex <= 0)
@@ -468,7 +468,7 @@ static int output_rr_packet(const void *d, size_t l, int ifindex) {
if (r < 0)
return log_error_errno(r, "Failed to parse RR: %m");
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
r = dns_resource_record_to_json(rr, &j);
if (r < 0)
@@ -994,7 +994,7 @@ static int verb_service(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
if (argc == 2)
@@ -1060,7 +1060,7 @@ static int verb_openpgp(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
STRV_FOREACH(p, strv_skip(argv, 1))
@@ -1117,7 +1117,7 @@ static int verb_tlsa(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
if (service_family_is_valid(argv[1])) {
@@ -1152,7 +1152,7 @@ static int show_statistics(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return sd_json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
struct statistics {
@@ -1316,7 +1316,7 @@ static int reset_statistics(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (sd_json_format_enabled(arg_json_format_flags))
return sd_json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
return 0;
@@ -2978,7 +2978,7 @@ static int monitor_reply(
return 0;
}
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
monitor_query_dump(parameters);
printf("\n");
} else
@@ -3180,7 +3180,7 @@ static int verb_show_cache(int argc, char *argv[], void *userdata) {
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"DumpCache() response 'dump' field not an array");
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
sd_json_variant *i;
JSON_VARIANT_ARRAY_FOREACH(i, d) {
@@ -3360,7 +3360,7 @@ static int verb_show_server_state(int argc, char *argv[], void *userdata) {
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"DumpCache() response 'dump' field not an array");
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
sd_json_variant *i;
JSON_VARIANT_ARRAY_FOREACH(i, d) {
diff --git a/src/run/run.c b/src/run/run.c
index b73e292514..fe61839058 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -1886,7 +1886,7 @@ static int print_unit_invocation(const char *unit, sd_id128_t invocation_id) {
assert(unit);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
if (sd_id128_is_null(invocation_id))
log_info("Running as unit: %s", unit);
else
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c
index 87aa11ccdf..4c0195a41e 100644
--- a/src/shared/bootspec.c
+++ b/src/shared/bootspec.c
@@ -1936,7 +1936,7 @@ int show_boot_entries(const BootConfig *config, sd_json_format_flags_t json_form
assert(config);
- if (!FLAGS_SET(json_format, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(json_format)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
for (size_t i = 0; i < config->n_entries; i++) {
diff --git a/src/shared/format-table.c b/src/shared/format-table.c
index f5ef7175a3..5f05247438 100644
--- a/src/shared/format-table.c
+++ b/src/shared/format-table.c
@@ -3124,7 +3124,7 @@ int table_print_json(Table *t, FILE *f, sd_json_format_flags_t flags) {
assert(t);
- if (flags & SD_JSON_FORMAT_OFF) /* If JSON output is turned off, use regular output */
+ if (!sd_json_format_enabled(flags)) /* If JSON output is turned off, use regular output */
return table_print(t, f);
if (!f)
diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c
index fcf29a99d3..0adfab253c 100644
--- a/src/sysext/sysext.c
+++ b/src/sysext/sysext.c
@@ -2222,7 +2222,7 @@ static int verb_list(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to discover images: %m");
- if ((arg_json_format_flags & SD_JSON_FORMAT_OFF) && hashmap_isempty(images)) {
+ if (hashmap_isempty(images) && !sd_json_format_enabled(arg_json_format_flags)) {
log_info("No OS extensions found.");
return 0;
}
diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h
index dbe9fa035e..5792dd8106 100644
--- a/src/systemd/_sd-common.h
+++ b/src/systemd/_sd-common.h
@@ -45,6 +45,10 @@ typedef void (*_sd_destroy_t)(void *userdata);
# define _sd_pure_ __attribute__((__pure__))
#endif
+#ifndef _sd_const_
+# define _sd_const_ __attribute__((__const__))
+#endif
+
/* Note that strictly speaking __deprecated__ has been available before GCC 6. However, starting with GCC 6
* it also works on enum values, which we are interested in. Since this is a developer-facing feature anyway
* (as opposed to build engineer-facing), let's hence conditionalize this to gcc 6, given that the developers
diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index 7573991c20..7be690400d 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -117,24 +117,24 @@ int sd_id128_get_invocation_app_specific(sd_id128_t app_id, sd_id128_t *ret);
#define SD_ID128_MAKE_UUID_STR(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
#a #b #c #d "-" #e #f "-" #g #h "-" #i #j "-" #k #l #m #n #o #p
-_sd_pure_ static __inline__ int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
+_sd_const_ static __inline__ int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
return a.qwords[0] == b.qwords[0] && a.qwords[1] == b.qwords[1];
}
int sd_id128_string_equal(const char *s, sd_id128_t id);
-_sd_pure_ static __inline__ int sd_id128_is_null(sd_id128_t a) {
+_sd_const_ static __inline__ int sd_id128_is_null(sd_id128_t a) {
return a.qwords[0] == 0 && a.qwords[1] == 0;
}
-_sd_pure_ static __inline__ int sd_id128_is_allf(sd_id128_t a) {
+_sd_const_ static __inline__ int sd_id128_is_allf(sd_id128_t a) {
return a.qwords[0] == UINT64_C(0xFFFFFFFFFFFFFFFF) && a.qwords[1] == UINT64_C(0xFFFFFFFFFFFFFFFF);
}
#define SD_ID128_NULL ((const sd_id128_t) { .qwords = { 0, 0 }})
#define SD_ID128_ALLF ((const sd_id128_t) { .qwords = { UINT64_C(0xFFFFFFFFFFFFFFFF), UINT64_C(0xFFFFFFFFFFFFFFFF) }})
-_sd_pure_ static __inline__ int sd_id128_in_setv(sd_id128_t a, va_list ap) {
+_sd_const_ static __inline__ int sd_id128_in_setv(sd_id128_t a, va_list ap) {
for (;;) {
sd_id128_t b = va_arg(ap, sd_id128_t);
@@ -146,7 +146,7 @@ _sd_pure_ static __inline__ int sd_id128_in_setv(sd_id128_t a, va_list ap) {
}
}
-_sd_pure_ static __inline__ int sd_id128_in_set_sentinel(sd_id128_t a, ...) {
+_sd_const_ static __inline__ int sd_id128_in_set_sentinel(sd_id128_t a, ...) {
va_list ap;
int r;
diff --git a/src/systemd/sd-json.h b/src/systemd/sd-json.h
index f3c9a27257..02c5843f07 100644
--- a/src/systemd/sd-json.h
+++ b/src/systemd/sd-json.h
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
@@ -342,6 +343,10 @@ int sd_json_variant_unhex(sd_json_variant *v, void **ret, size_t *ret_size);
const char* sd_json_variant_type_to_string(sd_json_variant_type_t t);
sd_json_variant_type_t sd_json_variant_type_from_string(const char *s);
+__extension__ _sd_const_ static __inline__ bool sd_json_format_enabled(sd_json_format_flags_t flags) {
+ return !(flags & SD_JSON_FORMAT_OFF);
+}
+
_SD_END_DECLARATIONS;
#endif
diff --git a/src/sysupdate/sysupdate.c b/src/sysupdate/sysupdate.c
index 40a274b879..2bdd71e742 100644
--- a/src/sysupdate/sysupdate.c
+++ b/src/sysupdate/sysupdate.c
@@ -585,7 +585,7 @@ static int context_show_version(Context *c, const char *version) {
if (arg_json_format_flags & (SD_JSON_FORMAT_OFF|SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
(void) pager_open(arg_pager_flags);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (!sd_json_format_enabled(arg_json_format_flags))
printf("%s%s%s Version: %s\n"
" State: %s%s%s\n"
"Installed: %s%s\n"
@@ -784,7 +784,7 @@ static int context_show_version(Context *c, const char *version) {
if (!have_sha256)
(void) table_hide_column_from_display(t, 12);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
printf("%s%s%s Version: %s\n"
" State: %s%s%s\n"
"Installed: %s%s%s%s%s\n"
@@ -873,7 +873,7 @@ static int context_vacuum(
disabled_count++;
}
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
if (count > 0 && disabled_count > 0)
log_info("Removed %i instances, and %zu disabled transfers.", count, disabled_count);
else if (count > 0)
@@ -1157,7 +1157,7 @@ static int verb_list(int argc, char **argv, void *userdata) {
if (version)
return context_show_version(context, version);
- else if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ else if (!sd_json_format_enabled(arg_json_format_flags))
return context_show_table(context);
else {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *json = NULL;
@@ -1351,7 +1351,7 @@ static int verb_check_new(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
if (!context->candidate) {
log_debug("No candidate found.");
return EXIT_FAILURE;
@@ -1611,7 +1611,7 @@ static int verb_components(int argc, char **argv, void *userdata) {
strv_sort(z);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
if (!has_default_component && set_isempty(names)) {
log_info("No components defined.");
return 0;
diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c
index 0a1da3ed31..30f34b4958 100644
--- a/src/udev/udevadm-info.c
+++ b/src/udev/udevadm-info.c
@@ -453,9 +453,7 @@ static int export_devices(sd_device_enumerator *e) {
pager_open(arg_pager_flags);
FOREACH_DEVICE_AND_SUBSYSTEM(e, d)
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF)
- (void) print_record(d, NULL);
- else {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
r = record_to_json(d, &v);
@@ -463,7 +461,8 @@ static int export_devices(sd_device_enumerator *e) {
return r;
(void) sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
- }
+ } else
+ (void) print_record(d, NULL);
return 0;
}
@@ -629,9 +628,7 @@ static int query_device(QueryType query, sd_device* device) {
return 0;
case QUERY_ALL:
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF)
- return print_record(device, NULL);
- else {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
r = record_to_json(device, &v);
@@ -639,7 +636,8 @@ static int query_device(QueryType query, sd_device* device) {
return r;
(void) sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
- }
+ } else
+ return print_record(device, NULL);
return 0;
@@ -1229,10 +1227,10 @@ int info_main(int argc, char *argv[], void *userdata) {
if (action == ACTION_QUERY)
r = query_device(query, device);
else if (action == ACTION_ATTRIBUTE_WALK) {
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF)
- r = print_device_chain(device);
- else
+ if (sd_json_format_enabled(arg_json_format_flags))
r = print_device_chain_in_json(device);
+ else
+ r = print_device_chain(device);
} else if (action == ACTION_TREE)
r = print_tree(device);
else
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c
index d74251fd86..16c8f385d6 100644
--- a/src/userdb/userdbctl.c
+++ b/src/userdb/userdbctl.c
@@ -1287,7 +1287,7 @@ static int parse_argv(int argc, char *argv[]) {
if (r <= 0)
return r;
- arg_output = FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) ? _OUTPUT_INVALID : OUTPUT_JSON;
+ arg_output = sd_json_format_enabled(arg_json_format_flags) ? OUTPUT_JSON : _OUTPUT_INVALID;
break;
case 'j':
diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c
index b6c6c0da42..76c9e4850a 100644
--- a/src/varlinkctl/varlinkctl.c
+++ b/src/varlinkctl/varlinkctl.c
@@ -287,7 +287,7 @@ static int verb_info(int argc, char *argv[], void *userdata) {
pager_open(arg_pager_flags);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
static const sd_json_dispatch_field dispatch_table[] = {
{ "vendor", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(GetInfoData, vendor), SD_JSON_MANDATORY },
{ "product", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(GetInfoData, product), SD_JSON_MANDATORY },
@@ -426,7 +426,7 @@ static int verb_introspect(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) || list_methods) {
+ if (!sd_json_format_enabled(arg_json_format_flags) || list_methods) {
static const sd_json_dispatch_field dispatch_table[] = {
{ "description", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, 0, SD_JSON_MANDATORY },
{}
@@ -478,7 +478,7 @@ static int verb_introspect(int argc, char *argv[], void *userdata) {
strv_sort_uniq(methods);
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ if (!sd_json_format_enabled(arg_json_format_flags))
strv_print(methods);
else {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
@@ -539,7 +539,7 @@ static int verb_call(int argc, char *argv[], void *userdata) {
parameter = argc > 3 && !streq(argv[3], "-") ? argv[3] : NULL;
/* No JSON mode explicitly configured? Then default to the same as -j */
- if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!sd_json_format_enabled(arg_json_format_flags)) {
arg_json_format_flags &= ~SD_JSON_FORMAT_OFF;
arg_json_format_flags |= SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
}