[apparmor] [PATCH 10/12] parser: Lift globals and print statements from create_cache()

Tyler Hicks tyhicks at canonical.com
Wed Dec 10 22:12:31 UTC 2014


With create_cache() headed for libapparmor, we can't use the show_cache
or write_cache globals. Also, PERROR() cannot be used.

Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
---
 parser/parser_main.c  |  1 +
 parser/policy_cache.c | 23 +++--------------------
 2 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/parser/parser_main.c b/parser/parser_main.c
index d10232e..33fb6e1 100644
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -914,6 +914,7 @@ int main(int argc, char *argv[])
 		} else if (!aa_policy_cache_is_valid(policy_cache)) {
 			if (write_cache && cond_clear_cache &&
 			    aa_policy_cache_create(policy_cache)) {
+				write_cache = 0;
 				skip_read_cache = 1;
 			} else if (!write_cache || !cond_clear_cache) {
 				if (show_cache)
diff --git a/parser/policy_cache.c b/parser/policy_cache.c
index 2aff6f6..39a0871 100644
--- a/parser/policy_cache.c
+++ b/parser/policy_cache.c
@@ -129,26 +129,9 @@ create_file:
 
 error:
 	/* does the dir exist? */
-	if (stat(policy_cache->path, &stat_file) == -1) {
-		if (mkdir(policy_cache->path, 0700) == 0)
-			goto create_file;
-		if (show_cache)
-			PERROR(_("Can't create cache directory: %s\n"),
-			       policy_cache->path);
-	} else if (!S_ISDIR(stat_file.st_mode)) {
-		if (show_cache)
-			PERROR(_("File in cache directory location: %s\n"),
-			       policy_cache->path);
-	} else {
-		if (show_cache)
-			PERROR(_("Can't update cache directory: %s\n"),
-			       policy_cache->path);
-	}
-
-	if (show_cache)
-		PERROR("Cache write disabled: cannot create %s\n",
-		       policy_cache->features_path);
-	write_cache = 0;
+	if (stat(policy_cache->path, &stat_file) == -1 && errno == ENOENT &&
+	    mkdir(policy_cache->path, 0700) == 0)
+		goto create_file;
 
 	return -1;
 }
-- 
2.1.0




More information about the AppArmor mailing list