[apparmor] [PATCH 04/11] Cleanup invert dfa control flag logic so that the flags are always positive
John Johansen
john.johansen at canonical.com
Tue Oct 19 01:20:36 BST 2010
The dfa flags currently are a weird mix of position and negative assertions.
Its cleaner just to have them all assert one way and let the cmd line
options apply them correctly.
---
parser/libapparmor_re/Makefile | 4 ++--
parser/libapparmor_re/apparmor_re.h | 8 ++++----
parser/libapparmor_re/regexp.y | 8 ++++----
parser/parser_main.c | 26 +++++++++++++-------------
4 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/parser/libapparmor_re/Makefile b/parser/libapparmor_re/Makefile
index 76d7473..4de254c 100644
--- a/parser/libapparmor_re/Makefile
+++ b/parser/libapparmor_re/Makefile
@@ -15,8 +15,8 @@ all : ${TARGET}
libapparmor_re.a: regexp.o
ar ${ARFLAGS} $@ $^
-regexp.o : regexp.cc
- $(LINK.cc) $^ -c -o $@
+regexp.o : regexp.cc apparmor_re.h
+ $(LINK.cc) $< -c -o $@
regexp.cc : regexp.y flex-tables.h
${BISON} -o $@ $<
diff --git a/parser/libapparmor_re/apparmor_re.h b/parser/libapparmor_re/apparmor_re.h
index 5af9a58..a17069b 100644
--- a/parser/libapparmor_re/apparmor_re.h
+++ b/parser/libapparmor_re/apparmor_re.h
@@ -13,13 +13,13 @@
typedef enum dfaflags {
DFA_CONTROL_EQUIV = 1 << 0,
- DFA_CONTROL_NO_TREE_NORMAL = 1 << 1,
- DFA_CONTROL_NO_TREE_SIMPLE = 1 << 2,
+ DFA_CONTROL_TREE_NORMAL = 1 << 1,
+ DFA_CONTROL_TREE_SIMPLE = 1 << 2,
DFA_CONTROL_TREE_LEFT = 1 << 3,
- DFA_CONTROL_NO_MINIMIZE = 1 << 4,
+ DFA_CONTROL_MINIMIZE = 1 << 4,
DFA_CONTROL_MINIMIZE_HASH_TRANS = 1 << 5,
DFA_CONTROL_MINIMIZE_HASH_PERMS = 1 << 6,
- DFA_CONTROL_NO_UNREACHABLE = 1 << 7,
+ DFA_CONTROL_REMOVE_UNREACHABLE = 1 << 7,
DFA_CONTROL_TRANS_HIGH = 1 << 8,
DFA_DUMP_TREE_STATS = 1 << 16,
diff --git a/parser/libapparmor_re/regexp.y b/parser/libapparmor_re/regexp.y
index 45946af..c95644b 100644
--- a/parser/libapparmor_re/regexp.y
+++ b/parser/libapparmor_re/regexp.y
@@ -913,7 +913,7 @@ Node *simplify_tree(Node *t, dfaflags_t flags)
bool modified;
do {
modified = false;
- if (!(flags & DFA_CONTROL_NO_TREE_NORMAL))
+ if (flags & DFA_CONTROL_TREE_NORMAL)
normalize_tree(t, dir);
t = simplify_tree_base(t, dir, modified);
if (modified)
@@ -1542,10 +1542,10 @@ DFA::DFA(Node *root, dfaflags_t flags) : root(root)
/* TODO Dump dfa with NODE mapping - or node to dfa mapping */
// ??????
- if (!(flags & DFA_CONTROL_NO_MINIMIZE))
+ if (flags & DFA_CONTROL_MINIMIZE)
minimize(flags);
- if (!(flags & DFA_CONTROL_NO_UNREACHABLE))
+ if (flags & DFA_CONTROL_REMOVE_UNREACHABLE)
remove_unreachable(flags);
}
@@ -2882,7 +2882,7 @@ extern "C" void *aare_create_dfa(aare_ruleset_t *rules, size_t *size, dfaflags_t
cerr << "\n\n";
}
- if (!(flags & DFA_CONTROL_NO_TREE_SIMPLE)) {
+ if (flags & DFA_CONTROL_TREE_SIMPLE) {
rules->root = simplify_tree(rules->root, flags);
if (flags & DFA_DUMP_SIMPLE_TREE) {
diff --git a/parser/parser_main.c b/parser/parser_main.c
index 2bc897f..6b02b73 100644
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -69,7 +69,7 @@ int binary_input = 0;
int names_only = 0;
int dump_vars = 0;
int dump_expanded_vars = 0;
-dfaflags_t dfaflags = DFA_CONTROL_MINIMIZE_HASH_TRANS | DFA_CONTROL_MINIMIZE_HASH_PERMS;
+dfaflags_t dfaflags = DFA_CONTROL_TREE_NORMAL | DFA_CONTROL_TREE_SIMPLE | DFA_CONTROL_MINIMIZE | DFA_CONTROL_MINIMIZE_HASH_TRANS | DFA_CONTROL_MINIMIZE_HASH_PERMS;
int conf_verbose = 0;
int conf_quiet = 0;
int kernel_load = 1;
@@ -395,30 +395,30 @@ static int process_args(int argc, char *argv[])
case 'O':
skip_read_cache = 1;
if (strcmp(optarg, "0") == 0) {
- dfaflags |= DFA_CONTROL_NO_TREE_NORMAL |
- DFA_CONTROL_NO_TREE_SIMPLE |
- DFA_CONTROL_NO_MINIMIZE |
- DFA_CONTROL_NO_UNREACHABLE;
+ dfaflags &= ~(DFA_CONTROL_TREE_NORMAL |
+ DFA_CONTROL_TREE_SIMPLE |
+ DFA_CONTROL_MINIMIZE |
+ DFA_CONTROL_REMOVE_UNREACHABLE);
} else if (strcmp(optarg, "equiv") == 0) {
dfaflags |= DFA_CONTROL_EQUIV;
} else if (strcmp(optarg, "no-equiv") == 0) {
dfaflags &= ~DFA_CONTROL_EQUIV;
} else if (strcmp(optarg, "expr-normalize") == 0) {
- dfaflags &= ~DFA_CONTROL_NO_TREE_NORMAL;
+ dfaflags |= DFA_CONTROL_TREE_NORMAL;
} else if (strcmp(optarg, "no-expr-normalize") == 0) {
- dfaflags |= DFA_CONTROL_NO_TREE_NORMAL;
+ dfaflags &= ~DFA_CONTROL_TREE_NORMAL;
} else if (strcmp(optarg, "expr-simplify") == 0) {
- dfaflags &= ~DFA_CONTROL_NO_TREE_SIMPLE;
+ dfaflags |= DFA_CONTROL_TREE_SIMPLE;
} else if (strcmp(optarg, "no-expr-simplify") == 0) {
- dfaflags |= DFA_CONTROL_NO_TREE_SIMPLE;
+ dfaflags &= ~DFA_CONTROL_TREE_SIMPLE;
} else if (strcmp(optarg, "expr-left-simplify") == 0) {
dfaflags |= DFA_CONTROL_TREE_LEFT;
} else if (strcmp(optarg, "expr-right-simplify") == 0) {
dfaflags &= ~DFA_CONTROL_TREE_LEFT;
} else if (strcmp(optarg, "minimize") == 0) {
- dfaflags &= ~DFA_CONTROL_NO_MINIMIZE;
+ dfaflags |= DFA_CONTROL_MINIMIZE;
} else if (strcmp(optarg, "no-minimize") == 0) {
- dfaflags |= DFA_CONTROL_NO_MINIMIZE;
+ dfaflags &= ~DFA_CONTROL_MINIMIZE;
} else if (strcmp(optarg, "hash-trans") == 0) {
dfaflags |= DFA_CONTROL_MINIMIZE_HASH_TRANS;
} else if (strcmp(optarg, "no-hash-trans") == 0) {
@@ -432,9 +432,9 @@ static int process_args(int argc, char *argv[])
} else if (strcmp(optarg, "trans-comp-high") == 0) {
dfaflags |= DFA_CONTROL_TRANS_HIGH;
} else if (strcmp(optarg, "remove-unreachable") == 0) {
- dfaflags &= ~DFA_CONTROL_NO_UNREACHABLE;
+ dfaflags |= DFA_CONTROL_REMOVE_UNREACHABLE;
} else if (strcmp(optarg, "no-remove-unreachable") == 0) {
- dfaflags |= DFA_CONTROL_NO_UNREACHABLE;
+ dfaflags &= ~DFA_CONTROL_REMOVE_UNREACHABLE;
} else {
PERROR("%s: Invalid --Optimize option %s\n",
progname, optarg);
--
1.7.1
More information about the AppArmor
mailing list