Skip to content

Commit

Permalink
dismod, dispol: reduce the messages in batch mode
Browse files Browse the repository at this point in the history
A change in v2:
* pass `verbose' to sepol_module_package_read().

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake authored and bachradsusi committed Jun 30, 2023
1 parent 6e077ba commit b3788b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 12 additions & 10 deletions checkpolicy/test/dismod.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,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;
Expand Down Expand Up @@ -813,21 +813,21 @@ static int read_policy(char *filename, policydb_t * policy)
package->file_contexts = NULL;
retval =
sepol_module_package_read(package,
(sepol_policy_file_t *) & f, 1);
(sepol_policy_file_t *) & f, verbose);
package->policy = NULL;
sepol_module_package_free(package);
} else {
if (policydb_init(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;
Expand All @@ -850,8 +850,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);
Expand Down Expand Up @@ -942,12 +943,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]);
Expand All @@ -966,7 +968,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);
}
Expand Down Expand Up @@ -1079,7 +1081,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);
Expand Down
8 changes: 5 additions & 3 deletions checkpolicy/test/dispol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -560,15 +561,16 @@ 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",
argv[0]);
exit(1);
}

fprintf(stdout, "binary policy file loaded\n\n");
if (!ops)
fprintf(stdout, "binary policy file loaded\n\n");
close(fd);

if (!ops)
Expand Down

0 comments on commit b3788b9

Please sign in to comment.