X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fchxid.c;h=2e86b2b5331ee23de28293ed1f7787b8696c5462;hb=d31714c201a6dd6f058033dea06f2db43e8571e8;hp=e2b6fa8fbd206b30f3706a2c5c223f5b54f8f8cf;hpb=de3e1dc1eae2d6bd6aa11c34290498d966885245;p=util-vserver.git diff --git a/util-vserver/src/chxid.c b/util-vserver/src/chxid.c index e2b6fa8..2e86b2b 100644 --- a/util-vserver/src/chxid.c +++ b/util-vserver/src/chxid.c @@ -38,7 +38,7 @@ CMDLINE_OPTIONS[] = { { 0,0,0,0 } }; -char const CMDLINE_OPTIONS_SHORT[] = "Rc:"; +char const CMDLINE_OPTIONS_SHORT[] = "Rc:x"; void showHelp(int fd, char const *cmd, int res) @@ -46,10 +46,11 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " -c [-R] [--] +\n\n" + " -c [-Rx] [--] +\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" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -65,53 +66,36 @@ showVersion() exit(0); } -static bool -setFile(char const *name, char const * display_name, struct stat const *exp_st) -{ - bool res = false; - int fd = open(name, O_RDONLY); - - if (fd==-1) { - perror("open()"); - return false; - } - - if (!exp_st || - !checkForRace(fd, name, exp_st)) - goto err; - - if (vc_X_set_filecontext(fd, global_args->ctx)==-1) { - //perror("vc_X_set_filecontext()"); - perror(display_name); - goto err; - } - - res = true; - - err: - close(fd); - return res; -} - bool handleFile(char const *name, char const * display_name, struct stat const *exp_st) { - if (S_ISLNK(exp_st->st_mode)) return true; + int rc = vc_set_iattr_compat(name, exp_st->st_dev, exp_st->st_ino, + global_args->ctx, 0, VC_IATTR_XID, + &exp_st->st_mode); - return setFile(name, display_name, exp_st); + if (rc==-1) { + perror(display_name); + return false; + } + + return true; } void -checkParams(struct Arguments const UNUSED *args, int argc) +fixupParams(struct Arguments UNUSED *args, int argc) { if (optind==argc) { WRITE_MSG(2, "No filename given; use '--help' for more information\n"); exit(1); } - if (args->ctx==VC_NOCTX) { - WRITE_MSG(2, "No valid context given; use '--help' for more information\n"); + if (args->ctx_str==0) { + WRITE_MSG(2, "No context given; use '--help' for more information\n"); exit(1); } + + args->ctx = resolveCtx(args->ctx_str); + args->do_display_dir = !args->do_recurse; + args->do_display_dot = true; }