]> git.ipfire.org Git - thirdparty/systemd.git/commit
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)
commit23441a3d882930b854b827172343c4222a2c9935
tree5751d9934838bfa61f31d5bf3611064afe8f660e
parentdc32b09b70c9bb20821df92ac82ace83d8a968e2
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.
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