-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Our QE team was complaining about getting random exist codes from setfiles, this consolidates the exit error code to be -1. This patch looks good to me. acked. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlJpOKAACgkQrlYvE4MpobOaZQCfVaTcm6MFBM1PRLr8v9KbmUDr WF4An0vO0xOV4tiGphXN7mXdRJjormux =QPV1 -----END PGP SIGNATURE-----
>From 808766c0c9bb320cbf6da4935742cb02be47c42a Mon Sep 17 00:00:00 2001 From: Dan Walsh <dwalsh@xxxxxxxxxx> Date: Fri, 11 Oct 2013 10:37:44 -0400 Subject: [PATCH 68/74] setfiles should always return -1 on failures. Scripts that are looking for -1 failures were getting confused by 1 and > 1 erros. We should be consistant on the error status. --- policycoreutils/setfiles/setfiles.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/policycoreutils/setfiles/setfiles.c b/policycoreutils/setfiles/setfiles.c index b11e49f..9ac3fa5 100644 --- a/policycoreutils/setfiles/setfiles.c +++ b/policycoreutils/setfiles/setfiles.c @@ -56,7 +56,7 @@ void usage(const char *const name) "usage: %s -c policyfile spec_file\n", name, name, name, name); } - exit(1); + exit(-1); } static int nerr = 0; @@ -66,7 +66,7 @@ void inc_err() nerr++; if (nerr > ABORT_ON_ERRORS - 1 && !r_opts.debug) { fprintf(stderr, "Exiting after %d errors.\n", ABORT_ON_ERRORS); - exit(1); + exit(-1); } } @@ -80,7 +80,7 @@ void set_rootpath(const char *arg) if (NULL == r_opts.rootpath) { fprintf(stderr, "%s: insufficient memory for r_opts.rootpath\n", r_opts.progname); - exit(1); + exit(-1); } /* trim trailing /, if present */ @@ -98,7 +98,7 @@ int canoncon(char **contextp) if (policyfile) { if (sepol_check_context(context) < 0) { fprintf(stderr, "invalid context %s\n", context); - exit(1); + exit(-1); } } else if (security_canonicalize_context_raw(context, &tmpcon) == 0) { free(context); @@ -175,7 +175,7 @@ int main(int argc, char **argv) r_opts.progname = strdup(argv[0]); if (!r_opts.progname) { fprintf(stderr, "%s: Out of memory!\n", argv[0]); - exit(1); + exit(-1); } base = basename(r_opts.progname); @@ -242,7 +242,7 @@ int main(int argc, char **argv) fprintf(stderr, "Error opening %s: %s\n", policyfile, strerror(errno)); - exit(1); + exit(-1); } __fsetlocking(policystream, FSETLOCKING_BYCALLER); @@ -252,7 +252,7 @@ int main(int argc, char **argv) fprintf(stderr, "Error reading policy %s: %s\n", policyfile, strerror(errno)); - exit(1); + exit(-1); } fclose(policystream); @@ -268,7 +268,7 @@ int main(int argc, char **argv) break; } if (add_exclude(optarg)) - exit(1); + exit(-1); break; case 'f': use_input_file = 1; @@ -318,13 +318,13 @@ int main(int argc, char **argv) if (optind + 1 >= argc) { fprintf(stderr, "usage: %s -r rootpath\n", argv[0]); - exit(1); + exit(-1); } if (NULL != r_opts.rootpath) { fprintf(stderr, "%s: only one -r can be specified\n", argv[0]); - exit(1); + exit(-1); } set_rootpath(argv[optind++]); break; @@ -337,7 +337,7 @@ int main(int argc, char **argv) if (r_opts.progress) { fprintf(stderr, "Progress and Verbose mutually exclusive\n"); - exit(1); + exit(-1); } r_opts.verbose++; break; @@ -391,12 +391,12 @@ int main(int argc, char **argv) if (stat(argv[optind], &sb) < 0) { perror(argv[optind]); - exit(1); + exit(-1); } if (!S_ISREG(sb.st_mode)) { fprintf(stderr, "%s: spec file %s is not a regular file.\n", argv[0], argv[optind]); - exit(1); + exit(-1); } altpath = argv[optind]; @@ -409,7 +409,7 @@ int main(int argc, char **argv) r_opts.selabel_opt_path = altpath; if (nerr) - exit(1); + exit(-1); restore_init(&r_opts); if (use_input_file) { @@ -452,5 +452,5 @@ int main(int argc, char **argv) if (r_opts.progress && r_opts.count >= STAR_COUNT) printf("\n"); - exit(errors); + exit(errors ? -1: 0); } -- 1.8.3.1