Skip to contentSkip to conversation

checkpolicy: remove extraneous policy build noise

PATCH In review Nick Kralevich 3 participants 6 messages Sep 19, 2018 – Sep 21, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpolicy: remove extraneous policy build noise

Reduce noise when calling the checkpolicy command line. In Android, this creates unnecessary build noise which we'd like to avoid.

https://en.wikipedia.org/wiki/Unix_philosophy

Rule of Silence
Developers should design programs so that they do not print unnecessary output. This rule aims to allow other programs and developers to pick out the information they need from a program's output without having to parse verbosity.

An alternative approach would be to add a -s (silent) option to these tools, or to have the Android build system redirect stdout to /dev/null.

---
 checkpolicy/checkmodule.c |  8 --------
 checkpolicy/checkpolicy.c | 11 -----------
 2 files changed, 19 deletions(-)
checkpolicy/checkmodule.c +0 -1
index 46ce258f..8edc1f8c 100644
@@ -228,7 +228,6 @@ int main(int argc, char **argv)
 		if (optind !=3D argc)
 			usage(argv[0]);
 	}
-	printf("%s:  loading policy configuration from %s\n", argv[0], file);

=20
/* Set policydb and sidtab used by libsepol service functions
to my structures, so that I can directly populate and
@@ -302,8 +301,6 @@ int main(int argc, char **argv)
=20
sepol_sidtab_destroy(&sidtab);
=20
- printf("%s: policy configuration loaded\n", argv[0]);
-
if (outfile) {
FILE *outfp =3D fopen(outfile, "w");
=20
@@ -313,16 +310,11 @@ int main(int argc, char **argv)
}
=20
if (!cil) {
- printf("%s: writing binary representation (version %d) to %s\n",
- argv[0], policyvers, outfile);
-
if (write_binary_policy(&modpolicydb, outfp) !=3D 0) {
fprintf(stderr, "%s: error writing %s\n", argv[0], outfile); exit(1);
}
} else {
- printf("%s: writing CIL to %s\n",argv[0], outfile);
-
if (sepol_module_policydb_to_cil(outfp, &modpolicydb, 0) !=3D 0) {
fprintf(stderr, "%s: error writing %s\n", argv[0], outfile); exit(1);

checkpolicy/checkpolicy.c +0 -2
index fbda4558..12c4c405 100644
@@ -512,8 +512,6 @@ int main(int argc, char **argv)
 		if (optind !=3D argc)
 			usage(argv[0]);
 	}
-	printf("%s:  loading policy configuration from %s\n", argv[0], file);
-
 	/* Set policydb and sidtab used by libsepol service functions
 	   to my structures, so that I can directly populate and
 	   manipulate them. */
@@ -623,8 +621,6 @@ int main(int argc, char **argv)
 	if (policydb_load_isids(&policydb, &sidtab))
 		exit(1);

