diff mbox series

[2/2] dismod, dispol: reduce the messages in batch mode

Message ID 20230613104439.2985001-2-yamato@redhat.com (mailing list archive)
State Superseded
Delegated to: Petr Lautrbach
Headers show
Series [1/2] dismod: print the policy version only in interactive mode | expand

Commit Message

Masatake YAMATO June 13, 2023, 10:44 a.m. UTC
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 checkpolicy/test/dismod.c | 20 +++++++++++---------
 checkpolicy/test/dispol.c |  8 +++++---
 2 files changed, 16 insertions(+), 12 deletions(-)

Comments

James Carter June 14, 2023, 6:17 p.m. UTC | #1
On Tue, Jun 13, 2023 at 6:52 AM Masatake YAMATO <yamato@redhat.com> wrote:
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
>  checkpolicy/test/dismod.c | 20 +++++++++++---------
>  checkpolicy/test/dispol.c |  8 +++++---
>  2 files changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
> index fa729ef2..bd26c302 100644
> --- a/checkpolicy/test/dismod.c
> +++ b/checkpolicy/test/dismod.c
> @@ -773,7 +773,7 @@ static int display_handle_unknown(policydb_t * p, FILE * out_fp)
>         return 0;
>  }
>
> -static int read_policy(char *filename, policydb_t * policy)
> +static int read_policy(char *filename, policydb_t * policy, int verbose)
>  {
>         FILE *in_fp;
>         struct policy_file f;
> @@ -816,13 +816,13 @@ static int read_policy(char *filename, policydb_t * policy)

You missed converting one function.
sepol_module_package_read() should also pass verbose instead of 1.

Thanks,
Jim

>                         fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
>                         exit(1);
>                 }
> -               retval = policydb_read(policy, &f, 1);
> +               retval = policydb_read(policy, &f, verbose);
>         }
>         fclose(in_fp);
>         return retval;
>  }
>
> -static void link_module(policydb_t * base, FILE * out_fp)
> +static void link_module(policydb_t * base, FILE * out_fp, int verbose)
>  {
>         char module_name[80] = { 0 };
>         int ret;
> @@ -845,8 +845,9 @@ static void link_module(policydb_t * base, FILE * out_fp)
>         }
>
>         /* read the binary policy */
> -       fprintf(out_fp, "Reading module...\n");
> -       if (read_policy(module_name, mods)) {
> +       if (verbose)
> +               fprintf(out_fp, "Reading module...\n");
> +       if (read_policy(module_name, mods, verbose)) {
>                 fprintf(stderr,
>                         "%s:  error(s) encountered while loading policy\n",
>                         module_name);
> @@ -937,12 +938,13 @@ int main(int argc, char **argv)
>         }
>
>         /* read the binary policy */
> -       fprintf(out_fp, "Reading policy...\n");
> +       if (!ops)
> +               fprintf(out_fp, "Reading policy...\n");
>         if (policydb_init(&policydb)) {
>                 fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
>                 exit(1);
>         }
> -       if (read_policy(mod, &policydb)) {
> +       if (read_policy(mod, &policydb, ops? 0: 1)) {
>                 fprintf(stderr,
>                         "%s:  error(s) encountered while loading policy\n",
>                         argv[0]);
> @@ -961,7 +963,7 @@ int main(int argc, char **argv)
>                 exit(1);
>         }
>
> -       if (policydb_index_others(NULL, &policydb, 1)) {
> +       if (policydb_index_others(NULL, &policydb, ops? 0: 1)) {
>                 fprintf(stderr, "Error indexing others\n");
>                 exit(1);
>         }
> @@ -1074,7 +1076,7 @@ int main(int argc, char **argv)
>                                         &policydb, out_fp);
>                         break;
>                 case 'l':
> -                       link_module(&policydb, out_fp);
> +                       link_module(&policydb, out_fp, ops? 0: 1);
>                         break;
>                 case 'v':
>                         print_version_info(&policydb, out_fp);
> diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c
> index bee1a660..b567ce77 100644
> --- a/checkpolicy/test/dispol.c
> +++ b/checkpolicy/test/dispol.c
> @@ -551,7 +551,8 @@ int main(int argc, char **argv)
>         }
>
>         /* read the binary policy */
> -       fprintf(out_fp, "Reading policy...\n");
> +       if (!ops)
> +               fprintf(out_fp, "Reading policy...\n");
>         policy_file_init(&pf);
>         pf.type = PF_USE_MEMORY;
>         pf.data = map;
> @@ -560,7 +561,7 @@ int main(int argc, char **argv)
>                 fprintf(stderr, "%s:  Out of memory!\n", argv[0]);
>                 exit(1);
>         }
> -       ret = policydb_read(&policydb, &pf, 1);
> +       ret = policydb_read(&policydb, &pf, ops? 0: 1);
>         if (ret) {
>                 fprintf(stderr,
>                         "%s:  error(s) encountered while parsing configuration\n",
> @@ -568,7 +569,8 @@ int main(int argc, char **argv)
>                 exit(1);
>         }
>
> -       fprintf(stdout, "binary policy file loaded\n\n");
> +       if (!ops)
> +               fprintf(stdout, "binary policy file loaded\n\n");
>         close(fd);
>
>         if (!ops)
> --
> 2.40.1
>
diff mbox series

Patch

diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
index fa729ef2..bd26c302 100644
--- a/checkpolicy/test/dismod.c
+++ b/checkpolicy/test/dismod.c
@@ -773,7 +773,7 @@  static int display_handle_unknown(policydb_t * p, FILE * out_fp)
 	return 0;
 }
 
