mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
parser: add the ability to print what flags are set in option flag tables
Add the ability to show which warnings are enabled by specifying "show" as an to the --dump, --warn, and --Optimize options Eg. --warn=show MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600 Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
db07b131b5
commit
6e6f99e0b8
3 changed files with 27 additions and 2 deletions
|
@ -112,12 +112,30 @@ void print_flag_table(optflag_table_t *table)
|
|||
longest = strlen(table[i].option);
|
||||
}
|
||||
|
||||
printf("%-*s \t%s\n", longest, " show", "show flags that have been set and exit");
|
||||
for (i = 0; table[i].option; i++) {
|
||||
printf("%5s%-*s \t%s\n", (table[i].control & 1) ? "[no-]" : "",
|
||||
longest, table[i].option, table[i].desc);
|
||||
}
|
||||
}
|
||||
|
||||
void print_flags(const char *prefix, optflag_table_t *table, dfaflags_t flags)
|
||||
{
|
||||
int i, count = 0;
|
||||
|
||||
printf("%s=", prefix);
|
||||
for (i = 0; table[i].option; i++) {
|
||||
if ((table[i].flags & flags) == table[i].flags) {
|
||||
if (count)
|
||||
printf(", ");
|
||||
printf("%s", table[i].option);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int handle_flag_table(optflag_table_t *table, const char *optarg,
|
||||
dfaflags_t *flags)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ typedef struct {
|
|||
extern optflag_table_t dumpflag_table[];
|
||||
extern optflag_table_t optflag_table[];
|
||||
|
||||
void print_flags(const char *prefix, optflag_table_t *table, dfaflags_t flags);
|
||||
int handle_flag_table(optflag_table_t *table, const char *optarg,
|
||||
dfaflags_t *flags);
|
||||
void flagtable_help(const char *name, const char *header, const char *command,
|
||||
|
|
|
@ -536,6 +536,8 @@ static int process_arg(int c, char *optarg)
|
|||
skip_read_cache = 1;
|
||||
if (!optarg) {
|
||||
dump_vars = 1;
|
||||
} else if (strcmp(optarg, "show") == 0) {
|
||||
print_flags("dump", dumpflag_table, dfaflags);
|
||||
} else if (strcmp(optarg, "variables") == 0) {
|
||||
dump_vars = 1;
|
||||
} else if (strcmp(optarg, "expanded-variables") == 0) {
|
||||
|
@ -548,7 +550,9 @@ static int process_arg(int c, char *optarg)
|
|||
}
|
||||
break;
|
||||
case 'O':
|
||||
if (!handle_flag_table(optflag_table, optarg,
|
||||
if (strcmp(optarg, "show") == 0) {
|
||||
print_flags("Optimize", optflag_table, dfaflags);
|
||||
} else if (!handle_flag_table(optflag_table, optarg,
|
||||
&dfaflags)) {
|
||||
PERROR("%s: Invalid --Optimize option %s\n",
|
||||
progname, optarg);
|
||||
|
@ -687,7 +691,9 @@ static int process_arg(int c, char *optarg)
|
|||
skip_mode_force = 1;
|
||||
break;
|
||||
case ARG_WARN:
|
||||
if (!handle_flag_table(warnflag_table, optarg,
|
||||
if (strcmp(optarg, "show") == 0) {
|
||||
print_flags("warn", warnflag_table, warnflags);
|
||||
} else if (!handle_flag_table(warnflag_table, optarg,
|
||||
&warnflags)) {
|
||||
PERROR("%s: Invalid --warn option %s\n",
|
||||
progname, optarg);
|
||||
|
|
Loading…
Add table
Reference in a new issue