[apparmor] [PATCH v2 19/42] parser: Remove exits from features code

Tyler Hicks tyhicks at canonical.com
Fri Mar 6 21:48:35 UTC 2015


This is done in preparation for moving the features code to a library.

Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
---
 parser/features.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/parser/features.c b/parser/features.c
index ccc238d..2b81564 100644
--- a/parser/features.c
+++ b/parser/features.c
@@ -102,6 +102,7 @@ static int features_dir_cb(DIR *dir, const char *name, struct stat *st,
 		PDEBUG("Opened features \"%s\"\n", name);
 		if (st->st_size > remaining) {
 			PDEBUG("Feature buffer full.");
+			errno = ENOBUFS;
 			return -1;
 		}
 
@@ -128,17 +129,17 @@ static int features_dir_cb(DIR *dir, const char *name, struct stat *st,
 	return 0;
 }
 
-static char *handle_features_dir(const char *filename, char *buffer, int size,
-				 char *pos)
+static int handle_features_dir(const char *filename, char *buffer, int size,
+			       char *pos)
 {
 	struct features_struct fst = { buffer, size, pos };
 
 	if (dirat_for_each(NULL, filename, &fst, features_dir_cb)) {
 		PDEBUG("Failed evaluating %s\n", filename);
-		exit(1);
+		return -1;
 	}
 
-	return fst.pos;
+	return 0;
 }
 
 static int load_features_file(const char *name, char *buffer, size_t size)
@@ -175,6 +176,7 @@ int aa_features_new(aa_features **features, const char *path)
 {
 	struct stat stat_file;
 	aa_features *f;
+	int retval;
 
 	*features = NULL;
 
@@ -188,9 +190,10 @@ int aa_features_new(aa_features **features, const char *path)
 	}
 	aa_features_ref(f);
 
-	if (S_ISDIR(stat_file.st_mode)) {
-		handle_features_dir(path, f->string, STRING_SIZE, f->string);
-	} else if (load_features_file(path, f->string, STRING_SIZE)) {
+	retval = S_ISDIR(stat_file.st_mode) ?
+		 handle_features_dir(path, f->string, STRING_SIZE, f->string) :
+		 load_features_file(path, f->string, STRING_SIZE);
+	if (retval) {
 		int save = errno;
 
 		aa_features_unref(f);
-- 
2.1.4




More information about the AppArmor mailing list