From fe6346afa27bc7d53050c25563f1a0afc4176aaf Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Thu, 25 Jan 2007 09:51:43 +0000 Subject: [PATCH] Add option to chxid to skip unified files. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2473 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- src/chxid.c | 31 ++++++++++++++++++++++++------- src/fstool.c | 6 ++++-- src/fstool.h | 1 + 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/chxid.c b/src/chxid.c index 7235847..1b8a823 100644 --- a/src/chxid.c +++ b/src/chxid.c @@ -38,7 +38,7 @@ CMDLINE_OPTIONS[] = { { 0,0,0,0 } }; -char const CMDLINE_OPTIONS_SHORT[] = "Rc:x"; +char const CMDLINE_OPTIONS_SHORT[] = "Rc:xU"; void showHelp(int fd, char const *cmd, int res) @@ -46,11 +46,12 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " -c [-Rx] [--] +\n\n" + " -c [-RxU] [--] +\n\n" " Options:\n" " -R ... recurse through directories\n" " -c ... assign the given context/vserver to the file(s)\n" - " -x ... do not cross filesystems\n\n" + " -x ... do not cross filesystems\n" + " -U ... skip unified files\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -66,14 +67,30 @@ showVersion() exit(0); } +static inline bool +isUnified(char const *filename) +{ + uint_least32_t const V = VC_IATTR_IUNLINK|VC_IATTR_IMMUTABLE; + + uint_least32_t flags; + uint_least32_t mask = V; + + if (vc_get_iattr(filename, 0, &flags, &mask)==-1 || (mask & V) != V) + return false; + + return (flags & V)==V ? true : false; +} + bool handleFile(char const *name, char const * display_name) { - int rc = vc_set_iattr(name, global_args->ctx, 0, VC_IATTR_XID); + if (!global_args->no_unified || !isUnified(name)) { + int rc = vc_set_iattr(name, global_args->ctx, 0, VC_IATTR_XID); - if (rc==-1) { - perror(display_name); - return false; + if (rc==-1) { + perror(display_name); + return false; + } } return true; diff --git a/src/fstool.c b/src/fstool.c index d1df02a..7cad977 100644 --- a/src/fstool.c +++ b/src/fstool.c @@ -182,8 +182,9 @@ int main(int argc, char *argv[]) .do_set = false, .do_unset = false, .local_fs = false, - .set_mask = 0, - .del_mask = 0 + .set_mask = 0, + .del_mask = 0, + .no_unified = false, }; global_args = &args; @@ -217,6 +218,7 @@ int main(int argc, char *argv[]) case 'u' : args.do_unset = true; break; case 'c' : args.ctx_str = optarg; break; case 'x' : args.local_fs = true; break; + case 'U' : args.no_unified = true; break; default : WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); diff --git a/src/fstool.h b/src/fstool.h index 4705dfe..1668baa 100644 --- a/src/fstool.h +++ b/src/fstool.h @@ -55,6 +55,7 @@ struct Arguments { bool do_set; bool do_unset; bool local_fs; + bool no_unified; uint32_t set_mask; uint32_t del_mask; -- 1.8.1.5