mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 00:14:44 +01:00
aa-status: fix json generation
- previously, aa-status --json --show profiles would return non-standard json - adding the --pretty flag would crash completely - closes #470 Things done: - removed trailing ", " in json generation - generate json seperator (", ") for each new json field (profiles/processes) after the header if json is enabled Tested on NixOS and apparmor 4.0.3 base, but should work on any version the patch applies on.
This commit is contained in:
parent
5fb91616e3
commit
4f006a660c
1 changed files with 13 additions and 3 deletions
|
@ -541,7 +541,12 @@ static int compare_processes_by_executable(const void *a, const void *b) {
|
|||
|
||||
static void json_header(FILE *outf)
|
||||
{
|
||||
fprintf(outf, "{\"version\": \"%s\", ", aa_status_json_version);
|
||||
fprintf(outf, "{\"version\": \"%s\"", aa_status_json_version);
|
||||
}
|
||||
|
||||
static void json_seperator(FILE *outf)
|
||||
{
|
||||
fprintf(outf, ", ");
|
||||
}
|
||||
|
||||
static void json_footer(FILE *outf)
|
||||
|
@ -609,7 +614,7 @@ static int detailed_profiles(FILE *outf, filters_t *filters, bool json,
|
|||
free_profiles(filtered, nfiltered);
|
||||
}
|
||||
if (json)
|
||||
fprintf(outf, "}, ");
|
||||
fprintf(outf, "}");
|
||||
|
||||
return AA_EXIT_ENABLED;
|
||||
}
|
||||
|
@ -702,7 +707,7 @@ static int detailed_processes(FILE *outf, filters_t *filters, bool json,
|
|||
fprintf(outf, "]");
|
||||
}
|
||||
|
||||
fprintf(outf, "}\n");
|
||||
fprintf(outf, "}");
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -1030,6 +1035,8 @@ int main(int argc, char **argv)
|
|||
if (opt_json)
|
||||
json_header(outf);
|
||||
if (opt_show & SHOW_PROFILES) {
|
||||
if (opt_json)
|
||||
json_seperator(outf);
|
||||
if (opt_count) {
|
||||
ret = simple_filtered_count(outf, &filters,
|
||||
profiles, nprofiles);
|
||||
|
@ -1042,6 +1049,9 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (opt_show & SHOW_PROCESSES) {
|
||||
if (opt_json)
|
||||
json_seperator(outf);
|
||||
|
||||
struct process *processes = NULL;
|
||||
size_t nprocesses = 0;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue