diff mbox series

checkpolicy: remove extraneous policy build noise

Message ID 20180919190856.58147-1-nnk@google.com (mailing list archive)
State Not Applicable
Headers show
Series checkpolicy: remove extraneous policy build noise | expand

Commit Message

Jann Horn via Selinux Sept. 19, 2018, 7:08 p.m. UTC
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 <nnk@google.com>
---
 checkpolicy/checkmodule.c |  8 --------
 checkpolicy/checkpolicy.c | 11 -----------
 2 files changed, 19 deletions(-)

Comments

William Roberts Sept. 19, 2018, 7:21 p.m. UTC | #1
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.

On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux <
selinux@tycho.nsa.gov> 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 <nnk@google.com>
> ---
>  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
> Selinux@tycho.nsa.gov
> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> To get help, send an email containing "help" to
> Selinux-request@tycho.nsa.gov.
>
<div dir="ltr">Some people might be checking this output since it&#39;s been there so long,<div>-s would be a good way to go.</div><div><br></div><div>Alternatively, a way to bring back this information via a verbose option -V could</div><div>be considered.</div><div><br></div><div>Either way, a simple logging mechanism analogous to</div><div>LOGV/LOGW/LOGE could be useful, I wonder what subordinate routines</div><div>are logging. IIRC it was all fprintf(stderr) stuff in libselinux proper as you allude</div><div>to in the redirection of stdout comment. We don&#39;t need to address this in this</div><div>patch, but we may want to consider it at some point.</div><div><br></div><div>I would lean towards a silent flag as it&#39;s backwards compatible,</div><div>but noting that it doesn&#39;t suppress subordinate callers.</div><div><br></div><div>I would also yield that opinion, as removing it works for me.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux &lt;<a href="mailto:selinux@tycho.nsa.gov">selinux@tycho.nsa.gov</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Reduce noise when calling the checkpolicy command line. In Android, this<br>
creates unnecessary build noise which we&#39;d like to avoid.<br>
<br>
<a href="https://en.wikipedia.org/wiki/Unix_philosophy" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Unix_philosophy</a><br>
<br>
  Rule of Silence<br>
  Developers should design programs so that they do not print<br>
  unnecessary output. This rule aims to allow other programs<br>
  and developers to pick out the information they need from a<br>
  program&#39;s output without having to parse verbosity.<br>
<br>
An alternative approach would be to add a -s (silent) option to these<br>
tools, or to have the Android build system redirect stdout to /dev/null.<br>
<br>
Signed-off-by: Nick Kralevich &lt;<a href="mailto:nnk@google.com" target="_blank">nnk@google.com</a>&gt;<br>
---<br>
 checkpolicy/checkmodule.c |  8 --------<br>
 checkpolicy/checkpolicy.c | 11 -----------<br>
 2 files changed, 19 deletions(-)<br>
<br>
diff --git a/checkpolicy/checkmodule.c b/checkpolicy/checkmodule.c<br>
index 46ce258f..8edc1f8c 100644<br>
--- a/checkpolicy/checkmodule.c<br>
+++ b/checkpolicy/checkmodule.c<br>
@@ -228,7 +228,6 @@ int main(int argc, char **argv)<br>
                if (optind != argc)<br>
                        usage(argv[0]);<br>
        }<br>
