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);
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;
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);
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);
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");
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;
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.");
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"))
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;
}
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) {
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);
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);
}
}
- 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);
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");
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;
}
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;
}
}
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) {
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))
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))
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;
}
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;
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());
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);
/* 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++) {
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);
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;
}
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);
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
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;
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;
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",
}
}
- 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 {
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));
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);
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;
_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);
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);
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;
}
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);
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));
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);
/* 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);
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);
(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");
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);
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"
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);
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) {
}
}
- 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
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++) {
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)
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);
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)
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)
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)
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))
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])) {
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 {
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;
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
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) {
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) {
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
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++) {
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)
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;
}
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
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
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"
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"
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)
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;
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;
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;
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);
return r;
(void) sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
- }
+ } else
+ (void) print_record(d, NULL);
return 0;
}
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);
return r;
(void) sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
- }
+ } else
+ return print_record(device, NULL);
return 0;
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
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':
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 },
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 },
{}
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;
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;
}