mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-28 12:58:07 +00:00
aa-status: allow profile/process counts to go to a file
Make it so the output options that count profiles and processes can be output to a file. This does not add a user option to do so Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
66279ea1c7
commit
a455b50c66
@ -407,11 +407,12 @@ static int filter_processes(struct process *processes,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* simple_filtered_count - count the number of profiles with mode == filter
|
* simple_filtered_count - count the number of profiles with mode == filter
|
||||||
|
* @outf: output file destination
|
||||||
* @filter: mode string to filter profiles on
|
* @filter: mode string to filter profiles on
|
||||||
*
|
*
|
||||||
* Return: 0 on success, else shell error code
|
* Return: 0 on success, else shell error code
|
||||||
*/
|
*/
|
||||||
static int simple_filtered_count(const char *filter) {
|
static int simple_filtered_count(FILE *outf, const char *filter) {
|
||||||
size_t n;
|
size_t n;
|
||||||
struct profile *profiles;
|
struct profile *profiles;
|
||||||
int ret;
|
int ret;
|
||||||
@ -421,7 +422,7 @@ static int simple_filtered_count(const char *filter) {
|
|||||||
size_t nfiltered;
|
size_t nfiltered;
|
||||||
struct profile *filtered = NULL;
|
struct profile *filtered = NULL;
|
||||||
ret = filter_profiles(profiles, n, filter, &filtered, &nfiltered);
|
ret = filter_profiles(profiles, n, filter, &filtered, &nfiltered);
|
||||||
printf("%zd\n", nfiltered);
|
fprintf(outf, "%zd\n", nfiltered);
|
||||||
free_profiles(filtered, nfiltered);
|
free_profiles(filtered, nfiltered);
|
||||||
}
|
}
|
||||||
free_profiles(profiles, n);
|
free_profiles(profiles, n);
|
||||||
@ -430,11 +431,12 @@ static int simple_filtered_count(const char *filter) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* simple_filtered_process_count - count processes with mode == filter
|
* simple_filtered_process_count - count processes with mode == filter
|
||||||
|
* @outf: output file destination
|
||||||
* @filter: mode string to filter processes on
|
* @filter: mode string to filter processes on
|
||||||
*
|
*
|
||||||
* Return: 0 on success, else shell error code
|
* Return: 0 on success, else shell error code
|
||||||
*/
|
*/
|
||||||
static int simple_filtered_process_count(const char *filter) {
|
static int simple_filtered_process_count(FILE *outf, const char *filter) {
|
||||||
size_t nprocesses, nprofiles;
|
size_t nprocesses, nprofiles;
|
||||||
struct profile *profiles = NULL;
|
struct profile *profiles = NULL;
|
||||||
struct process *processes = NULL;
|
struct process *processes = NULL;
|
||||||
@ -448,7 +450,7 @@ static int simple_filtered_process_count(const char *filter) {
|
|||||||
size_t nfiltered;
|
size_t nfiltered;
|
||||||
struct process *filtered = NULL;
|
struct process *filtered = NULL;
|
||||||
ret = filter_processes(processes, nprocesses, filter, &filtered, &nfiltered);
|
ret = filter_processes(processes, nprocesses, filter, &filtered, &nfiltered);
|
||||||
printf("%zd\n", nfiltered);
|
fprintf(outf, "%zd\n", nfiltered);
|
||||||
free_processes(filtered, nfiltered);
|
free_processes(filtered, nfiltered);
|
||||||
}
|
}
|
||||||
free_profiles(profiles, nprofiles);
|
free_profiles(profiles, nprofiles);
|
||||||
@ -699,22 +701,22 @@ static char **parse_args(int argc, char **argv)
|
|||||||
print_usage(argv[0], false);
|
print_usage(argv[0], false);
|
||||||
break;
|
break;
|
||||||
case ARG_PROFILED:
|
case ARG_PROFILED:
|
||||||
exit(simple_filtered_count(NULL));
|
exit(simple_filtered_count(stdout, NULL));
|
||||||
break;
|
break;
|
||||||
case ARG_ENFORCED:
|
case ARG_ENFORCED:
|
||||||
exit(simple_filtered_count("enforce"));
|
exit(simple_filtered_count(stdout, "enforce"));
|
||||||
break;
|
break;
|
||||||
case ARG_COMPLAIN:
|
case ARG_COMPLAIN:
|
||||||
exit(simple_filtered_count("complain"));
|
exit(simple_filtered_count(stdout, "complain"));
|
||||||
break;
|
break;
|
||||||
case ARG_UNCONFINED:
|
case ARG_UNCONFINED:
|
||||||
exit(simple_filtered_count("unconfined"));
|
exit(simple_filtered_count(stdout, "unconfined"));
|
||||||
break;
|
break;
|
||||||
case ARG_KILL:
|
case ARG_KILL:
|
||||||
exit(simple_filtered_count("kill"));
|
exit(simple_filtered_count(stdout, "kill"));
|
||||||
break;
|
break;
|
||||||
case ARG_PS_MIXED:
|
case ARG_PS_MIXED:
|
||||||
exit(simple_filtered_process_count("mixed"));
|
exit(simple_filtered_process_count(stdout, "mixed"));
|
||||||
break;
|
break;
|
||||||
case ARG_JSON:
|
case ARG_JSON:
|
||||||
exit(detailed_output(stdout, true));
|
exit(detailed_output(stdout, true));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user