summaryrefslogtreecommitdiffstats
path: root/src/home/homectl.c
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/home/homectl.c
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/home/homectl.c')
-rw-r--r--src/home/homectl.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/home/homectl.c b/src/home/homectl.c
index 11270d7edb..b3aacbcbcf 100644
--- a/src/home/homectl.c
+++ b/src/home/homectl.c
@@ -203,7 +203,7 @@ static int list_homes(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
- if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (!table_isempty(table) || sd_json_format_enabled(arg_json_format_flags)) {
r = table_set_sort(table, (size_t) 0);
if (r < 0)
return table_log_sort_error(r);
@@ -213,7 +213,7 @@ static int list_homes(int argc, char *argv[], void *userdata) {
return r;
}
- if (arg_legend && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ if (arg_legend && !sd_json_format_enabled(arg_json_format_flags)) {
if (table_isempty(table))
printf("No home areas.\n");
else
@@ -671,7 +671,7 @@ static void dump_home_record(UserRecord *hr) {
log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr->user_name);
}
- if (arg_json_format_flags & SD_JSON_FORMAT_OFF)
+ if (!sd_json_format_enabled(arg_json_format_flags))
user_record_show(hr, true);
else {
_cleanup_(user_record_unrefp) UserRecord *stripped = NULL;