-       printf(&quot;%s:  loading policy configuration from %s\n&quot;, argv[0], file);<br>
<br>
        /* Set policydb and sidtab used by libsepol service functions<br>
           to my structures, so that I can directly populate and<br>
@@ -302,8 +301,6 @@ int main(int argc, char **argv)<br>
<br>
        sepol_sidtab_destroy(&amp;sidtab);<br>
<br>
-       printf(&quot;%s:  policy configuration loaded\n&quot;, argv[0]);<br>
-<br>
        if (outfile) {<br>
                FILE *outfp = fopen(outfile, &quot;w&quot;);<br>
<br>
@@ -313,16 +310,11 @@ int main(int argc, char **argv)<br>
                }<br>
<br>
                if (!cil) {<br>
-                       printf(&quot;%s:  writing binary representation (version %d) to %s\n&quot;,<br>
-                                  argv[0], policyvers, outfile);<br>
-<br>
                        if (write_binary_policy(&amp;modpolicydb, outfp) != 0) {<br>
                                fprintf(stderr, &quot;%s:  error writing %s\n&quot;, argv[0], outfile);<br>
                                exit(1);<br>
                        }<br>
                } else {<br>
-                       printf(&quot;%s:  writing CIL to %s\n&quot;,argv[0], outfile);<br>
-<br>
                        if (sepol_module_policydb_to_cil(outfp, &amp;modpolicydb, 0) != 0) {<br>
                                fprintf(stderr, &quot;%s:  error writing %s\n&quot;, argv[0], outfile);<br>
                                exit(1);<br>
diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c<br>
index fbda4558..12c4c405 100644<br>
--- a/checkpolicy/checkpolicy.c<br>
+++ b/checkpolicy/checkpolicy.c<br>
@@ -512,8 +512,6 @@ int main(int argc, char **argv)<br>
                if (optind != argc)<br>
                        usage(argv[0]);<br>
        }<br>
-       printf(&quot;%s:  loading policy configuration from %s\n&quot;, argv[0], file);<br>
-<br>
        /* Set policydb and sidtab used by libsepol service functions<br>
           to my structures, so that I can directly populate and<br>
           manipulate them. */<br>
@@ -623,8 +621,6 @@ int main(int argc, char **argv)<br>
        if (policydb_load_isids(&amp;policydb, &amp;sidtab))<br>
                exit(1);<br>
