From f61fd4206138e1f58007b9f8a8d00bdbe5c82b33 Mon Sep 17 00:00:00 2001 From: Alex Murray Date: Fri, 25 Aug 2023 09:17:21 +0930 Subject: [PATCH] binutils/aa_status.c: quiet verbose outputs when --json is specified By default aa-status outputs with --verbose enabled - if --json is also specified then aa-status would currently output in its first line "apparmor module is loaded.": aa-status --json | head -n1 apparmor module is loaded. And only after this the actual json output would follow. This then results in failures to parse this JSON output: aa-status --json | jq . parse error: Invalid numeric literal at line 1, column 9 This in turn then breaks tools / tests which expect the output of aa-status --json to be purely json - e.g: https://salsa.debian.org/apparmor-team/apparmor-profiles-extra/-/blob/debian/unstable/debian/tests/policy-is-loaded#L12 So ensure dprintf() etc do not output when --json is specified to restrict the output of aa-status to pure JSON. Signed-off-by: Alex Murray --- binutils/aa_status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binutils/aa_status.c b/binutils/aa_status.c index 601600a51..2bc33a763 100644 --- a/binutils/aa_status.c +++ b/binutils/aa_status.c @@ -129,13 +129,13 @@ const char *process_statuses[] = {"enforce", "complain", "prompt", "kill", "unco #define dprintf(...) \ do { \ - if (verbose) \ + if (verbose && !opt_json) \ printf(__VA_ARGS__); \ } while (0) #define dfprintf(...) \ do { \ - if (verbose) \ + if (verbose && !opt_json) \ fprintf(__VA_ARGS__); \ } while (0)