0fd1802
From 667fe9187c203ffcba855e821dff11c8f71ef000 Mon Sep 17 00:00:00 2001
0fd1802
From: Dan Walsh <dwalsh@redhat.com>
0fd1802
Date: Tue, 20 Sep 2011 15:39:51 -0400
0fd1802
Subject: [PATCH 2/6] setools-should-exit-with-an-error-status-if-it-gets-an
0fd1802
 error
0fd1802
0fd1802
---
0fd1802
 secmds/seinfo.c |   51 +++++++++++++++++++++++++++------------------------
0fd1802
 1 files changed, 27 insertions(+), 24 deletions(-)
0fd1802
0fd1802
diff --git a/secmds/seinfo.c b/secmds/seinfo.c
0fd1802
index fdf23e9..3088f88 100644
0fd1802
--- a/secmds/seinfo.c
0fd1802
+++ b/secmds/seinfo.c
0fd1802
@@ -827,7 +827,7 @@ static int print_sens(FILE * fp, const char *name, int expand, const apol_policy
0fd1802
  */
0fd1802
 static int print_cats(FILE * fp, const char *name, int expand, const apol_policy_t * policydb)
0fd1802
 {
0fd1802
-	int retval = 0;
0fd1802
+	int retval = -1;
0fd1802
 	apol_cat_query_t *query = NULL;
0fd1802
 	apol_vector_t *v = NULL;
0fd1802
 	const qpol_cat_t *cat_datum = NULL;
0fd1802
@@ -911,9 +911,10 @@ static int print_fsuse(FILE * fp, const char *type, const apol_policy_t * policy
0fd1802
 		fprintf(fp, "   %s\n", tmp);
0fd1802
 		free(tmp);
0fd1802
 	}
0fd1802
-	if (type && !apol_vector_get_size(v))
0fd1802
+	if (type && !apol_vector_get_size(v)) {
0fd1802
 		ERR(policydb, "No fs_use statement for filesystem of type %s.", type);
0fd1802
-
0fd1802
+		goto cleanup;
0fd1802
+	}
0fd1802
 	retval = 0;
0fd1802
       cleanup:
0fd1802
 	apol_fs_use_query_destroy(&query);
0fd1802
@@ -949,7 +950,6 @@ static int print_genfscon(FILE * fp, const char *type, const apol_policy_t * pol
0fd1802
 		ERR(policydb, "%s", strerror(ENOMEM));
0fd1802
 		goto cleanup;
0fd1802
 	}
0fd1802
-
0fd1802
 	if (apol_genfscon_query_set_filesystem(policydb, query, type))
0fd1802
 		goto cleanup;
0fd1802
 	if (apol_genfscon_get_by_query(policydb, query, &v))
0fd1802
@@ -967,8 +967,10 @@ static int print_genfscon(FILE * fp, const char *type, const apol_policy_t * pol
0fd1802
 		free(tmp);
0fd1802
 	}
0fd1802
 
0fd1802
-	if (type && !apol_vector_get_size(v))
0fd1802
+	if (type && !apol_vector_get_size(v)) {
0fd1802
 		ERR(policydb, "No genfscon statement for filesystem of type %s.", type);
0fd1802
+		goto cleanup;
0fd1802
+	}
0fd1802
 
0fd1802
 	retval = 0;
0fd1802
       cleanup:
0fd1802
@@ -1646,6 +1648,7 @@ cleanup:	// close and destroy iterators etc.
0fd1802
 
0fd1802
 int main(int argc, char **argv)
0fd1802
 {
0fd1802
+	int rc = 0;
0fd1802
 	int classes, types, attribs, roles, users, all, expand, stats, rt, optc, isids, bools, sens, cats, fsuse, genfs, netif,
0fd1802
 		node, port, permissives, polcaps, constrain, linebreaks;
0fd1802
 	apol_policy_t *policydb = NULL;
0fd1802
@@ -1851,46 +1854,46 @@ int main(int argc, char **argv)
0fd1802
 
0fd1802
 	/* display requested info */
0fd1802
 	if (stats || all)
0fd1802
-		print_stats(stdout, policydb);
0fd1802
+		rc = print_stats(stdout, policydb);
0fd1802
 	if (classes || all)
0fd1802
-		print_classes(stdout, class_name, expand, policydb);
0fd1802
+		rc = print_classes(stdout, class_name, expand, policydb);
0fd1802
 	if (types || all)
0fd1802
-		print_types(stdout, type_name, expand, policydb);
0fd1802
+		rc = print_types(stdout, type_name, expand, policydb);
0fd1802
 	if (attribs || all)
0fd1802
-		print_attribs(stdout, attrib_name, expand, policydb);
0fd1802
+		rc = print_attribs(stdout, attrib_name, expand, policydb);
0fd1802
 	if (roles || all)
0fd1802
-		print_roles(stdout, role_name, expand, policydb);
0fd1802
+		rc = print_roles(stdout, role_name, expand, policydb);
0fd1802
 	if (users || all)
0fd1802
-		print_users(stdout, user_name, expand, policydb);
0fd1802
+		rc = print_users(stdout, user_name, expand, policydb);
0fd1802
 	if (bools || all)
0fd1802
-		print_booleans(stdout, bool_name, expand, policydb);
0fd1802
+		rc = print_booleans(stdout, bool_name, expand, policydb);
0fd1802
 	if (sens || all)
0fd1802
-		print_sens(stdout, sens_name, expand, policydb);
0fd1802
+		rc = print_sens(stdout, sens_name, expand, policydb);
0fd1802
 	if (cats || all)
0fd1802
-		print_cats(stdout, cat_name, expand, policydb);
0fd1802
+		rc = print_cats(stdout, cat_name, expand, policydb);
0fd1802
 	if (fsuse || all)
0fd1802
-		print_fsuse(stdout, fsuse_type, policydb);
0fd1802
+		rc = print_fsuse(stdout, fsuse_type, policydb);
0fd1802
 	if (genfs || all)
0fd1802
-		print_genfscon(stdout, genfs_type, policydb);
0fd1802
+		rc = print_genfscon(stdout, genfs_type, policydb);
0fd1802
 	if (netif || all)
0fd1802
-		print_netifcon(stdout, netif_name, policydb);
0fd1802
+		rc = print_netifcon(stdout, netif_name, policydb);
0fd1802
 	if (node || all)
0fd1802
-		print_nodecon(stdout, node_addr, policydb);
0fd1802
+		rc = print_nodecon(stdout, node_addr, policydb);
0fd1802
 	if (port || all)
0fd1802
-		print_portcon(stdout, port_num, protocol, policydb);
0fd1802
+		rc = print_portcon(stdout, port_num, protocol, policydb);
0fd1802
 	if (isids || all)
0fd1802
-		print_isids(stdout, isid_name, expand, policydb);
0fd1802
+		rc = print_isids(stdout, isid_name, expand, policydb);
0fd1802
 	if (permissives || all)
0fd1802
-		print_permissives(stdout, permissive_name, expand, policydb);
0fd1802
+		rc = print_permissives(stdout, permissive_name, expand, policydb);
0fd1802
 	if (polcaps || all)
0fd1802
-		print_polcaps(stdout, polcap_name, expand, policydb);
0fd1802
+		rc = print_polcaps(stdout, polcap_name, expand, policydb);
0fd1802
 	if (constrain || all)
0fd1802
-		print_constraints(stdout, expand, policydb, linebreaks);
0fd1802
+		rc = print_constraints(stdout, expand, policydb, linebreaks);
0fd1802
 
0fd1802
 	apol_policy_destroy(&policydb);
0fd1802
 	apol_policy_path_destroy(&pol_path);
0fd1802
 	free(policy_file);
0fd1802
-	exit(0);
0fd1802
+	exit(rc);
0fd1802
 }
0fd1802
 
0fd1802
 /**
0fd1802
-- 
0fd1802
1.7.6.2
0fd1802