libselinux/utils: print errno on failure
PATCH 1/1 libselinux/utils: print errno on failure
Print error description on failure after functions known to set errno.
Also mention the library function name in getenforce, policyvers and setenforce instead of the program name twice.
--- libselinux/utils/compute_av.c | 3 ++- libselinux/utils/compute_create.c | 5 +++-- libselinux/utils/compute_member.c | 5 +++-- libselinux/utils/compute_relabel.c | 5 +++-- libselinux/utils/getconlist.c | 2 +- libselinux/utils/getdefaultcon.c | 2 +- libselinux/utils/getenforce.c | 4 +++- libselinux/utils/getfilecon.c | 6 ++++-- libselinux/utils/getpidcon.c | 4 +++- libselinux/utils/policyvers.c | 4 +++- libselinux/utils/selabel_digest.c | 2 +- libselinux/utils/selabel_get_digests_all_partial_matches.c | 3 ++- libselinux/utils/selabel_lookup.c | 3 ++- libselinux/utils/selabel_lookup_best_match.c | 3 ++- libselinux/utils/selabel_partial_match.c | 3 ++- libselinux/utils/setenforce.c | 3 ++- libselinux/utils/setfilecon.c | 6 ++++-- 17 files changed, 41 insertions(+), 22 deletions(-)
libselinux/utils/compute_av.c +2 -1
@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h>
@@ -35,7 +36,7 @@ int main(int argc, char **argv) ret =security_compute_av (argv[1 ], argv[2 ], tclass,1 , &avd);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_av failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_compute_av failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }
libselinux/utils/compute_create.c +3 -2
@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h>
@@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_create (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_create failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_create failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }
libselinux/utils/compute_member.c +3 -2
@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h>
@@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_member (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_member failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_member failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }
libselinux/utils/compute_relabel.c +3 -2
@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h>
@@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_relabel (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_relabel failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_relabel failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }
libselinux/utils/getconlist.c +1 -1
@@ -55,7 +55,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));free (level);return 2 ; }
libselinux/utils/getdefaultcon.c +1 -1
@@ -62,7 +62,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));return 2 ; } }else
libselinux/utils/getenforce.c +3 -1
@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main(int argc __attribute__ ((unused)),
@@ -16,7 +18,7 @@ int main(int argc __attribute__ ((unused)),if (rc ==1 ) { rc =security_getenforce ();if (rc <0 ) { -fputs ("getenforce: getenforce() failed" , stderr); +fprintf (stderr,"getenforce: security_getenforce() failed: %s\n" ,strerror (errno));return 2 ; }
libselinux/utils/getfilecon.c +4 -2
@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)
@@ -16,8 +18,8 @@ int main(int argc, char **argv)for (i =1 ; i < argc; i++) { rc =getfilecon (argv[i], &buf);if (rc <0 ) { -fprintf (stderr,"%s: getfilecon(%s) failed\n" , argv[0 ], - argv[i]); +fprintf (stderr,"%s: getfilecon(%s) failed: %s\n" , argv[0 ], + argv[i],strerror (errno));exit (2 ); }printf ("%s\t%s\n" , argv[i], buf);
libselinux/utils/getpidcon.c +3 -1
@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)
@@ -21,7 +23,7 @@ int main(int argc, char **argv) rc =getpidcon (pid, &buf);if (rc <0 ) { -fprintf (stderr,"%s: getpidcon() failed\n" , argv[0 ]); +fprintf (stderr,"%s: getpidcon() failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }
libselinux/utils/policyvers.c +3 -1
@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc __attribute__ ((unused)),char **argv)
@@ -9,7 +11,7 @@ int main(int argc __attribute__ ((unused)), char **argv) rc =security_policyvers ();if (rc <0 ) { -fprintf (stderr,"%s: policyvers() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_policyvers() failed: %s\n" , argv[0 ],strerror (errno));exit (2 ); }
libselinux/utils/selabel_digest.c +1 -1
@@ -34,7 +34,7 @@ static int run_check_digest(char *cmd, char *selabel_digest) fp =popen (cmd,"r" );if (!fp) { -printf ("Failed to run command line\n" ); +fprintf (stderr,"Failed to run command '%s': %s\n" , cmd,strerror (errno));return -1 ; }
libselinux/utils/selabel_get_digests_all_partial_matches.c +2 -1
@@ -77,7 +77,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }
libselinux/utils/selabel_lookup.c +2 -1
@@ -91,7 +91,8 @@ int main(int argc, char **argv) hnd =selabel_open (backend, selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }
libselinux/utils/selabel_lookup_best_match.c +2 -1
@@ -117,7 +117,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , options,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno)); rc =-1 ; goto out; }
libselinux/utils/selabel_partial_match.c +2 -1
@@ -61,7 +61,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }
libselinux/utils/setenforce.c +2 -1
@@ -4,6 +4,7 @@#include <ctype.h> #include <string.h> #include <strings.h> +#include <errno.h> #include <selinux/selinux.h> static __attribute__ ((__noreturn__))void usage (const char *progname)
@@ -35,7 +36,7 @@ int main(int argc, char **argv)usage (argv[0 ]); }if (rc <0 ) { -fprintf (stderr,"%s: setenforce() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_setenforce() failed: %s\n" , argv[0 ],strerror (errno));return 2 ; }return 0 ;
libselinux/utils/setfilecon.c +4 -2
@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)
@@ -15,8 +17,8 @@ int main(int argc, char **argv)for (i =2 ; i < argc; i++) { rc =setfilecon (argv[i], argv[1 ]);if (rc <0 ) { -fprintf (stderr,"%s: setfilecon(%s,%s) failed\n" , - argv[0 ], argv[i], argv[1 ]); +fprintf (stderr,"%s: setfilecon(%s,%s) failed: %s\n" , + argv[0 ], argv[i], argv[1 ],strerror (errno));exit (2 ); } }
Signature · 1 line
2.36.0
Quoted 40 lines · Christian Göttsche
Print error description on failure after functions known to set errno.
Also mention the library function name in getenforce, policyvers and setenforce instead of the program name twice.
Signed-off-by Christian Göttsche <[email protected]>--- libselinux/utils/compute_av.c | 3 ++- libselinux/utils/compute_create.c | 5 +++-- libselinux/utils/compute_member.c | 5 +++-- libselinux/utils/compute_relabel.c | 5 +++-- libselinux/utils/getconlist.c | 2 +- libselinux/utils/getdefaultcon.c | 2 +- libselinux/utils/getenforce.c | 4 +++- libselinux/utils/getfilecon.c | 6 ++++-- libselinux/utils/getpidcon.c | 4 +++- libselinux/utils/policyvers.c | 4 +++- libselinux/utils/selabel_digest.c | 2 +- libselinux/utils/selabel_get_digests_all_partial_matches.c | 3 ++- libselinux/utils/selabel_lookup.c | 3 ++- libselinux/utils/selabel_lookup_best_match.c | 3 ++- libselinux/utils/selabel_partial_match.c | 3 ++- libselinux/utils/setenforce.c | 3 ++- libselinux/utils/setfilecon.c | 6 ++++-- 17 files changed, 41 insertions(+), 22 deletions(-)libselinux/utils/compute_av.c +1
-0@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h>
libselinux/utils/compute_av.c int main(int argc, char **argv) · line 42
Quoted 8 lines
libselinux/utils/compute_av.c +1
-1@@ -35,7 +36,7 @@ int main(int argc, char **argv) ret =security_compute_av (argv[1 ], argv[2 ], tclass,1 , &avd);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_av failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_compute_av failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }
Back in August you converted a bunch of strerror() uses in libselinux to instead use "%m" for thread safety. Since all of these are for utility programs and not the main library, thread safety is not a concern, but is there any reason not to just use "%m"?
Jim
Quoted 302 lines
libselinux/utils/compute_create.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_create (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_create failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_create failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_member.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_member (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_member failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_member failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_relabel.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_relabel (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_relabel failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_relabel failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/getconlist.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));free (level);return 2 ; }libselinux/utils/getdefaultcon.c +1
-1@@ -62,7 +62,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));return 2 ; } }else libselinux/utils/getenforce.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main(int argc __attribute__ ((unused)),@@ -16,7 +18,7 @@ int main(int argc __attribute__ ((unused)),if (rc ==1 ) { rc =security_getenforce ();if (rc <0 ) { -fputs ("getenforce: getenforce() failed" , stderr); +fprintf (stderr,"getenforce: security_getenforce() failed: %s\n" ,strerror (errno));return 2 ; }libselinux/utils/getfilecon.c +4
-2@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -16,8 +18,8 @@ int main(int argc, char **argv)for (i =1 ; i < argc; i++) { rc =getfilecon (argv[i], &buf);if (rc <0 ) { -fprintf (stderr,"%s: getfilecon(%s) failed\n" , argv[0 ], - argv[i]); +fprintf (stderr,"%s: getfilecon(%s) failed: %s\n" , argv[0 ], + argv[i],strerror (errno));exit (2 ); }printf ("%s\t%s\n" , argv[i], buf);libselinux/utils/getpidcon.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -21,7 +23,7 @@ int main(int argc, char **argv) rc =getpidcon (pid, &buf);if (rc <0 ) { -fprintf (stderr,"%s: getpidcon() failed\n" , argv[0 ]); +fprintf (stderr,"%s: getpidcon() failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/policyvers.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc __attribute__ ((unused)),char **argv)@@ -9,7 +11,7 @@ int main(int argc __attribute__ ((unused)), char **argv) rc =security_policyvers ();if (rc <0 ) { -fprintf (stderr,"%s: policyvers() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_policyvers() failed: %s\n" , argv[0 ],strerror (errno));exit (2 ); }libselinux/utils/selabel_digest.c +1
-1@@ -34,7 +34,7 @@ static int run_check_digest(char *cmd, char *selabel_digest) fp =popen (cmd,"r" );if (!fp) { -printf ("Failed to run command line\n" ); +fprintf (stderr,"Failed to run command '%s': %s\n" , cmd,strerror (errno));return -1 ; }libselinux/utils/selabel_get_digests_all_partial_matches.c +2
-1@@ -77,7 +77,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup.c +2
-1@@ -91,7 +91,8 @@ int main(int argc, char **argv) hnd =selabel_open (backend, selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup_best_match.c +2
-1@@ -117,7 +117,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , options,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno)); rc =-1 ; goto out; }libselinux/utils/selabel_partial_match.c +2
-1@@ -61,7 +61,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/setenforce.c +2
-1@@ -4,6 +4,7 @@#include <ctype.h> #include <string.h> #include <strings.h> +#include <errno.h> #include <selinux/selinux.h> static __attribute__ ((__noreturn__))void usage (const char *progname)@@ -35,7 +36,7 @@ int main(int argc, char **argv)usage (argv[0 ]); }if (rc <0 ) { -fprintf (stderr,"%s: setenforce() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_setenforce() failed: %s\n" , argv[0 ],strerror (errno));return 2 ; }return 0 ;libselinux/utils/setfilecon.c +4
-3@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -15,8 +17,8 @@ int main(int argc, char **argv)for (i =2 ; i < argc; i++) { rc =setfilecon (argv[i], argv[1 ]);if (rc <0 ) { -fprintf (stderr,"%s: setfilecon(%s,%s) failed\n" , - argv[0 ], argv[i], argv[1 ]); +fprintf (stderr,"%s: setfilecon(%s,%s) failed: %s\n" , + argv[0 ], argv[i], argv[1 ],strerror (errno));exit (2 ); } } --2.36.0
Quoted 44 lines · James Carter
Quoted 41 lines · Christian Göttsche
Print error description on failure after functions known to set errno.
Also mention the library function name in getenforce, policyvers and setenforce instead of the program name twice.
Signed-off-by Christian Göttsche <[email protected]>--- libselinux/utils/compute_av.c | 3 ++- libselinux/utils/compute_create.c | 5 +++-- libselinux/utils/compute_member.c | 5 +++-- libselinux/utils/compute_relabel.c | 5 +++-- libselinux/utils/getconlist.c | 2 +- libselinux/utils/getdefaultcon.c | 2 +- libselinux/utils/getenforce.c | 4 +++- libselinux/utils/getfilecon.c | 6 ++++-- libselinux/utils/getpidcon.c | 4 +++- libselinux/utils/policyvers.c | 4 +++- libselinux/utils/selabel_digest.c | 2 +- libselinux/utils/selabel_get_digests_all_partial_matches.c | 3 ++- libselinux/utils/selabel_lookup.c | 3 ++- libselinux/utils/selabel_lookup_best_match.c | 3 ++- libselinux/utils/selabel_partial_match.c | 3 ++- libselinux/utils/setenforce.c | 3 ++- libselinux/utils/setfilecon.c | 6 ++++-- 17 files changed, 41 insertions(+), 22 deletions(-)libselinux/utils/compute_av.c +1
-0@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,7 +36,7 @@ int main(int argc, char **argv)
Quoted 12 lines
libselinux/utils/compute_av.c int main(int argc, char **argv) · line 42
Quoted 7 lines
libselinux/utils/compute_av.c +1
-1ret =security_compute_av (argv[1 ], argv[2 ], tclass,1 , &avd);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_av failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_compute_av failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }Back in August you converted a bunch of
strerror()uses in libselinux to instead use "%m" for thread safety. Since all of these are for utility programs and not the main library, thread safety is not a concern, but is there any reason not to just use "%m"?
None to my knowledge, other than matching the surrounding code.
Quoted 305 lines
Jim
Quoted 302 lines
libselinux/utils/compute_create.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_create (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_create failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_create failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_member.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_member (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_member failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_member failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_relabel.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_relabel (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_relabel failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_relabel failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/getconlist.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));free (level);return 2 ; }libselinux/utils/getdefaultcon.c +1
-1@@ -62,7 +62,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));return 2 ; } }else libselinux/utils/getenforce.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main(int argc __attribute__ ((unused)),@@ -16,7 +18,7 @@ int main(int argc __attribute__ ((unused)),if (rc ==1 ) { rc =security_getenforce ();if (rc <0 ) { -fputs ("getenforce: getenforce() failed" , stderr); +fprintf (stderr,"getenforce: security_getenforce() failed: %s\n" ,strerror (errno));return 2 ; }libselinux/utils/getfilecon.c +4
-2@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -16,8 +18,8 @@ int main(int argc, char **argv)for (i =1 ; i < argc; i++) { rc =getfilecon (argv[i], &buf);if (rc <0 ) { -fprintf (stderr,"%s: getfilecon(%s) failed\n" , argv[0 ], - argv[i]); +fprintf (stderr,"%s: getfilecon(%s) failed: %s\n" , argv[0 ], + argv[i],strerror (errno));exit (2 ); }printf ("%s\t%s\n" , argv[i], buf);libselinux/utils/getpidcon.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -21,7 +23,7 @@ int main(int argc, char **argv) rc =getpidcon (pid, &buf);if (rc <0 ) { -fprintf (stderr,"%s: getpidcon() failed\n" , argv[0 ]); +fprintf (stderr,"%s: getpidcon() failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/policyvers.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc __attribute__ ((unused)),char **argv)@@ -9,7 +11,7 @@ int main(int argc __attribute__ ((unused)), char **argv) rc =security_policyvers ();if (rc <0 ) { -fprintf (stderr,"%s: policyvers() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_policyvers() failed: %s\n" , argv[0 ],strerror (errno));exit (2 ); }libselinux/utils/selabel_digest.c +1
-1@@ -34,7 +34,7 @@ static int run_check_digest(char *cmd, char *selabel_digest) fp =popen (cmd,"r" );if (!fp) { -printf ("Failed to run command line\n" ); +fprintf (stderr,"Failed to run command '%s': %s\n" , cmd,strerror (errno));return -1 ; }libselinux/utils/selabel_get_digests_all_partial_matches.c +2
-1@@ -77,7 +77,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup.c +2
-1@@ -91,7 +91,8 @@ int main(int argc, char **argv) hnd =selabel_open (backend, selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup_best_match.c +2
-1@@ -117,7 +117,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , options,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno)); rc =-1 ; goto out; }libselinux/utils/selabel_partial_match.c +2
-1@@ -61,7 +61,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/setenforce.c +2
-1@@ -4,6 +4,7 @@#include <ctype.h> #include <string.h> #include <strings.h> +#include <errno.h> #include <selinux/selinux.h> static __attribute__ ((__noreturn__))void usage (const char *progname)@@ -35,7 +36,7 @@ int main(int argc, char **argv)usage (argv[0 ]); }if (rc <0 ) { -fprintf (stderr,"%s: setenforce() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_setenforce() failed: %s\n" , argv[0 ],strerror (errno));return 2 ; }return 0 ;libselinux/utils/setfilecon.c +4
-3@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -15,8 +17,8 @@ int main(int argc, char **argv)for (i =2 ; i < argc; i++) { rc =setfilecon (argv[i], argv[1 ]);if (rc <0 ) { -fprintf (stderr,"%s: setfilecon(%s,%s) failed\n" , - argv[0 ], argv[i], argv[1 ]); +fprintf (stderr,"%s: setfilecon(%s,%s) failed: %s\n" , + argv[0 ], argv[i], argv[1 ],strerror (errno));exit (2 ); } } --2.36.0
Quoted 7 lines · Christian Göttsche
Print error description on failure after functions known to set errno.
Also mention the library function name in getenforce, policyvers and setenforce instead of the program name twice.
Signed-off-by Christian Göttsche <[email protected]>
Quoted 343 lines
--- libselinux/utils/compute_av.c | 3 ++- libselinux/utils/compute_create.c | 5 +++-- libselinux/utils/compute_member.c | 5 +++-- libselinux/utils/compute_relabel.c | 5 +++-- libselinux/utils/getconlist.c | 2 +- libselinux/utils/getdefaultcon.c | 2 +- libselinux/utils/getenforce.c | 4 +++- libselinux/utils/getfilecon.c | 6 ++++-- libselinux/utils/getpidcon.c | 4 +++- libselinux/utils/policyvers.c | 4 +++- libselinux/utils/selabel_digest.c | 2 +- libselinux/utils/selabel_get_digests_all_partial_matches.c | 3 ++- libselinux/utils/selabel_lookup.c | 3 ++- libselinux/utils/selabel_lookup_best_match.c | 3 ++- libselinux/utils/selabel_partial_match.c | 3 ++- libselinux/utils/setenforce.c | 3 ++- libselinux/utils/setfilecon.c | 6 ++++-- 17 files changed, 41 insertions(+), 22 deletions(-)libselinux/utils/compute_av.c +2
-1@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,7 +36,7 @@ int main(int argc, char **argv) ret =security_compute_av (argv[1 ], argv[2 ], tclass,1 , &avd);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_av failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_compute_av failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_create.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_create (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_create failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_create failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_member.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_member (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_member failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_member failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_relabel.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_relabel (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_relabel failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_relabel failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/getconlist.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));free (level);return 2 ; }libselinux/utils/getdefaultcon.c +1
-1@@ -62,7 +62,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));return 2 ; } }else libselinux/utils/getenforce.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main(int argc __attribute__ ((unused)),@@ -16,7 +18,7 @@ int main(int argc __attribute__ ((unused)),if (rc ==1 ) { rc =security_getenforce ();if (rc <0 ) { -fputs ("getenforce: getenforce() failed" , stderr); +fprintf (stderr,"getenforce: security_getenforce() failed: %s\n" ,strerror (errno));return 2 ; }libselinux/utils/getfilecon.c +4
-2@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -16,8 +18,8 @@ int main(int argc, char **argv)for (i =1 ; i < argc; i++) { rc =getfilecon (argv[i], &buf);if (rc <0 ) { -fprintf (stderr,"%s: getfilecon(%s) failed\n" , argv[0 ], - argv[i]); +fprintf (stderr,"%s: getfilecon(%s) failed: %s\n" , argv[0 ], + argv[i],strerror (errno));exit (2 ); }printf ("%s\t%s\n" , argv[i], buf);libselinux/utils/getpidcon.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -21,7 +23,7 @@ int main(int argc, char **argv) rc =getpidcon (pid, &buf);if (rc <0 ) { -fprintf (stderr,"%s: getpidcon() failed\n" , argv[0 ]); +fprintf (stderr,"%s: getpidcon() failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/policyvers.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc __attribute__ ((unused)),char **argv)@@ -9,7 +11,7 @@ int main(int argc __attribute__ ((unused)), char **argv) rc =security_policyvers ();if (rc <0 ) { -fprintf (stderr,"%s: policyvers() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_policyvers() failed: %s\n" , argv[0 ],strerror (errno));exit (2 ); }libselinux/utils/selabel_digest.c +1
-1@@ -34,7 +34,7 @@ static int run_check_digest(char *cmd, char *selabel_digest) fp =popen (cmd,"r" );if (!fp) { -printf ("Failed to run command line\n" ); +fprintf (stderr,"Failed to run command '%s': %s\n" , cmd,strerror (errno));return -1 ; }libselinux/utils/selabel_get_digests_all_partial_matches.c +2
-1@@ -77,7 +77,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup.c +2
-1@@ -91,7 +91,8 @@ int main(int argc, char **argv) hnd =selabel_open (backend, selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup_best_match.c +2
-1@@ -117,7 +117,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , options,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno)); rc =-1 ; goto out; }libselinux/utils/selabel_partial_match.c +2
-1@@ -61,7 +61,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/setenforce.c +2
-1@@ -4,6 +4,7 @@#include <ctype.h> #include <string.h> #include <strings.h> +#include <errno.h> #include <selinux/selinux.h> static __attribute__ ((__noreturn__))void usage (const char *progname)@@ -35,7 +36,7 @@ int main(int argc, char **argv)usage (argv[0 ]); }if (rc <0 ) { -fprintf (stderr,"%s: setenforce() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_setenforce() failed: %s\n" , argv[0 ],strerror (errno));return 2 ; }return 0 ;libselinux/utils/setfilecon.c +4
-3@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -15,8 +17,8 @@ int main(int argc, char **argv)for (i =2 ; i < argc; i++) { rc =setfilecon (argv[i], argv[1 ]);if (rc <0 ) { -fprintf (stderr,"%s: setfilecon(%s,%s) failed\n" , - argv[0 ], argv[i], argv[1 ]); +fprintf (stderr,"%s: setfilecon(%s,%s) failed: %s\n" , + argv[0 ], argv[i], argv[1 ],strerror (errno));exit (2 ); } } --2.36.0
Quoted 4 lines · James Carter
Quoted 1 line · Christian Göttsche
Quoted 9 lines
Quoted 6 lines
Print error description on failure after functions known to set errno.
Also mention the library function name in getenforce, policyvers and setenforce instead of the program name twice.
Signed-off-by Christian Göttsche <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 343 lines
Quoted 343 lines
--- libselinux/utils/compute_av.c | 3 ++- libselinux/utils/compute_create.c | 5 +++-- libselinux/utils/compute_member.c | 5 +++-- libselinux/utils/compute_relabel.c | 5 +++-- libselinux/utils/getconlist.c | 2 +- libselinux/utils/getdefaultcon.c | 2 +- libselinux/utils/getenforce.c | 4 +++- libselinux/utils/getfilecon.c | 6 ++++-- libselinux/utils/getpidcon.c | 4 +++- libselinux/utils/policyvers.c | 4 +++- libselinux/utils/selabel_digest.c | 2 +- libselinux/utils/selabel_get_digests_all_partial_matches.c | 3 ++- libselinux/utils/selabel_lookup.c | 3 ++- libselinux/utils/selabel_lookup_best_match.c | 3 ++- libselinux/utils/selabel_partial_match.c | 3 ++- libselinux/utils/setenforce.c | 3 ++- libselinux/utils/setfilecon.c | 6 ++++-- 17 files changed, 41 insertions(+), 22 deletions(-)libselinux/utils/compute_av.c +2
-1@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,7 +36,7 @@ int main(int argc, char **argv) ret =security_compute_av (argv[1 ], argv[2 ], tclass,1 , &avd);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_av failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_compute_av failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_create.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_create (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_create failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_create failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_member.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_member (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_member failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_member failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/compute_relabel.c +3
-2@@ -2,6 +2,7 @@#include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <selinux/selinux.h> @@ -35,8 +36,8 @@ int main(int argc, char **argv) ret =security_compute_relabel (argv[1 ], argv[2 ], tclass, &buf);if (ret <0 ) { -fprintf (stderr,"%s: security_compute_relabel failed\n" , - argv[0 ]); +fprintf (stderr,"%s: security_compute_relabel failed: %s\n" , + argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/getconlist.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));free (level);return 2 ; }libselinux/utils/getdefaultcon.c +1
-1@@ -62,7 +62,7 @@ int main(int argc, char **argv)/* If a context wasn't passed, use the current context. */ if (((argc - optind) <2 )) {if (getcon (&cur_context) <0 ) { -fprintf (stderr,"Couldn't get current context.\n" ); +fprintf (stderr,"Couldn't get current context: %s\n" ,strerror (errno));return 2 ; } }else libselinux/utils/getenforce.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main(int argc __attribute__ ((unused)),@@ -16,7 +18,7 @@ int main(int argc __attribute__ ((unused)),if (rc ==1 ) { rc =security_getenforce ();if (rc <0 ) { -fputs ("getenforce: getenforce() failed" , stderr); +fprintf (stderr,"getenforce: security_getenforce() failed: %s\n" ,strerror (errno));return 2 ; }libselinux/utils/getfilecon.c +4
-2@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -16,8 +18,8 @@ int main(int argc, char **argv)for (i =1 ; i < argc; i++) { rc =getfilecon (argv[i], &buf);if (rc <0 ) { -fprintf (stderr,"%s: getfilecon(%s) failed\n" , argv[0 ], - argv[i]); +fprintf (stderr,"%s: getfilecon(%s) failed: %s\n" , argv[0 ], + argv[i],strerror (errno));exit (2 ); }printf ("%s\t%s\n" , argv[i], buf);libselinux/utils/getpidcon.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -21,7 +23,7 @@ int main(int argc, char **argv) rc =getpidcon (pid, &buf);if (rc <0 ) { -fprintf (stderr,"%s: getpidcon() failed\n" , argv[0 ]); +fprintf (stderr,"%s: getpidcon() failed: %s\n" , argv[0 ],strerror (errno));exit (3 ); }libselinux/utils/policyvers.c +3
-1@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc __attribute__ ((unused)),char **argv)@@ -9,7 +11,7 @@ int main(int argc __attribute__ ((unused)), char **argv) rc =security_policyvers ();if (rc <0 ) { -fprintf (stderr,"%s: policyvers() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_policyvers() failed: %s\n" , argv[0 ],strerror (errno));exit (2 ); }libselinux/utils/selabel_digest.c +1
-1@@ -34,7 +34,7 @@ static int run_check_digest(char *cmd, char *selabel_digest) fp =popen (cmd,"r" );if (!fp) { -printf ("Failed to run command line\n" ); +fprintf (stderr,"Failed to run command '%s': %s\n" , cmd,strerror (errno));return -1 ; }libselinux/utils/selabel_get_digests_all_partial_matches.c +2
-1@@ -77,7 +77,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup.c +2
-1@@ -91,7 +91,8 @@ int main(int argc, char **argv) hnd =selabel_open (backend, selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/selabel_lookup_best_match.c +2
-1@@ -117,7 +117,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , options,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno)); rc =-1 ; goto out; }libselinux/utils/selabel_partial_match.c +2
-1@@ -61,7 +61,8 @@ int main(int argc, char **argv) hnd =selabel_open (SELABEL_CTX_FILE , selabel_option,2 );if (!hnd) {fprintf (stderr,"ERROR: selabel_open - Could not obtain " -"handle.\n" ); +"handle: %s\n" , +strerror (errno));return -1 ; }libselinux/utils/setenforce.c +2
-1@@ -4,6 +4,7 @@#include <ctype.h> #include <string.h> #include <strings.h> +#include <errno.h> #include <selinux/selinux.h> static __attribute__ ((__noreturn__))void usage (const char *progname)@@ -35,7 +36,7 @@ int main(int argc, char **argv)usage (argv[0 ]); }if (rc <0 ) { -fprintf (stderr,"%s: setenforce() failed\n" , argv[0 ]); +fprintf (stderr,"%s: security_setenforce() failed: %s\n" , argv[0 ],strerror (errno));return 2 ; }return 0 ;libselinux/utils/setfilecon.c +4
-3@@ -1,6 +1,8 @@#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <selinux/selinux.h> int main (int argc,char **argv)@@ -15,8 +17,8 @@ int main(int argc, char **argv)for (i =2 ; i < argc; i++) { rc =setfilecon (argv[i], argv[1 ]);if (rc <0 ) { -fprintf (stderr,"%s: setfilecon(%s,%s) failed\n" , - argv[0 ], argv[i], argv[1 ]); +fprintf (stderr,"%s: setfilecon(%s,%s) failed: %s\n" , + argv[0 ], argv[i], argv[1 ],strerror (errno));exit (2 ); } } --2.36.0