Merge pull request #34633 from keszybz/sd-json-enum-formatting
Add sd_json_format_enabled() helper
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
|
||||
+7
-7
@@ -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))
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
+12
-12
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
+9
-11
@@ -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
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user