<br>
-       printf(&quot;%s:  policy configuration loaded\n&quot;, argv[0]);<br>
-<br>
        if (outfile) {<br>
                outfp = fopen(outfile, &quot;w&quot;);<br>
                if (!outfp) {<br>
@@ -636,8 +632,6 @@ int main(int argc, char **argv)<br>
<br>
                if (!cil) {<br>
                        if (!conf) {<br>
-                               printf(&quot;%s:  writing binary representation (version %d) to %s\n&quot;, argv[0], policyvers, outfile);<br>
-<br>
                                policydb.policy_type = POLICY_KERN;<br>
<br>
                                policy_file_init(&amp;pf);<br>
@@ -645,8 +639,6 @@ int main(int argc, char **argv)<br>
                                pf.fp = outfp;<br>
                                ret = policydb_write(&amp;policydb, &amp;pf);<br>
                        } else {<br>
-                               printf(&quot;%s:  writing policy.conf to %s\n&quot;,<br>
-                                      argv[0], outfile);<br>
                                ret = sepol_kernel_policydb_to_conf(outfp, policydbp);<br>
                        }<br>
                        if (ret) {<br>
@@ -655,7 +647,6 @@ int main(int argc, char **argv)<br>
                                exit(1);<br>
                        }<br>
                } else {<br>
-                       printf(&quot;%s:  writing CIL to %s\n&quot;,argv[0], outfile);<br>
                        if (binary) {<br>
                                ret = sepol_kernel_policydb_to_cil(outfp, policydbp);<br>
                        } else {<br>
@@ -894,8 +885,6 @@ int main(int argc, char **argv)<br>
                        FGETS(ans, sizeof(ans), stdin);<br>
                        pathlen = strlen(ans);<br>
                        ans[pathlen - 1] = 0;<br>
-                       printf(&quot;%s:  loading policy configuration from %s\n&quot;,<br>
-                              argv[0], ans);<br>
                        fd = open(ans, O_RDONLY);<br>
                        if (fd &lt; 0) {<br>
                                fprintf(stderr, &quot;Can&#39;t open &#39;%s&#39;:  %s\n&quot;,<br>
-- <br>
2.19.0.397.gdd90340f6a-goog<br>
<br>
_______________________________________________<br>
Selinux mailing list<br>
<a href="mailto:Selinux@tycho.nsa.gov" target="_blank">Selinux@tycho.nsa.gov</a><br>
To unsubscribe, send email to <a href="mailto:Selinux-leave@tycho.nsa.gov" target="_blank">Selinux-leave@tycho.nsa.gov</a>.<br>
To get help, send an email containing &quot;help&quot; to <a href="mailto:Selinux-request@tycho.nsa.gov" target="_blank">Selinux-request@tycho.nsa.gov</a>.<br>
</blockquote></div></div>
Stephen Smalley Sept. 19, 2018, 7:38 p.m. UTC | #2
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).

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().

> 
> On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux 
> <selinux@tycho.nsa.gov <mailto:selinux@tycho.nsa.gov>> 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 <nnk@google.com <mailto:nnk@google.com>>
>     ---
>       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
>     Selinux@tycho.nsa.gov <mailto:Selinux@tycho.nsa.gov>
>     To unsubscribe, send email to Selinux-leave@tycho.nsa.gov
>     <mailto:Selinux-leave@tycho.nsa.gov>.
>     To get help, send an email containing "help" to
>     Selinux-request@tycho.nsa.gov <mailto:Selinux-request@tycho.nsa.gov>.
> 
> 
> 
> _______________________________________________
> Selinux mailing list
> Selinux@tycho.nsa.gov
> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> To get help, send an email containing "help" to Selinux-request@tycho.nsa.gov.
>
William Roberts Sept. 19, 2018, 7:41 p.m. UTC | #3
On Wed, Sep 19, 2018 at 12:36 PM Stephen Smalley <sds@tycho.nsa.gov> 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.



> 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.


> >
> > On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux
> > <selinux@tycho.nsa.gov <mailto:selinux@tycho.nsa.gov>> 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 <nnk@google.com <mailto:nnk@google.com
> >>
> >     ---
> >       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
> >     Selinux@tycho.nsa.gov <mailto:Selinux@tycho.nsa.gov>
> >     To unsubscribe, send email to Selinux-leave@tycho.nsa.gov
> >     <mailto:Selinux-leave@tycho.nsa.gov>.
> >     To get help, send an email containing "help" to
> >     Selinux-request@tycho.nsa.gov <mailto:Selinux-request@tycho.nsa.gov
> >.
> >
> >
> >
> > _______________________________________________
> > Selinux mailing list
> > Selinux@tycho.nsa.gov
> > To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> > To get help, send an email containing "help" to
> Selinux-request@tycho.nsa.gov.
> >
>
>
<div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 19, 2018 at 12:36 PM Stephen Smalley &lt;<a href="mailto:sds@tycho.nsa.gov">sds@tycho.nsa.gov</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 09/19/2018 03:21 PM, William Roberts wrote:<br>
&gt; Some people might be checking this output since it&#39;s been there so long,<br>
&gt; -s would be a good way to go.<br>
&gt; <br>
&gt; Alternatively, a way to bring back this information via a verbose option <br>
&gt; -V could<br>
&gt; be considered.<br>
&gt; <br>
&gt; Either way, a simple logging mechanism analogous to<br>
&gt; LOGV/LOGW/LOGE could be useful, I wonder what subordinate routines<br>
&gt; are logging. IIRC it was all fprintf(stderr) stuff in libselinux proper <br>
&gt; as you allude<br>
&gt; to in the redirection of stdout comment. We don&#39;t need to address this <br>
&gt; in this<br>
&gt; patch, but we may want to consider it at some point.<br>
&gt; <br>
&gt; I would lean towards a silent flag as it&#39;s backwards compatible,<br>
&gt; but noting that it doesn&#39;t suppress subordinate callers.<br>
&gt; <br>
&gt; I would also yield that opinion, as removing it works for me.<br>
<br>
I&#39;m ok dropping the output unless someone knows of an existing user that <br>
relies upon it (which I can&#39;t really envision).<br></blockquote><div><br></div><div>Why don&#39;t we extend the review period to 72 hours, and ill apply this</div><div>Friday unless we hear of this breaking someone. Essentially</div><div>consider this a soft-ack.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
With regard to subordinate routines, libsepol has sepol_debug(0) or <br>
sepol_msg_set_callback() to suppress or redirect its logging.</blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
checkpolicy doesn&#39;t use libselinux but it likewise has <br>
selinux_set_callback().<br></blockquote><div><br></div><div>What about things like:</div><div><div>libselinux/src/load_policy.c:299:<span style="white-space:pre">		</span>fprintf(stderr, &quot;libselinux:  %s\n&quot;, errormsg);</div></div><div><br></div><div>Also utils and others are using fprintf directly.... perhaps something we wish to make common</div><div>across utilities and subordinate libs.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
&gt; <br>
&gt; On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux <br>
&gt; &lt;<a href="mailto:selinux@tycho.nsa.gov" target="_blank">selinux@tycho.nsa.gov</a> &lt;mailto:<a href="mailto:selinux@tycho.nsa.gov" target="_blank">selinux@tycho.nsa.gov</a>&gt;&gt; wrote:<br>
&gt; <br>
&gt;     Reduce noise when calling the checkpolicy command line. In Android, this<br>
&gt;     creates unnecessary build noise which we&#39;d like to avoid.<br>
&gt; <br>
&gt;     <a href="https://en.wikipedia.org/wiki/Unix_philosophy" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Unix_philosophy</a><br>
&gt; <br>
&gt;        Rule of Silence<br>
&gt;        Developers should design programs so that they do not print<br>
&gt;        unnecessary output. This rule aims to allow other programs<br>
&gt;        and developers to pick out the information they need from a<br>
&gt;        program&#39;s output without having to parse verbosity.<br>
&gt; <br>
&gt;     An alternative approach would be to add a -s (silent) option to these<br>
&gt;     tools, or to have the Android build system redirect stdout to /dev/null.<br>
&gt; <br>
&gt;     Signed-off-by: Nick Kralevich &lt;<a href="mailto:nnk@google.com" target="_blank">nnk@google.com</a> &lt;mailto:<a href="mailto:nnk@google.com" target="_blank">nnk@google.com</a>&gt;&gt;<br>
&gt;     ---<br>
&gt;       checkpolicy/checkmodule.c |  8 --------<br>
&gt;       checkpolicy/checkpolicy.c | 11 -----------<br>
&gt;       2 files changed, 19 deletions(-)<br>
&gt; <br>
&gt;     diff --git a/checkpolicy/checkmodule.c b/checkpolicy/checkmodule.c<br>
&gt;     index 46ce258f..8edc1f8c 100644<br>
&gt;     --- a/checkpolicy/checkmodule.c<br>
&gt;     +++ b/checkpolicy/checkmodule.c<br>
&gt;     @@ -228,7 +228,6 @@ int main(int argc, char **argv)<br>
&gt;                      if (optind != argc)<br>
&gt;                              usage(argv[0]);<br>
&gt;              }<br>
&gt;     -       printf(&quot;%s:  loading policy configuration from %s\n&quot;,<br>
&gt;     argv[0], file);<br>
&gt; <br>
&gt;              /* Set policydb and sidtab used by libsepol service functions<br>
&gt;                 to my structures, so that I can directly populate and<br>
&gt;     @@ -302,8 +301,6 @@ int main(int argc, char **argv)<br>
&gt; <br>
&gt;              sepol_sidtab_destroy(&amp;sidtab);<br>
&gt; <br>
&gt;     -       printf(&quot;%s:  policy configuration loaded\n&quot;, argv[0]);<br>
&gt;     -<br>
&gt;              if (outfile) {<br>
&gt;                      FILE *outfp = fopen(outfile, &quot;w&quot;);<br>
&gt; <br>
&gt;     @@ -313,16 +310,11 @@ int main(int argc, char **argv)<br>
&gt;                      }<br>
&gt; <br>
&gt;                      if (!cil) {<br>
&gt;     -                       printf(&quot;%s:  writing binary representation<br>
&gt;     (version %d) to %s\n&quot;,<br>
&gt;     -                                  argv[0], policyvers, outfile);<br>
&gt;     -<br>
&gt;                              if (write_binary_policy(&amp;modpolicydb,<br>
&gt;     outfp) != 0) {<br>
&gt;                                      fprintf(stderr, &quot;%s:  error writing<br>
&gt;     %s\n&quot;, argv[0], outfile);<br>
&gt;                                      exit(1);<br>
&gt;                              }<br>
&gt;                      } else {<br>
&gt;     -                       printf(&quot;%s:  writing CIL to %s\n&quot;,argv[0],<br>
&gt;     outfile);<br>
&gt;     -<br>
&gt;                              if (sepol_module_policydb_to_cil(outfp,<br>
&gt;     &amp;modpolicydb, 0) != 0) {<br>
&gt;                                      fprintf(stderr, &quot;%s:  error writing<br>
&gt;     %s\n&quot;, argv[0], outfile);<br>
&gt;                                      exit(1);<br>
&gt;     diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c<br>
&gt;     index fbda4558..12c4c405 100644<br>
&gt;     --- a/checkpolicy/checkpolicy.c<br>
&gt;     +++ b/checkpolicy/checkpolicy.c<br>
&gt;     @@ -512,8 +512,6 @@ int main(int argc, char **argv)<br>
&gt;                      if (optind != argc)<br>
&gt;                              usage(argv[0]);<br>
&gt;              }<br>
&gt;     -       printf(&quot;%s:  loading policy configuration from %s\n&quot;,<br>
&gt;     argv[0], file);<br>
&gt;     -<br>
&gt;              /* Set policydb and sidtab used by libsepol service functions<br>
&gt;                 to my structures, so that I can directly populate and<br>
&gt;                 manipulate them. */<br>
&gt;     @@ -623,8 +621,6 @@ int main(int argc, char **argv)<br>
&gt;              if (policydb_load_isids(&amp;policydb, &amp;sidtab))<br>
&gt;                      exit(1);<br>
&gt; <br>
&gt;     -       printf(&quot;%s:  policy configuration loaded\n&quot;, argv[0]);<br>
&gt;     -<br>
&gt;              if (outfile) {<br>
&gt;                      outfp = fopen(outfile, &quot;w&quot;);<br>
&gt;                      if (!outfp) {<br>
&gt;     @@ -636,8 +632,6 @@ int main(int argc, char **argv)<br>
&gt; <br>
&gt;                      if (!cil) {<br>
&gt;                              if (!conf) {<br>
&gt;     -                               printf(&quot;%s:  writing binary<br>
&gt;     representation (version %d) to %s\n&quot;, argv[0], policyvers, outfile);<br>
&gt;     -<br>
&gt;                                      policydb.policy_type = POLICY_KERN;<br>
&gt; <br>
&gt;                                      policy_file_init(&amp;pf);<br>
&gt;     @@ -645,8 +639,6 @@ int main(int argc, char **argv)<br>
&gt;                                      pf.fp = outfp;<br>
&gt;                                      ret = policydb_write(&amp;policydb, &amp;pf);<br>
&gt;                              } else {<br>
&gt;     -                               printf(&quot;%s:  writing policy.conf to<br>
&gt;     %s\n&quot;,<br>
&gt;     -                                      argv[0], outfile);<br>
&gt;                                      ret =<br>
&gt;     sepol_kernel_policydb_to_conf(outfp, policydbp);<br>
&gt;                              }<br>
&gt;                              if (ret) {<br>
&gt;     @@ -655,7 +647,6 @@ int main(int argc, char **argv)<br>
&gt;                                      exit(1);<br>
&gt;                              }<br>
&gt;                      } else {<br>
&gt;     -                       printf(&quot;%s:  writing CIL to %s\n&quot;,argv[0],<br>
&gt;     outfile);<br>
&gt;                              if (binary) {<br>
&gt;                                      ret =<br>
&gt;     sepol_kernel_policydb_to_cil(outfp, policydbp);<br>
&gt;                              } else {<br>
&gt;     @@ -894,8 +885,6 @@ int main(int argc, char **argv)<br>
&gt;                              FGETS(ans, sizeof(ans), stdin);<br>
&gt;                              pathlen = strlen(ans);<br>
&gt;                              ans[pathlen - 1] = 0;<br>
&gt;     -                       printf(&quot;%s:  loading policy configuration<br>
&gt;     from %s\n&quot;,<br>
&gt;     -                              argv[0], ans);<br>
&gt;                              fd = open(ans, O_RDONLY);<br>
&gt;                              if (fd &lt; 0) {<br>
&gt;                                      fprintf(stderr, &quot;Can&#39;t open &#39;%s&#39;: <br>
&gt;     %s\n&quot;,<br>
&gt;     -- <br>
&gt;     2.19.0.397.gdd90340f6a-goog<br>
&gt; <br>
&gt;     _______________________________________________<br>
&gt;     Selinux mailing list<br>
&gt;     <a href="mailto:Selinux@tycho.nsa.gov" target="_blank">Selinux@tycho.nsa.gov</a> &lt;mailto:<a href="mailto:Selinux@tycho.nsa.gov" target="_blank">Selinux@tycho.nsa.gov</a>&gt;<br>
&gt;     To unsubscribe, send email to <a href="mailto:Selinux-leave@tycho.nsa.gov" target="_blank">Selinux-leave@tycho.nsa.gov</a><br>
&gt;     &lt;mailto:<a href="mailto:Selinux-leave@tycho.nsa.gov" target="_blank">Selinux-leave@tycho.nsa.gov</a>&gt;.<br>
&gt;     To get help, send an email containing &quot;help&quot; to<br>
&gt;     <a href="mailto:Selinux-request@tycho.nsa.gov" target="_blank">Selinux-request@tycho.nsa.gov</a> &lt;mailto:<a href="mailto:Selinux-request@tycho.nsa.gov" target="_blank">Selinux-request@tycho.nsa.gov</a>&gt;.<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; Selinux mailing list<br>
&gt; <a href="mailto:Selinux@tycho.nsa.gov" target="_blank">Selinux@tycho.nsa.gov</a><br>
&gt; To unsubscribe, send email to <a href="mailto:Selinux-leave@tycho.nsa.gov" target="_blank">Selinux-leave@tycho.nsa.gov</a>.<br>
&gt; To get help, send an email containing &quot;help&quot; to <a href="mailto:Selinux-request@tycho.nsa.gov" target="_blank">Selinux-request@tycho.nsa.gov</a>.<br>
&gt; <br>
<br>
</blockquote></div></div></div>
Stephen Smalley Sept. 19, 2018, 7:48 p.m. UTC | #4
On 09/19/2018 03:41 PM, William Roberts wrote:
> 
> 
> On Wed, Sep 19, 2018 at 12:36 PM Stephen Smalley <sds@tycho.nsa.gov 
> <mailto:sds@tycho.nsa.gov>> 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.
> 
>     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().

> 
> 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.

> 
> 
>      >
>      > On Wed, Sep 19, 2018 at 12:13 PM Nick Kralevich via Selinux
>      > <selinux@tycho.nsa.gov <mailto:selinux@tycho.nsa.gov>
>     <mailto:selinux@tycho.nsa.gov <mailto:selinux@tycho.nsa.gov>>> 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 <nnk@google.com
>     <mailto:nnk@google.com> <mailto:nnk@google.com <mailto:nnk@google.com>>>
>      >     ---
>      >       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
>      > Selinux@tycho.nsa.gov <mailto:Selinux@tycho.nsa.gov>
>     <mailto:Selinux@tycho.nsa.gov <mailto:Selinux@tycho.nsa.gov>>
>      >     To unsubscribe, send email to Selinux-leave@tycho.nsa.gov
>     <mailto:Selinux-leave@tycho.nsa.gov>
>      >     <mailto:Selinux-leave@tycho.nsa.gov
>     <mailto:Selinux-leave@tycho.nsa.gov>>.
>      >     To get help, send an email containing "help" to
>      > Selinux-request@tycho.nsa.gov
>     <mailto:Selinux-request@tycho.nsa.gov>
>     <mailto:Selinux-request@tycho.nsa.gov
>     <mailto:Selinux-request@tycho.nsa.gov>>.
>      >
>      >
>      >
>      > _______________________________________________
>      > Selinux mailing list
>      > Selinux@tycho.nsa.gov <mailto:Selinux@tycho.nsa.gov>
>      > To unsubscribe, send email to Selinux-leave@tycho.nsa.gov
>     <mailto:Selinux-leave@tycho.nsa.gov>.
>      > To get help, send an email containing "help" to
>     Selinux-request@tycho.nsa.gov <mailto:Selinux-request@tycho.nsa.gov>.
>      >
>
William Roberts Sept. 21, 2018, 7:52 p.m. UTC | #5
merged: https://github.com/SELinuxProject/selinux/pull/99

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

Patch

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",