From 821c8a5d6130055152a6042343d469d0a9f13404 Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Fri, 3 Feb 2012 12:14:36 -0500 Subject: [PATCH] On full relabels we will now show a estimated percent complete rather then just *s. --- policycoreutils-rhat.patch | 194 ++++++++++++++++++++++++++++++++++--- policycoreutils.spec | 6 +- 2 files changed, 187 insertions(+), 13 deletions(-) diff --git a/policycoreutils-rhat.patch b/policycoreutils-rhat.patch index c18d986..b1adc66 100644 --- a/policycoreutils-rhat.patch +++ b/policycoreutils-rhat.patch @@ -21,6 +21,13 @@ index c90d4dd..37a7a7a 100644 clean: -rm -f $(TARGETS) *.o +diff --git a/policycoreutils/mcstrans/VERSION b/policycoreutils/mcstrans/VERSION +index d15723f..1c09c74 100644 +--- a/policycoreutils/mcstrans/VERSION ++++ b/policycoreutils/mcstrans/VERSION +@@ -1 +1 @@ +-0.3.2 ++0.3.3 diff --git a/policycoreutils/newrole/newrole.c b/policycoreutils/newrole/newrole.c index 99d0ed7..19e20a8 100644 --- a/policycoreutils/newrole/newrole.c @@ -1126,7 +1133,7 @@ index 17afe23..12cd0fe 100644 (rc, fcontext) = semanage_fcontext_create(self.sh) if rc < 0: diff --git a/policycoreutils/setfiles/restore.c b/policycoreutils/setfiles/restore.c -index 9a7d315..5ade9f1 100644 +index 9a7d315..51020de 100644 --- a/policycoreutils/setfiles/restore.c +++ b/policycoreutils/setfiles/restore.c @@ -1,5 +1,6 @@ @@ -1176,7 +1183,21 @@ index 9a7d315..5ade9f1 100644 if (match(my_file, ftsent->fts_statp, &newcon) < 0) /* Check for no matching specification. */ -@@ -139,74 +143,105 @@ static int restore(FTSENT *ftsent) +@@ -114,7 +118,12 @@ static int restore(FTSENT *ftsent) + if (r_opts->progress) { + r_opts->count++; + if (r_opts->count % STAR_COUNT == 0) { +- fprintf(stdout, "*"); ++ if (r_opts->progress == 1) { ++ fprintf(stdout, "*"); ++ } else { ++ int progress = 100.0 * r_opts->count / r_opts->nfile; ++ fprintf(stdout, "\r%d%%", progress); ++ } + fflush(stdout); + } + } +@@ -139,74 +148,105 @@ static int restore(FTSENT *ftsent) printf("%s: %s matched by %s\n", r_opts->progname, my_file, newcon); } @@ -1311,7 +1332,7 @@ index 9a7d315..5ade9f1 100644 goto out; /* -@@ -220,12 +255,15 @@ static int restore(FTSENT *ftsent) +@@ -220,12 +260,15 @@ static int restore(FTSENT *ftsent) } ret = 1; out: @@ -1327,7 +1348,97 @@ index 9a7d315..5ade9f1 100644 freecon(newcon); return ERR; } -@@ -447,22 +485,6 @@ int add_exclude(const char *directory) +@@ -250,6 +293,44 @@ static int apply_spec(FTSENT *ftsent) + return rc; + } + ++static unsigned round_up(unsigned x, unsigned m) ++{ ++ return m * ((-1 + m + x) / m); ++} ++ ++static unsigned int *bitmap_alloc(unsigned nbits) ++{ ++ unsigned const w_bitmap = round_up(nbits, 8*sizeof(int)) / ++ (8*sizeof(int)); ++ return calloc(w_bitmap, sizeof(int)); ++} ++ ++static void bitmap_free(unsigned int *bmap) ++{ ++ free(bmap); ++} ++ ++#define LG_BPW ((4==sizeof(int)) \ ++ ? 5 \ ++ : ((8==sizeof(int)) \ ++ ? 6 \ ++ : 31 )) ++ ++static unsigned int bitmap_test(unsigned int *const map, unsigned bit) ++{ ++ return ++ map[bit>>LG_BPW] & (1u<<((-1+ (8*sizeof(int))) & bit)); ++} ++ ++static unsigned int bitmap_set(unsigned int *const map, unsigned bit) ++{ ++ unsigned int old = bitmap_test(map, bit); ++ map[bit>>LG_BPW] |= (1u<<((-1+ (8*sizeof(int))) & bit)); ++ return old; ++} ++ ++#include ++ + static int process_one(char *name, int recurse_this_path) + { + int rc = 0; +@@ -284,6 +365,14 @@ static int process_one(char *name, int recurse_this_path) + /* Keep the inode of the first one. */ + dev_num = ftsent->fts_statp->st_dev; + ++ unsigned int *i_bitmap = 0; ++ struct statvfs statvfs_buf; ++ memset(&statvfs_buf, 0, sizeof(statvfs_buf)); ++ if (!statvfs(name, &statvfs_buf)) { ++ r_opts->nfile = statvfs_buf.f_files - statvfs_buf.f_ffree; ++ i_bitmap = bitmap_alloc(statvfs_buf.f_files); ++ } ++ + do { + rc = 0; + /* Skip the post order nodes. */ +@@ -299,6 +388,21 @@ static int process_one(char *name, int recurse_this_path) + continue; + } + } ++ /* FTS_SEEDOT is not set, so fts_read() ignores "." and "..". ++ * Thus the hardlinks for a directory should be ignored. ++ */ ++ if (ftsent->fts_info != FTS_D ++ && 1 < ftsent->fts_statp->st_nlink) { ++ /* Adjust for hardlinks. */ ++ ino_t const inum = ftsent->fts_statp->st_ino; ++ if (inum < statvfs_buf.f_files /* paranoia? */ ++ && !bitmap_test(i_bitmap, inum)) { ++ /* First time for this .st_ino */ ++ bitmap_set(i_bitmap, inum); ++ r_opts->nfile += -1+ ++ ftsent->fts_statp->st_nlink; ++ } ++ } + rc = apply_spec(ftsent); + if (rc == SKIP) + fts_set(fts_handle, ftsent, FTS_SKIP); +@@ -314,6 +418,7 @@ out: + filespec_eval(); + filespec_destroy(); + } ++ bitmap_free(i_bitmap); + if (fts_handle) + fts_close(fts_handle); + return rc; +@@ -447,22 +552,6 @@ int add_exclude(const char *directory) return 0; } @@ -1351,10 +1462,28 @@ index 9a7d315..5ade9f1 100644 * Evaluate the association hash table distribution. */ diff --git a/policycoreutils/setfiles/restore.h b/policycoreutils/setfiles/restore.h -index ac27222..4b39972 100644 +index ac27222..1a3da73 100644 --- a/policycoreutils/setfiles/restore.h +++ b/policycoreutils/setfiles/restore.h -@@ -40,6 +40,7 @@ struct restore_opts { +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + + #define STAR_COUNT 1000 + +@@ -21,7 +22,8 @@ + struct restore_opts { + int add_assoc; /* Track inode associations for conflict detection. */ + int progress; +- unsigned long long count; ++ uint64_t count; /* Number of files processed so far */ ++ uint64_t nfile; /* Estimated total number of files */ + int debug; + int change; + int hard_links; +@@ -40,6 +42,7 @@ struct restore_opts { int fts_flags; /* Flags to fts, e.g. follow links, follow mounts */ const char *selabel_opt_validate; const char *selabel_opt_path; @@ -1474,7 +1603,7 @@ index 7f700ca..2741919 100644 .B \-W display warnings about entries that had no matching files. diff --git a/policycoreutils/setfiles/setfiles.c b/policycoreutils/setfiles/setfiles.c -index fa0cd6a..0ec0eff 100644 +index fa0cd6a..08ec370 100644 --- a/policycoreutils/setfiles/setfiles.c +++ b/policycoreutils/setfiles/setfiles.c @@ -39,7 +39,7 @@ void usage(const char *const name) @@ -1495,7 +1624,7 @@ index fa0cd6a..0ec0eff 100644 char *input_filename = NULL; int use_input_file = 0; char *buf = NULL; -@@ -145,6 +145,8 @@ int main(int argc, char **argv) +@@ -145,12 +145,15 @@ int main(int argc, char **argv) int recurse; /* Recursive descent. */ char *base; int mass_relabel = 0, errors = 0; @@ -1504,7 +1633,14 @@ index fa0cd6a..0ec0eff 100644 memset(&r_opts, 0, sizeof(r_opts)); -@@ -160,6 +162,7 @@ int main(int argc, char **argv) + /* Initialize variables */ + r_opts.progress = 0; + r_opts.count = 0; ++ r_opts.nfile = 0; + r_opts.debug = 0; + r_opts.change = 1; + r_opts.verbose = 0; +@@ -160,6 +163,7 @@ int main(int argc, char **argv) r_opts.outfile = NULL; r_opts.force = 0; r_opts.hard_links = 1; @@ -1512,7 +1648,7 @@ index fa0cd6a..0ec0eff 100644 altpath = NULL; -@@ -217,7 +220,7 @@ int main(int argc, char **argv) +@@ -217,7 +221,7 @@ int main(int argc, char **argv) exclude_non_seclabel_mounts(); /* Process any options. */ @@ -1521,7 +1657,7 @@ index fa0cd6a..0ec0eff 100644 switch (opt) { case 'c': { -@@ -280,6 +283,35 @@ int main(int argc, char **argv) +@@ -280,6 +284,35 @@ int main(int argc, char **argv) case 'n': r_opts.change = 0; break; @@ -1557,7 +1693,41 @@ index fa0cd6a..0ec0eff 100644 case 'o': if (strcmp(optarg, "-") == 0) { r_opts.outfile = stdout; -@@ -433,7 +465,15 @@ int main(int argc, char **argv) +@@ -336,7 +369,7 @@ int main(int argc, char **argv) + "Progress and Verbose mutually exclusive\n"); + usage(argv[0]); + } +- r_opts.progress = 1; ++ r_opts.progress++; + break; + case 'W': + warn_no_match = 1; +@@ -349,6 +382,14 @@ int main(int argc, char **argv) + } + } + ++ for (i = optind; i < argc; i++) { ++ if (!strcmp(argv[i], "/")) { ++ mass_relabel = 1; ++ if (r_opts.progress) ++ r_opts.progress++; ++ } ++ } ++ + if (!iamrestorecon) { + if (policyfile) { + if (optind != (argc - 1)) +@@ -415,9 +456,6 @@ int main(int argc, char **argv) + fclose(f); + } else { + for (i = optind; i < argc; i++) { +- if (!strcmp(argv[i], "/")) +- mass_relabel = 1; +- + errors |= process_glob(argv[i], recurse); + } + } +@@ -433,7 +471,15 @@ int main(int argc, char **argv) if (r_opts.outfile) fclose(r_opts.outfile); diff --git a/policycoreutils.spec b/policycoreutils.spec index ae69470..6e0dc6e 100644 --- a/policycoreutils.spec +++ b/policycoreutils.spec @@ -7,7 +7,7 @@ Summary: SELinux policy core utilities Name: policycoreutils Version: 2.1.10 -Release: 20%{?dist} +Release: 21%{?dist} License: GPLv2 Group: System Environment/Base # Based on git repository with tag 20101221 @@ -356,6 +356,10 @@ fi %{_bindir}/systemctl try-restart restorecond.service >/dev/null 2>&1 || : %changelog +* Fri Feb 3 2012 Dan Walsh - 2.1.10-21 +- On full relabels we will now show a estimated percent complete rather then +just *s. + * Wed Feb 1 2012 Dan Walsh - 2.1.10-20 - Add unit_file.py for sepolgen