-static int read_policy(char *filename, policydb_t * policy)
+static int read_policy(char *filename, policydb_t * policy, int verbose)
 {
 	FILE *in_fp;
 	struct policy_file f;
@@ -816,13 +816,13 @@  static int read_policy(char *filename, policydb_t * policy)
 			fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
 			exit(1);
 		}
-		retval = policydb_read(policy, &f, 1);
+		retval = policydb_read(policy, &f, verbose);
 	}
 	fclose(in_fp);
 	return retval;
 }
 
-static void link_module(policydb_t * base, FILE * out_fp)
+static void link_module(policydb_t * base, FILE * out_fp, int verbose)
 {
 	char module_name[80] = { 0 };
 	int ret;
@@ -845,8 +845,9 @@  static void link_module(policydb_t * base, FILE * out_fp)
 	}
 
 	/* read the binary policy */
-	fprintf(out_fp, "Reading module...\n");
-	if (read_policy(module_name, mods)) {
+	if (verbose)
+		fprintf(out_fp, "Reading module...\n");
+	if (read_policy(module_name, mods, verbose)) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while loading policy\n",
 			module_name);
@@ -937,12 +938,13 @@  int main(int argc, char **argv)
 	}
 
 	/* read the binary policy */
-	fprintf(out_fp, "Reading policy...\n");
+	if (!ops)
+		fprintf(out_fp, "Reading policy...\n");
 	if (policydb_init(&policydb)) {
 		fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
 		exit(1);
 	}
-	if (read_policy(mod, &policydb)) {
+	if (read_policy(mod, &policydb, ops? 0: 1)) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while loading policy\n",
 			argv[0]);
@@ -961,7 +963,7 @@  int main(int argc, char **argv)
 		exit(1);
 	}
 
-	if (policydb_index_others(NULL, &policydb, 1)) {
+	if (policydb_index_others(NULL, &policydb, ops? 0: 1)) {
 		fprintf(stderr, "Error indexing others\n");
 		exit(1);
 	}
@@ -1074,7 +1076,7 @@  int main(int argc, char **argv)
 					&policydb, out_fp);
 			break;
 		case 'l':
-			link_module(&policydb, out_fp);
+			link_module(&policydb, out_fp, ops? 0: 1);
 			break;
 		case 'v':
 			print_version_info(&policydb, out_fp);
diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c
index bee1a660..b567ce77 100644
--- a/checkpolicy/test/dispol.c
+++ b/checkpolicy/test/dispol.c
@@ -551,7 +551,8 @@  int main(int argc, char **argv)
 	}
 
 	/* read the binary policy */
-	fprintf(out_fp, "Reading policy...\n");
+	if (!ops)
+		fprintf(out_fp, "Reading policy...\n");
 	policy_file_init(&pf);
 	pf.type = PF_USE_MEMORY;
 	pf.data = map;
@@ -560,7 +561,7 @@  int main(int argc, char **argv)
 		fprintf(stderr, "%s:  Out of memory!\n", argv[0]);
 		exit(1);
 	}
-	ret = policydb_read(&policydb, &pf, 1);
+	ret = policydb_read(&policydb, &pf, ops? 0: 1);
 	if (ret) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while parsing configuration\n",
@@ -568,7 +569,8 @@  int main(int argc, char **argv)
 		exit(1);
 	}
 
-	fprintf(stdout, "binary policy file loaded\n\n");
+	if (!ops)
+		fprintf(stdout, "binary policy file loaded\n\n");
 	close(fd);
 
 	if (!ops)