]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-json,tree-wide: add sd_json_format_enabled() and use it everwhere 34633/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 4 Oct 2024 16:08:35 +0000 (18:08 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 28 Oct 2024 08:23:07 +0000 (09:23 +0100)
We often used a pattern like if (!FLAGS_SET(flags, SD_JSON_FORMAT_OFF)),
which is rather verbose and also contains a double negative, which we try
to avoid. Add a little helper to avoid an explicit bit check.

This change clarifies an aditional thing: in some cases we treated
SD_JSON_FORMAT_OFF as a flag (flags & SD_JSON_FORMAT_OFF), while in other cases
we treated it as an independent enum value (flags == SD_JSON_FORMAT_OFF).
In the first form, flags like SD_JSON_FORMAT_SSE do _not_ turn the json
output on, while in the second form they do. Let's use the first form
everywhere.

No functional change intended.

Initially I wasn't sure if this helper should be made public or just internal,
but it seems such a common pattern that if we expose the flags, we might just
as well expose it too, to make life easier for any consumers.

31 files changed:
src/analyze/analyze-fdstore.c
src/analyze/analyze-inspect-elf.c
src/analyze/analyze-plot.c
src/analyze/analyze-security.c
src/analyze/analyze.c
src/boot/bootctl-status.c
src/boot/measure.c
src/busctl/busctl.c
src/creds/creds.c
src/dissect/dissect.c
src/home/homectl.c
src/hostname/hostnamectl.c
src/import/importctl.c
src/journal/journalctl-misc.c
src/kernel-install/kernel-install.c
src/libsystemd/sd-json/sd-json.c
src/login/loginctl.c
src/network/networkctl-description.c
src/network/networkctl-lldp.c
src/partition/repart.c
src/pcrlock/pcrlock.c
src/resolve/resolvectl.c
src/run/run.c
src/shared/bootspec.c
src/shared/format-table.c
src/sysext/sysext.c
src/systemd/sd-json.h
src/sysupdate/sysupdate.c
src/udev/udevadm-info.c
src/userdb/userdbctl.c
src/varlinkctl/varlinkctl.c

index 4cf015ab44c9abaa012715eb032b97753caea314..e7e273e218badd5267ba9356cb28a06b70ab38c7 100644 (file)
@@ -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);
index 1ae73041630fed6cb2755eae6ec8287f3fe634f1..01824d5eaba8a7a3512a3a94a7ed133dc5a97892 100644 (file)
@@ -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;
index 78aeff1b62a27138bd8395c1bf0391abb34f67ef..d3316651c9e6d95c3b7900e0639b8e5cfef5dad6 100644 (file)
@@ -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);
index 874fff14b499f6a8527ff48dcecac0ff3c6a788b..aefd4f6122eb6654a794a644f73e79bedeb2b514 100644 (file)
@@ -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;
 
index 5aba273ca6ce926de52c6392f46cde5a6873e3d0..0db3547a49d242c5cd5a23995267c01e755aff37 100644 (file)
@@ -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"))
index 61d76dd67954cb94e020783820ed9f50bf0741a5..c548ddcee537c3bf32a955da3965bd9eebb8f36c 100644 (file)
@@ -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;
         }
index 38bc2afda53909d31327cbfbcc1d15cb1bcab2df..3ad49e9d740d1712a333fd35081d27f70e2d3f63 100644 (file)
@@ -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);
 
index 1e352a37294ef6d8dbc9747f4280bd4ca048b9fd..4eeb4a98e52d5e542fe08d41d9b7f72733cbbae7 100644 (file)
@@ -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))
index bb59db37fc9bd6522bdcb4de96869f9330169d25..b24a84eaa6489e9c9d33a2b1fa80c71fe08aa4fd 100644 (file)
@@ -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;
 
index 1cad45c8ff94b08091aa3333b9241a3aaa2ad025..78a830d574b2c30fbc3589ce83c768954ba8e7a6 100644 (file)
@@ -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;
         }
index 11270d7edb82c0b5b8e4f2f5f219566d4e2d0bd0..b3aacbcbcf9e356c0566f52fbb35d2541c811172 100644 (file)
@@ -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;
index 4bbfa670b766898880d7a146ae671aa467ef15dd..a537312d25727c84a6d0f5b3b33aa569f816a9a4 100644 (file)
@@ -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;
index 0ddfa988a6f00fff3aba73432a4e1beea00895db..1ddba76b09cc0e631eee05043b47c2f71eb66cf9 100644 (file)
@@ -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",
index 5a1f31122184eaf1ed009c4035493e8c6395ac15..3dea69d9fb3dd5ea018afe68f542191909b112da 100644 (file)
@@ -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 {
index f4f30df07dd5505cb93a76fc4265f1051c020f43..f059f5dc763fe2c75a915a6532a29c84831344b1 100644 (file)
@@ -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));
index 297052bdb417efadac0ac0786429c848c58f4988..5e9c1ba15bed40379f1a05ff3304f11737ab245d 100644 (file)
@@ -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);
index cdb017a9312d84c6876d3a0fa79544b8674bf930..bda69de076289cf3a14b7ea45ee77afa55bce7cb 100644 (file)
@@ -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;
index 14ce55bfae5b9781433ef1a416db4d8b721a5eb8..410751f9e78e7cf22acf0281ebbf286ad7116caf 100644 (file)
@@ -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);
index 7836cb5ccf54e92cafeb169f24e4121f71dafa77..8a10562b0d1bdfe2f125b7bd873ed056604866d9 100644 (file)
@@ -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);
index 65b50e346f9045d84d42743f77a50096be24a8ba..1acd5af38c398a4540f0b5b2f5ff71e6485a059d 100644 (file)
@@ -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);
index 46f285d54ab694cd4ae87302fac17d47b313bcfc..c1915761ee886317a44349f0e6669687f97b9bd5 100644 (file)
@@ -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++) {
index 0204fdf16f78b92ee6f4b439cd25b80edaebb110..62354b47842dc3579a3559630f342626decbf745 100644 (file)
@@ -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) {
index b73e2925143638a117cb29d409fc72ab7c8c321b..fe6183905886e1cda4248e1fbc07fc1929b789e9 100644 (file)
@@ -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
index 87aa11ccdfc7880f4062e80fd3de1108381195db..4c0195a41ef3a33ec53320a9cf4559f6635cdb59 100644 (file)
@@ -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++) {
index f5ef7175a324fd07aacbe448c1045d7817b5c7f3..5f05247438ade1dc1aedfefc379f1ac962a8827c 100644 (file)
@@ -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)
index fcf29a99d311fb175dba2908cc736ac8ec1f5484..0adfab253cbd5f43a7d2d5979129f1f8c6c4d103 100644 (file)
@@ -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;
         }
index f3c9a272572e3da0c94e54ad1292104ad019dd08..02c5843f0792359e8a54b2d7a834dd54e88270ad 100644 (file)
@@ -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
index 40a274b879140b368c1de11bfe5c6e31bba2d34e..2bdd71e74272e64ae8c17b25b09317d064769762 100644 (file)
@@ -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;
index 0a1da3ed310e17c805524b033ae23fd96ef42879..30f34b495850e3a5ab5a345621fab033671730e0 100644 (file)
@@ -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
index d74251fd86ec0e01f273a201628620fe8bb013d0..16c8f385d696bb6694dc7ebace8191126a390e05 100644 (file)
@@ -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':
index b6c6c0da4201f2da09d6020bfa9573c3ac00f960..76c9e4850a710e2dca96a0681f332fcf4e72714c 100644 (file)
@@ -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;
         }