summaryrefslogtreecommitdiffstats
path: root/src/busctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-10-04 18:08:35 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-10-28 09:23:07 +0100
commit23441a3d882930b854b827172343c4222a2c9935 (patch)
tree5751d9934838bfa61f31d5bf3611064afe8f660e /src/busctl
parentsd-id128: mark functions as const, not pure (diff)
downloadsystemd-23441a3d882930b854b827172343c4222a2c9935.tar.xz
systemd-23441a3d882930b854b827172343c4222a2c9935.zip
sd-json,tree-wide: add sd_json_format_enabled() and use it everwhere
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.
Diffstat (limited to 'src/busctl')
-rw-r--r--src/busctl/busctl.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index 1e352a3729..4eeb4a98e5 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -1331,7 +1331,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
if (r < 0)
return log_error_errno(r, "Failed to get unique name: %m");
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Monitoring bus message stream.");
(void) sd_notify(/* unset_environment=false */ false, "READY=1");
@@ -1365,13 +1365,13 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
fflush(stdout);
if (arg_num_matches != UINT64_MAX && --arg_num_matches == 0) {
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Received requested number of matching messages, exiting.");
return 0;
}
if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected") > 0) {
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Connection terminated, exiting.");
return 0;
}
@@ -1384,7 +1384,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
r = sd_bus_wait(bus, arg_timeout > 0 ? arg_timeout : UINT64_MAX);
if (r == 0 && arg_timeout > 0) {
- if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
+ if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
log_info("Timed out waiting for messages, exiting.");
return 0;
}
@@ -1394,7 +1394,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
}
static int verb_monitor(int argc, char **argv, void *userdata) {
- return monitor(argc, argv, (arg_json_format_flags & SD_JSON_FORMAT_OFF) ? message_dump : message_json);
+ return monitor(argc, argv, sd_json_format_enabled(arg_json_format_flags) ? message_json : message_dump);
}
static int verb_capture(int argc, char **argv, void *userdata) {
@@ -2146,7 +2146,7 @@ static int call(int argc, char **argv, void *userdata) {
if (r > 0 || arg_quiet)
return 0;
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
@@ -2256,7 +2256,7 @@ static int get_property(int argc, char **argv, void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
- if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (sd_json_format_enabled(arg_json_format_flags)) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))