mdev: Rob's #if forest removal
[oweals/busybox.git] / selinux / setfiles.c
index 08b911a03078cd38754ac04701f480068b9a37fe..8185d7810a9dd491228a616ca6f6096e1ee14c01 100644 (file)
@@ -99,7 +99,7 @@ enum {
 #define FLAG_R               (option_mask32 & OPT_R)
 
 
-static void qprintf(const char *fmt, ...)
+static void qprintf(const char *fmt UNUSED_PARAM, ...)
 {
        /* quiet, do nothing */
 }
@@ -112,7 +112,7 @@ static void inc_err(void)
        }
 }
 
-static void add_exclude(const char *const directory)
+static void add_exclude(const char *directory)
 {
        struct stat sb;
        size_t len;
@@ -189,7 +189,7 @@ static int match(const char *name, struct stat *sb, char **con)
                        file_sep = strrchr(tmp_path, '/');
                        if (file_sep == tmp_path) {
                                file_sep++;
-                               p[0] = '\0';
+                               path[0] = '\0';
                                p = path;
                        } else if (file_sep) {
                                *file_sep++ = '\0';
@@ -284,8 +284,8 @@ static int restore(const char *file)
                if (count % 0x400 == 0) { /* every 1024 times */
                        count = (count % (80*0x400));
                        if (count == 0)
-                               fputc('\n', stdout);
-                       fputc('*', stdout);
+                               bb_putchar('\n');
+                       bb_putchar('*');
                        fflush(stdout);
                }
        }
@@ -391,8 +391,11 @@ static int restore(const char *file)
  * This function is called by recursive_action on each file during
  * the directory traversal.
  */
-static int apply_spec(const char *file,
-                     struct stat *sb, void *userData, int depth)
+static int FAST_FUNC apply_spec(
+               const char *file,
+               struct stat *sb,
+               void *userData UNUSED_PARAM,
+               int depth UNUSED_PARAM)
 {
        if (!follow_mounts) {
                /* setfiles does not process across different mount points */
@@ -486,7 +489,7 @@ static int process_one(char *name)
        goto out;
 }
 
-int setfiles_main(int argc, char **argv);
+int setfiles_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int setfiles_main(int argc, char **argv)
 {
        struct stat sb;
@@ -537,10 +540,10 @@ int setfiles_main(int argc, char **argv)
        opt_complementary = "e::vv:v--p:p--v:v--q:q--v";
        /* Option order must match OPT_x definitions! */
        if (applet_name[0] == 'r') { /* restorecon */
-               flags = getopt32(argc, argv, "de:f:ilnpqrsvo:FWR",
+               flags = getopt32(argv, "de:f:ilnpqrsvo:FWR",
                        &exclude_dir, &input_filename, &out_filename, &verbose);
        } else { /* setfiles */
-               flags = getopt32(argc, argv, "de:f:ilnpqr:svo:FW"
+               flags = getopt32(argv, "de:f:ilnpqr:svo:FW"
                                USE_FEATURE_SETFILES_CHECK_OPTION("c:"),
                        &exclude_dir, &input_filename, &rootpath, &out_filename,
                                 USE_FEATURE_SETFILES_CHECK_OPTION(&policyfile,)
@@ -551,7 +554,7 @@ int setfiles_main(int argc, char **argv)
        if ((applet_name[0] == 's') && (flags & OPT_c)) {
                FILE *policystream;
 
-               policystream = xfopen(policyfile, "r");
+               policystream = xfopen_for_read(policyfile);
                if (sepol_set_policydb_from_file(policystream) < 0) {
                        bb_error_msg_and_die("sepol_set_policydb_from_file on %s", policyfile);
                }
@@ -572,7 +575,7 @@ int setfiles_main(int argc, char **argv)
        if (flags & OPT_o) {
                outfile = stdout;
                if (NOT_LONE_CHAR(out_filename, '-')) {
-                       outfile = xfopen(out_filename, "w");
+                       outfile = xfopen_for_write(out_filename);
                }
        }
        if (applet_name[0] == 'r') { /* restorecon */
@@ -595,7 +598,7 @@ int setfiles_main(int argc, char **argv)
                if (argc == 1)
                        bb_show_usage();
                if (stat(argv[optind], &sb) < 0) {
-                       bb_perror_msg_and_die("%s", argv[optind]);
+                       bb_simple_perror_msg_and_die(argv[optind]);
                }
                if (!S_ISREG(sb.st_mode)) {
                        bb_error_msg_and_die("spec file %s is not a regular file", argv[optind]);
@@ -603,13 +606,13 @@ int setfiles_main(int argc, char **argv)
                /* Load the file contexts configuration and check it. */
                rc = matchpathcon_init(argv[optind]);
                if (rc < 0) {
-                       bb_perror_msg_and_die("%s", argv[optind]);
+                       bb_simple_perror_msg_and_die(argv[optind]);
                }
 
                optind++;
 
                if (nerr)
-                       exit(1);
+                       exit(EXIT_FAILURE);
        }
 
        if (input_filename) {
@@ -617,7 +620,7 @@ int setfiles_main(int argc, char **argv)
                FILE *f = stdin;
 
                if (NOT_LONE_CHAR(input_filename, '-'))
-                       f = xfopen(input_filename, "r");
+                       f = xfopen_for_read(input_filename);
                while ((len = getline(&buf, &buf_len, f)) > 0) {
                        buf[len - 1] = '\0';
                        errors |= process_one(buf);