=20
- printf("%s: policy configuration loaded\n", argv[0]);
-
if (outfile) {
outfp =3D fopen(outfile, "w");
if (!outfp) {
@@ -636,8 +632,6 @@ int main(int argc, char **argv)
=20
if (!cil) {
if (!conf) {
- printf("%s: writing binary representation (version %d) to %s\n", ar=
gv[0], policyvers, outfile);
-
policydb.policy_type =3D POLICY_KERN;
=20
policy_file_init(&pf);
@@ -645,8 +639,6 @@ int main(int argc, char **argv)
pf.fp =3D outfp;
ret =3D policydb_write(&policydb, &pf);
} else {
- printf("%s: writing policy.conf to %s\n",
- argv[0], outfile);
ret =3D sepol_kernel_policydb_to_conf(outfp, policydbp);
}
if (ret) {
@@ -655,7 +647,6 @@ int main(int argc, char **argv)
exit(1);
}
} else {
- printf("%s: writing CIL to %s\n",argv[0], outfile);
if (binary) {
ret =3D sepol_kernel_policydb_to_cil(outfp, policydbp);
} else {
@@ -894,8 +885,6 @@ int main(int argc, char **argv)
FGETS(ans, sizeof(ans), stdin);
pathlen =3D strlen(ans);
ans[pathlen - 1] =3D 0;
- printf("%s: loading policy configuration from %s\n",
- argv[0], ans);
fd =3D open(ans, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Can't open '%s': %s\n",
--=20
2.19.0.397.gdd90340f6a-goog

#1 lore raw

Some people might be checking this output since it's been there so long, -s would be a good way to go.

Alternatively, a way to bring back this information via a verbose option -V could
be considered.

Either way, a simple logging mechanism analogous to LOGV/LOGW/LOGE could be useful, I wonder what subordinate routines are logging. IIRC it was all fprintf(stderr) stuff in libselinux proper as you allude
to in the redirection of stdout comment. We don't need to address this in this
patch, but we may want to consider it at some point.

I would lean towards a silent flag as it's backwards compatible, but noting that it doesn't suppress subordinate callers.

I would also yield that opinion, as removing it works for me.

Quoted 138 lines · Nick Kralevich via Selinux

Reduce noise when calling the checkpolicy command line. In Android, this creates unnecessary build noise which we'd like to avoid.

https://en.wikipedia.org/wiki/Unix_philosophy

Rule of Silence
Developers should design programs so that they do not print unnecessary output. This rule aims to allow other programs and developers to pick out the information they need from a program's output without having to parse verbosity.

An alternative approach would be to add a -s (silent) option to these tools, or to have the Android build system redirect stdout to /dev/null.

---
 checkpolicy/checkmodule.c |  8 --------
 checkpolicy/checkpolicy.c | 11 -----------
 2 files changed, 19 deletions(-)
checkpolicy/checkmodule.c +0 -1
index 46ce258f..8edc1f8c 100644
@@ -228,7 +228,6 @@ int main(int argc, char **argv)
                if (optind != argc)
                        usage(argv[0]);
        }
-       printf("%s:  loading policy configuration from %s\n", argv[0],
 file);
 
        /* Set policydb and sidtab used by libsepol service functions

to my structures, so that I can directly populate and

checkpolicy/checkmodule.c +0 -6
@@ -302,8 +301,6 @@ int main(int argc, char **argv)
 
        sepol_sidtab_destroy(&sidtab);
 
-       printf("%s:  policy configuration loaded\n", argv[0]);
-
        if (outfile) {
                FILE *outfp = fopen(outfile, "w");
 
@@ -313,16 +310,11 @@ int main(int argc, char **argv)
                }
 
                if (!cil) {
-                       printf("%s:  writing binary representation
 (version %d) to %s\n",
-                                  argv[0], policyvers, outfile);
-
                        if (write_binary_policy(&modpolicydb, outfp) != 0)
 {
                                fprintf(stderr, "%s:  error writing %s\n",
 argv[0], outfile);
                                exit(1);
                        }
                } else {
-                       printf("%s:  writing CIL to %s\n",argv[0],

outfile);
-
if (sepol_module_policydb_to_cil(outfp,
&modpolicydb, 0) != 0) {
fprintf(stderr, "%s: error writing %s\n",

argv[0], outfile);
                                exit(1);
checkpolicy/checkpolicy.c +0 -2
index fbda4558..12c4c405 100644
@@ -512,8 +512,6 @@ int main(int argc, char **argv)
                if (optind != argc)
                        usage(argv[0]);
        }
-       printf("%s:  loading policy configuration from %s\n", argv[0],
 file);
-
        /* Set policydb and sidtab used by libsepol service functions
           to my structures, so that I can directly populate and

manipulate them. */

checkpolicy/checkpolicy.c +0 -4
@@ -623,8 +621,6 @@ int main(int argc, char **argv)
        if (policydb_load_isids(&policydb, &sidtab))
                exit(1);
 
-       printf("%s:  policy configuration loaded\n", argv[0]);
-
        if (outfile) {
                outfp = fopen(outfile, "w");
                if (!outfp) {
@@ -636,8 +632,6 @@ int main(int argc, char **argv)
 
                if (!cil) {
                        if (!conf) {
-                               printf("%s:  writing binary representation
 (version %d) to %s\n", argv[0], policyvers, outfile);
-
                                policydb.policy_type = POLICY_KERN;
 
                                policy_file_init(&pf);
checkpolicy/checkpolicy.c +0 -2
@@ -645,8 +639,6 @@ int main(int argc, char **argv)
                                pf.fp = outfp;
                                ret = policydb_write(&policydb, &pf);
                        } else {
-                               printf("%s:  writing policy.conf to %s\n",
-                                      argv[0], outfile);
                                ret = sepol_kernel_policydb_to_conf(outfp,
 policydbp);
                        }
                        if (ret) {
checkpolicy/checkpolicy.c +0 -1
@@ -655,7 +647,6 @@ int main(int argc, char **argv)
                                exit(1);
                        }
                } else {
-                       printf("%s:  writing CIL to %s\n",argv[0],
 outfile);
                        if (binary) {
                                ret = sepol_kernel_policydb_to_cil(outfp,
policydbp);
                        } else {
checkpolicy/checkpolicy.c +0 -2
@@ -894,8 +885,6 @@ int main(int argc, char **argv)
                        FGETS(ans, sizeof(ans), stdin);
                        pathlen = strlen(ans);
                        ans[pathlen - 1] = 0;
-                       printf("%s:  loading policy configuration from
 %s\n",
-                              argv[0], ans);
                        fd = open(ans, O_RDONLY);
                        if (fd < 0) {
                                fprintf(stderr, "Can't open '%s':  %s\n",

--
2.19.0.397.gdd90340f6a-goog

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].

#2 lore raw
Quoted 13 lines · William Roberts

Some people might be checking this output since it's been there so long, -s would be a good way to go.

Alternatively, a way to bring back this information via a verbose option -V could
be considered.

Either way, a simple logging mechanism analogous to
LOGV/LOGW/LOGE could be useful, I wonder what subordinate routines
are logging. IIRC it was all fprintf(stderr) stuff in libselinux proper as you allude to in the redirection of stdout comment. We don't need to address this in this patch, but we may want to consider it at some point.

Quoted 4 lines

I would lean towards a silent flag as it's backwards compatible, but noting that it doesn't suppress subordinate callers.

I would also yield that opinion, as removing it works for me.

I'm ok dropping the output unless someone knows of an existing user that relies upon it (which I can't really envision).

With regard to subordinate routines, libsepol has sepol_debug(0) or sepol_msg_set_callback() to suppress or redirect its logging.

checkpolicy doesn't use libselinux but it likewise has selinux_set_callback().

Quoted 152 lines · On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux…
    Reduce noise when calling the checkpolicy command line. In Android, this
    creates unnecessary build noise which we'd like to avoid.

    https://en.wikipedia.org/wiki/Unix_philosophy

       Rule of Silence
       Developers should design programs so that they do not print
       unnecessary output. This rule aims to allow other programs
       and developers to pick out the information they need from a
       program's output without having to parse verbosity.

    An alternative approach would be to add a -s (silent) option to these
    tools, or to have the Android build system redirect stdout to /dev/null.

    Signed-off-by: Nick Kralevich <[email protected] <mailto:[email protected]>>
    ---
      checkpolicy/checkmodule.c |  8 --------
      checkpolicy/checkpolicy.c | 11 -----------
      2 files changed, 19 deletions(-)

    diff --git a/checkpolicy/checkmodule.c b/checkpolicy/checkmodule.c
    index 46ce258f..8edc1f8c 100644
    --- a/checkpolicy/checkmodule.c
    +++ b/checkpolicy/checkmodule.c
    @@ -228,7 +228,6 @@ int main(int argc, char **argv)
                     if (optind != argc)
                             usage(argv[0]);
             }
    -       printf("%s:  loading policy configuration from %s\n",
    argv[0], file);

             /* Set policydb and sidtab used by libsepol service functions
                to my structures, so that I can directly populate and
    @@ -302,8 +301,6 @@ int main(int argc, char **argv)

             sepol_sidtab_destroy(&sidtab);

    -       printf("%s:  policy configuration loaded\n", argv[0]);
    -
             if (outfile) {
                     FILE *outfp = fopen(outfile, "w");

    @@ -313,16 +310,11 @@ int main(int argc, char **argv)
                     }

                     if (!cil) {
    -                       printf("%s:  writing binary representation
    (version %d) to %s\n",
    -                                  argv[0], policyvers, outfile);
    -
                             if (write_binary_policy(&modpolicydb,
    outfp) != 0) {
                                     fprintf(stderr, "%s:  error writing
    %s\n", argv[0], outfile);
                                     exit(1);
                             }
                     } else {
    -                       printf("%s:  writing CIL to %s\n",argv[0],
    outfile);
    -
                             if (sepol_module_policydb_to_cil(outfp,
    &modpolicydb, 0) != 0) {
                                     fprintf(stderr, "%s:  error writing
    %s\n", argv[0], outfile);
                                     exit(1);
    diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c
    index fbda4558..12c4c405 100644
    --- a/checkpolicy/checkpolicy.c
    +++ b/checkpolicy/checkpolicy.c
    @@ -512,8 +512,6 @@ int main(int argc, char **argv)
                     if (optind != argc)
                             usage(argv[0]);
             }
    -       printf("%s:  loading policy configuration from %s\n",
    argv[0], file);
    -
             /* Set policydb and sidtab used by libsepol service functions
                to my structures, so that I can directly populate and
                manipulate them. */
    @@ -623,8 +621,6 @@ int main(int argc, char **argv)
             if (policydb_load_isids(&policydb, &sidtab))
                     exit(1);

    -       printf("%s:  policy configuration loaded\n", argv[0]);
    -
             if (outfile) {
                     outfp = fopen(outfile, "w");
                     if (!outfp) {
    @@ -636,8 +632,6 @@ int main(int argc, char **argv)

                     if (!cil) {
                             if (!conf) {
    -                               printf("%s:  writing binary
    representation (version %d) to %s\n", argv[0], policyvers, outfile);
    -
                                     policydb.policy_type = POLICY_KERN;

                                     policy_file_init(&pf);
    @@ -645,8 +639,6 @@ int main(int argc, char **argv)
                                     pf.fp = outfp;
                                     ret = policydb_write(&policydb, &pf);
                             } else {
    -                               printf("%s:  writing policy.conf to
    %s\n",
    -                                      argv[0], outfile);
                                     ret =
    sepol_kernel_policydb_to_conf(outfp, policydbp);
                             }
                             if (ret) {
    @@ -655,7 +647,6 @@ int main(int argc, char **argv)
                                     exit(1);
                             }
                     } else {
    -                       printf("%s:  writing CIL to %s\n",argv[0],
    outfile);
                             if (binary) {
                                     ret =
    sepol_kernel_policydb_to_cil(outfp, policydbp);
                             } else {
    @@ -894,8 +885,6 @@ int main(int argc, char **argv)
                             FGETS(ans, sizeof(ans), stdin);
                             pathlen = strlen(ans);
                             ans[pathlen - 1] = 0;
    -                       printf("%s:  loading policy configuration
    from %s\n",
    -                              argv[0], ans);
                             fd = open(ans, O_RDONLY);
                             if (fd < 0) {
                                     fprintf(stderr, "Can't open '%s': 
    %s\n",
    -- 
    2.19.0.397.gdd90340f6a-goog

    _______________________________________________
    Selinux mailing list
    [email protected] <mailto:[email protected]>
    To unsubscribe, send email to [email protected]
    <mailto:[email protected]>.
    To get help, send an email containing "help" to
    [email protected] <mailto:[email protected]>.

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

#3 lore raw
Quoted 16 lines · Stephen Smalley
Quoted 15 lines · William Roberts

Some people might be checking this output since it's been there so long, -s would be a good way to go.

Alternatively, a way to bring back this information via a verbose option -V could
be considered.

Either way, a simple logging mechanism analogous to LOGV/LOGW/LOGE could be useful, I wonder what subordinate routines are logging. IIRC it was all fprintf(stderr) stuff in libselinux proper as you allude
to in the redirection of stdout comment. We don't need to address this in this
patch, but we may want to consider it at some point.

Quoted 8 lines
Quoted 4 lines

I would lean towards a silent flag as it's backwards compatible, but noting that it doesn't suppress subordinate callers.

I would also yield that opinion, as removing it works for me.

I'm ok dropping the output unless someone knows of an existing user that relies upon it (which I can't really envision).

Why don't we extend the review period to 72 hours, and ill apply this Friday unless we hear of this breaking someone. Essentially consider this a soft-ack.

Quoted 9 lines

With regard to subordinate routines, libsepol has sepol_debug(0) or sepol_msg_set_callback() to suppress or redirect its logging.

checkpolicy doesn't use libselinux but it likewise has selinux_set_callback().

What about things like:
libselinux/src/load_policy.c:299: fprintf(stderr, "libselinux: %s\n", errormsg);

Also utils and others are using fprintf directly.... perhaps something we wish to make common
across utilities and subordinate libs.

Quoted 163 lines
Quoted 5 lines

On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux <[email protected] <mailto:[email protected]>> wrote:

Reduce noise when calling the checkpolicy command line. In Android,

this

Quoted 4 lines

creates unnecessary build noise which we'd like to avoid.

https://en.wikipedia.org/wiki/Unix_philosophy

Quoted 8 lines

Rule of Silence
Developers should design programs so that they do not print unnecessary output. This rule aims to allow other programs and developers to pick out the information they need from a program's output without having to parse verbosity.

An alternative approach would be to add a -s (silent) option to these tools, or to have the Android build system redirect stdout to

/dev/null.

Quoted 12 lines
Quoted 1 line
    ---
      checkpolicy/checkmodule.c |  8 --------
      checkpolicy/checkpolicy.c | 11 -----------
      2 files changed, 19 deletions(-)

    diff --git a/checkpolicy/checkmodule.c b/checkpolicy/checkmodule.c
    index 46ce258f..8edc1f8c 100644
    --- a/checkpolicy/checkmodule.c
    +++ b/checkpolicy/checkmodule.c
Quoted 8 lines
    @@ -228,7 +228,6 @@ int main(int argc, char **argv)
                     if (optind != argc)
                             usage(argv[0]);
             }
    -       printf("%s:  loading policy configuration from %s\n",
    argv[0], file);

             /* Set policydb and sidtab used by libsepol service

functions

Quoted 37 lines
                to my structures, so that I can directly populate and
    @@ -302,8 +301,6 @@ int main(int argc, char **argv)

             sepol_sidtab_destroy(&sidtab);

    -       printf("%s:  policy configuration loaded\n", argv[0]);
    -
             if (outfile) {
                     FILE *outfp = fopen(outfile, "w");

    @@ -313,16 +310,11 @@ int main(int argc, char **argv)
                     }

                     if (!cil) {
    -                       printf("%s:  writing binary representation
    (version %d) to %s\n",
    -                                  argv[0], policyvers, outfile);
    -
                             if (write_binary_policy(&modpolicydb,
    outfp) != 0) {
                                     fprintf(stderr, "%s:  error writing
    %s\n", argv[0], outfile);
                                     exit(1);
                             }
                     } else {
    -                       printf("%s:  writing CIL to %s\n",argv[0],
    outfile);
    -
                             if (sepol_module_policydb_to_cil(outfp,
    &modpolicydb, 0) != 0) {
                                     fprintf(stderr, "%s:  error writing
    %s\n", argv[0], outfile);
                                     exit(1);
    diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c
    index fbda4558..12c4c405 100644
    --- a/checkpolicy/checkpolicy.c
    +++ b/checkpolicy/checkpolicy.c
Quoted 8 lines
    @@ -512,8 +512,6 @@ int main(int argc, char **argv)
                     if (optind != argc)
                             usage(argv[0]);
             }
    -       printf("%s:  loading policy configuration from %s\n",
    argv[0], file);
    -
             /* Set policydb and sidtab used by libsepol service

functions

Quoted 16 lines
                to my structures, so that I can directly populate and
                manipulate them. */
    @@ -623,8 +621,6 @@ int main(int argc, char **argv)
             if (policydb_load_isids(&policydb, &sidtab))
                     exit(1);

    -       printf("%s:  policy configuration loaded\n", argv[0]);
    -
             if (outfile) {
                     outfp = fopen(outfile, "w");
                     if (!outfp) {
    @@ -636,8 +632,6 @@ int main(int argc, char **argv)

                     if (!cil) {
                             if (!conf) {
    -                               printf("%s:  writing binary
Quoted 8 lines
    representation (version %d) to %s\n", argv[0], policyvers, outfile);
    -
                                     policydb.policy_type = POLICY_KERN;

                                     policy_file_init(&pf);
    @@ -645,8 +639,6 @@ int main(int argc, char **argv)
                                     pf.fp = outfp;
                                     ret = policydb_write(&policydb,

&pf);

Quoted 43 lines
                             } else {
    -                               printf("%s:  writing policy.conf to
    %s\n",
    -                                      argv[0], outfile);
                                     ret =
    sepol_kernel_policydb_to_conf(outfp, policydbp);
                             }
                             if (ret) {
    @@ -655,7 +647,6 @@ int main(int argc, char **argv)
                                     exit(1);
                             }
                     } else {
    -                       printf("%s:  writing CIL to %s\n",argv[0],
    outfile);
                             if (binary) {
                                     ret =
    sepol_kernel_policydb_to_cil(outfp, policydbp);
                             } else {
    @@ -894,8 +885,6 @@ int main(int argc, char **argv)
                             FGETS(ans, sizeof(ans), stdin);
                             pathlen = strlen(ans);
                             ans[pathlen - 1] = 0;
    -                       printf("%s:  loading policy configuration
    from %s\n",
    -                              argv[0], ans);
                             fd = open(ans, O_RDONLY);
                             if (fd < 0) {
                                     fprintf(stderr, "Can't open '%s':
    %s\n",
    --
    2.19.0.397.gdd90340f6a-goog

    _______________________________________________
    Selinux mailing list
    [email protected] <mailto:[email protected]>
    To unsubscribe, send email to [email protected]
    <mailto:[email protected]>.
    To get help, send an email containing "help" to
    [email protected] <mailto:[email protected]

.

Quoted 5 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to

[email protected].

Quoted 1 line
#4 lore raw
Quoted 42 lines · William Roberts

On Wed, Sep 19, 2018 at 12:36 PM Stephen Smalley <[email protected] <mailto:[email protected]>> wrote:

On 09/19/2018 03:21 PM, William Roberts wrote:
> Some people might be checking this output since it's been there
so long,
> -s would be a good way to go.
>
> Alternatively, a way to bring back this information via a verbose
option
> -V could
> be considered.
>
> Either way, a simple logging mechanism analogous to
> LOGV/LOGW/LOGE could be useful, I wonder what subordinate routines > are logging. IIRC it was all fprintf(stderr) stuff in libselinux
proper
> as you allude
> to in the redirection of stdout comment. We don't need to address
this
> in this
> patch, but we may want to consider it at some point.
>
> I would lean towards a silent flag as it's backwards compatible, > but noting that it doesn't suppress subordinate callers. >
> I would also yield that opinion, as removing it works for me.

I'm ok dropping the output unless someone knows of an existing user that
relies upon it (which I can't really envision).

Why don't we extend the review period to 72 hours, and ill apply this Friday unless we hear of this breaking someone. Essentially consider this a soft-ack.

With regard to subordinate routines, libsepol has sepol_debug(0) or sepol_msg_set_callback() to suppress or redirect its logging.

Quoted 6 lines

checkpolicy doesn't use libselinux but it likewise has selinux_set_callback().

What about things like:
libselinux/src/load_policy.c:299:fprintf(stderr, "libselinux:  %s\n", errormsg);

Yes, there are a few lingering cases that ought to be converted over to selinux_log().

Quoted 3 lines

Also utils and others are using fprintf directly.... perhaps something we wish to make common across utilities and subordinate libs.

No, it is completely appropriate for the utilities to do it directly. Only the library should be using the callbacks.

Quoted 183 lines

     >
     > On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux
     > <[email protected] <mailto:[email protected]>
    <mailto:[email protected] <mailto:[email protected]>>> wrote:
     >
     >     Reduce noise when calling the checkpolicy command line. In
    Android, this
     >     creates unnecessary build noise which we'd like to avoid.
     >
     > https://en.wikipedia.org/wiki/Unix_philosophy
     >
     >        Rule of Silence
     >        Developers should design programs so that they do not print
     >        unnecessary output. This rule aims to allow other programs
     >        and developers to pick out the information they need from a
     >        program's output without having to parse verbosity.
     >
     >     An alternative approach would be to add a -s (silent) option
    to these
     >     tools, or to have the Android build system redirect stdout to
    /dev/null.
     >
     >     Signed-off-by: Nick Kralevich <[email protected]
    <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>
     >     ---
     >       checkpolicy/checkmodule.c |  8 --------
     >       checkpolicy/checkpolicy.c | 11 -----------
     >       2 files changed, 19 deletions(-)
     >
     >     diff --git a/checkpolicy/checkmodule.c
    b/checkpolicy/checkmodule.c
     >     index 46ce258f..8edc1f8c 100644
     >     --- a/checkpolicy/checkmodule.c
     >     +++ b/checkpolicy/checkmodule.c
     >     @@ -228,7 +228,6 @@ int main(int argc, char **argv)
     >                      if (optind != argc)
     >                              usage(argv[0]);
     >              }
     >     -       printf("%s:  loading policy configuration from %s\n",
     >     argv[0], file);
     >
     >              /* Set policydb and sidtab used by libsepol service
    functions
     >                 to my structures, so that I can directly populate and
     >     @@ -302,8 +301,6 @@ int main(int argc, char **argv)
     >
     >              sepol_sidtab_destroy(&sidtab);
     >
     >     -       printf("%s:  policy configuration loaded\n", argv[0]);
     >     -
     >              if (outfile) {
     >                      FILE *outfp = fopen(outfile, "w");
     >
     >     @@ -313,16 +310,11 @@ int main(int argc, char **argv)
     >                      }
     >
     >                      if (!cil) {
     >     -                       printf("%s:  writing binary
    representation
     >     (version %d) to %s\n",
     >     -                                  argv[0], policyvers, outfile);
     >     -
     >                              if (write_binary_policy(&modpolicydb,
     >     outfp) != 0) {
     >                                      fprintf(stderr, "%s:  error
    writing
     >     %s\n", argv[0], outfile);
     >                                      exit(1);
     >                              }
     >                      } else {
     >     -                       printf("%s:  writing CIL to
    %s\n",argv[0],
     >     outfile);
     >     -
     >                              if (sepol_module_policydb_to_cil(outfp,
     >     &modpolicydb, 0) != 0) {
     >                                      fprintf(stderr, "%s:  error
    writing
     >     %s\n", argv[0], outfile);
     >                                      exit(1);
     >     diff --git a/checkpolicy/checkpolicy.c
    b/checkpolicy/checkpolicy.c
     >     index fbda4558..12c4c405 100644
     >     --- a/checkpolicy/checkpolicy.c
     >     +++ b/checkpolicy/checkpolicy.c
     >     @@ -512,8 +512,6 @@ int main(int argc, char **argv)
     >                      if (optind != argc)
     >                              usage(argv[0]);
     >              }
     >     -       printf("%s:  loading policy configuration from %s\n",
     >     argv[0], file);
     >     -
     >              /* Set policydb and sidtab used by libsepol service
    functions
     >                 to my structures, so that I can directly populate and
     >                 manipulate them. */
     >     @@ -623,8 +621,6 @@ int main(int argc, char **argv)
     >              if (policydb_load_isids(&policydb, &sidtab))
     >                      exit(1);
     >
     >     -       printf("%s:  policy configuration loaded\n", argv[0]);
     >     -
     >              if (outfile) {
     >                      outfp = fopen(outfile, "w");
     >                      if (!outfp) {
     >     @@ -636,8 +632,6 @@ int main(int argc, char **argv)
     >
     >                      if (!cil) {
     >                              if (!conf) {
     >     -                               printf("%s:  writing binary
     >     representation (version %d) to %s\n", argv[0], policyvers,
    outfile);
     >     -
     >                                      policydb.policy_type =
    POLICY_KERN;
     >
     >                                      policy_file_init(&pf);
     >     @@ -645,8 +639,6 @@ int main(int argc, char **argv)
     >                                      pf.fp = outfp;
     >                                      ret =
    policydb_write(&policydb, &pf);
     >                              } else {
     >     -                               printf("%s:  writing
    policy.conf to
     >     %s\n",
     >     -                                      argv[0], outfile);
     >                                      ret =
     >     sepol_kernel_policydb_to_conf(outfp, policydbp);
     >                              }
     >                              if (ret) {
     >     @@ -655,7 +647,6 @@ int main(int argc, char **argv)
     >                                      exit(1);
     >                              }
     >                      } else {
     >     -                       printf("%s:  writing CIL to
    %s\n",argv[0],
     >     outfile);
     >                              if (binary) {
     >                                      ret =
     >     sepol_kernel_policydb_to_cil(outfp, policydbp);
     >                              } else {
     >     @@ -894,8 +885,6 @@ int main(int argc, char **argv)
     >                              FGETS(ans, sizeof(ans), stdin);
     >                              pathlen = strlen(ans);
     >                              ans[pathlen - 1] = 0;
     >     -                       printf("%s:  loading policy configuration
     >     from %s\n",
     >     -                              argv[0], ans);
     >                              fd = open(ans, O_RDONLY);
     >                              if (fd < 0) {
     >                                      fprintf(stderr, "Can't open
    '%s':
     >     %s\n",
     >     --
     >     2.19.0.397.gdd90340f6a-goog
     >
     >     _______________________________________________
     >     Selinux mailing list
     > [email protected] <mailto:[email protected]>
    <mailto:[email protected] <mailto:[email protected]>>
     >     To unsubscribe, send email to [email protected]
    <mailto:[email protected]>
     >     <mailto:[email protected]
    <mailto:[email protected]>>.
     >     To get help, send an email containing "help" to
     > [email protected]
    <mailto:[email protected]>
    <mailto:[email protected]
    <mailto:[email protected]>>.
     >
     >
     >
     > _______________________________________________
     > Selinux mailing list
     > [email protected] <mailto:[email protected]>
     > To unsubscribe, send email to [email protected]
    <mailto:[email protected]>.
     > To get help, send an email containing "help" to
    [email protected] <mailto:[email protected]>.
     >
#5 lore raw
In reply to Nick Kralevich

merged: https://github.com/SELinuxProject/selinux/pull/99

Quoted 138 lines · Nick Kralevich via Selinux

Reduce noise when calling the checkpolicy command line. In Android, this creates unnecessary build noise which we'd like to avoid.

https://en.wikipedia.org/wiki/Unix_philosophy

Rule of Silence
Developers should design programs so that they do not print unnecessary output. This rule aims to allow other programs and developers to pick out the information they need from a program's output without having to parse verbosity.

An alternative approach would be to add a -s (silent) option to these tools, or to have the Android build system redirect stdout to /dev/null.

---
 checkpolicy/checkmodule.c |  8 --------
 checkpolicy/checkpolicy.c | 11 -----------
 2 files changed, 19 deletions(-)
checkpolicy/checkmodule.c +0 -1
index 46ce258f..8edc1f8c 100644
@@ -228,7 +228,6 @@ int main(int argc, char **argv)
                if (optind != argc)
                        usage(argv[0]);
        }
-       printf("%s:  loading policy configuration from %s\n", argv[0],
 file);
 
        /* Set policydb and sidtab used by libsepol service functions

to my structures, so that I can directly populate and

checkpolicy/checkmodule.c +0 -6
@@ -302,8 +301,6 @@ int main(int argc, char **argv)
 
        sepol_sidtab_destroy(&sidtab);
 
-       printf("%s:  policy configuration loaded\n", argv[0]);
-
        if (outfile) {
                FILE *outfp = fopen(outfile, "w");
 
@@ -313,16 +310,11 @@ int main(int argc, char **argv)
                }
 
                if (!cil) {
-                       printf("%s:  writing binary representation
 (version %d) to %s\n",
-                                  argv[0], policyvers, outfile);
-
                        if (write_binary_policy(&modpolicydb, outfp) != 0)
 {
                                fprintf(stderr, "%s:  error writing %s\n",
 argv[0], outfile);
                                exit(1);
                        }
                } else {
-                       printf("%s:  writing CIL to %s\n",argv[0],

outfile);
-
if (sepol_module_policydb_to_cil(outfp,
&modpolicydb, 0) != 0) {
fprintf(stderr, "%s: error writing %s\n",

argv[0], outfile);
                                exit(1);
checkpolicy/checkpolicy.c +0 -2
index fbda4558..12c4c405 100644
@@ -512,8 +512,6 @@ int main(int argc, char **argv)
                if (optind != argc)
                        usage(argv[0]);
        }
-       printf("%s:  loading policy configuration from %s\n", argv[0],
 file);
-
        /* Set policydb and sidtab used by libsepol service functions
           to my structures, so that I can directly populate and

manipulate them. */

checkpolicy/checkpolicy.c +0 -4
@@ -623,8 +621,6 @@ int main(int argc, char **argv)
        if (policydb_load_isids(&policydb, &sidtab))
                exit(1);
 
-       printf("%s:  policy configuration loaded\n", argv[0]);
-
        if (outfile) {
                outfp = fopen(outfile, "w");
                if (!outfp) {
@@ -636,8 +632,6 @@ int main(int argc, char **argv)
 
                if (!cil) {
                        if (!conf) {
-                               printf("%s:  writing binary representation
 (version %d) to %s\n", argv[0], policyvers, outfile);
-
                                policydb.policy_type = POLICY_KERN;
 
                                policy_file_init(&pf);
checkpolicy/checkpolicy.c +0 -2
@@ -645,8 +639,6 @@ int main(int argc, char **argv)
                                pf.fp = outfp;
                                ret = policydb_write(&policydb, &pf);
                        } else {
-                               printf("%s:  writing policy.conf to %s\n",
-                                      argv[0], outfile);
                                ret = sepol_kernel_policydb_to_conf(outfp,
 policydbp);
                        }
                        if (ret) {
checkpolicy/checkpolicy.c +0 -1
@@ -655,7 +647,6 @@ int main(int argc, char **argv)
                                exit(1);
                        }
                } else {
-                       printf("%s:  writing CIL to %s\n",argv[0],
 outfile);
                        if (binary) {
                                ret = sepol_kernel_policydb_to_cil(outfp,
policydbp);
                        } else {
checkpolicy/checkpolicy.c +0 -2
@@ -894,8 +885,6 @@ int main(int argc, char **argv)
                        FGETS(ans, sizeof(ans), stdin);
                        pathlen = strlen(ans);
                        ans[pathlen - 1] = 0;
-                       printf("%s:  loading policy configuration from
 %s\n",
-                              argv[0], ans);
                        fd = open(ans, O_RDONLY);
                        if (fd < 0) {
                                fprintf(stderr, "Can't open '%s':  %s\n",

--
2.19.0.397.gdd90340f6a-goog

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].