Add a "-x" option to chown(8)/chgrp(1) similar to the same option in

du(1), cp(1) etc, to prevent the crossing of mountpoints whilst using the
commands recursively.

PR:		bin/130855
Submitted by:	keramida
MFC after:	1 month
This commit is contained in:
Gavin Atkinson 2010-02-21 10:14:06 +00:00
parent ba96c16ae8
commit 1901b12462
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=204165
3 changed files with 26 additions and 13 deletions

View File

@ -31,7 +31,7 @@
.\" @(#)chgrp.1 8.3 (Berkeley) 3/31/94 .\" @(#)chgrp.1 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd April 25, 2003 .Dd February 21, 2010
.Dt CHGRP 1 .Dt CHGRP 1
.Os .Os
.Sh NAME .Sh NAME
@ -39,7 +39,7 @@
.Nd change group .Nd change group
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl fhv .Op Fl fhvx
.Oo .Oo
.Fl R .Fl R
.Op Fl H | Fl L | Fl P .Op Fl H | Fl L | Fl P
@ -89,6 +89,8 @@ If the
flag is specified more than once, flag is specified more than once,
.Nm .Nm
will print the filename, followed by the old and new numeric group ID. will print the filename, followed by the old and new numeric group ID.
.It Fl x
File system mount points are not traversed.
.El .El
.Pp .Pp
The The
@ -125,7 +127,9 @@ In previous versions of this system, symbolic links did not have groups.
.Pp .Pp
The The
.Fl v .Fl v
option is non-standard and its use in scripts is not recommended. and
.Fl x
options are non-standard and their use in scripts is not recommended.
.Sh SEE ALSO .Sh SEE ALSO
.Xr chown 2 , .Xr chown 2 ,
.Xr fts 3 , .Xr fts 3 ,

View File

@ -28,7 +28,7 @@
.\" @(#)chown.8 8.3 (Berkeley) 3/31/94 .\" @(#)chown.8 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd April 25, 2003 .Dd February 21, 2010
.Dt CHOWN 8 .Dt CHOWN 8
.Os .Os
.Sh NAME .Sh NAME
@ -36,7 +36,7 @@
.Nd change file owner and group .Nd change file owner and group
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl fhv .Op Fl fhvx
.Oo .Oo
.Fl R .Fl R
.Op Fl H | Fl L | Fl P .Op Fl H | Fl L | Fl P
@ -44,7 +44,7 @@
.Ar owner Ns Op : Ns Ar group .Ar owner Ns Op : Ns Ar group
.Ar .Ar
.Nm .Nm
.Op Fl fhv .Op Fl fhvx
.Oo .Oo
.Fl R .Fl R
.Op Fl H | Fl L | Fl P .Op Fl H | Fl L | Fl P
@ -97,6 +97,8 @@ If the
flag is specified more than once, flag is specified more than once,
.Nm .Nm
will print the filename, followed by the old and new numeric user/group ID. will print the filename, followed by the old and new numeric user/group ID.
.It Fl x
File system mount points are not traversed.
.El .El
.Pp .Pp
The The
@ -146,7 +148,9 @@ owners.
.Pp .Pp
The The
.Fl v .Fl v
option is non-standard and its use in scripts is not recommended. and
.Fl x
options are non-standard and their use in scripts is not recommended.
.Sh SEE ALSO .Sh SEE ALSO
.Xr chgrp 1 , .Xr chgrp 1 ,
.Xr find 1 , .Xr find 1 ,

View File

@ -73,14 +73,14 @@ main(int argc, char **argv)
{ {
FTS *ftsp; FTS *ftsp;
FTSENT *p; FTSENT *p;
int Hflag, Lflag, Rflag, fflag, hflag, vflag; int Hflag, Lflag, Rflag, fflag, hflag, vflag, xflag;
int ch, fts_options, rval; int ch, fts_options, rval;
char *cp; char *cp;
ischown = (strcmp(basename(argv[0]), "chown") == 0); ischown = (strcmp(basename(argv[0]), "chown") == 0);
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; Hflag = Lflag = Rflag = fflag = hflag = vflag = xflag = 0;
while ((ch = getopt(argc, argv, "HLPRfhv")) != -1) while ((ch = getopt(argc, argv, "HLPRfhvx")) != -1)
switch (ch) { switch (ch) {
case 'H': case 'H':
Hflag = 1; Hflag = 1;
@ -105,6 +105,9 @@ main(int argc, char **argv)
case 'v': case 'v':
vflag++; vflag++;
break; break;
case 'x':
xflag = 1;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -128,6 +131,8 @@ main(int argc, char **argv)
} }
} else } else
fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL; fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
if (xflag)
fts_options |= FTS_XDEV;
uid = (uid_t)-1; uid = (uid_t)-1;
gid = (gid_t)-1; gid = (gid_t)-1;
@ -301,11 +306,11 @@ usage(void)
if (ischown) if (ischown)
(void)fprintf(stderr, "%s\n%s\n", (void)fprintf(stderr, "%s\n%s\n",
"usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group]" "usage: chown [-fhvx] [-R [-H | -L | -P]] owner[:group]"
" file ...", " file ...",
" chown [-fhv] [-R [-H | -L | -P]] :group file ..."); " chown [-fhvx] [-R [-H | -L | -P]] :group file ...");
else else
(void)fprintf(stderr, "%s\n", (void)fprintf(stderr, "%s\n",
"usage: chgrp [-fhv] [-R [-H | -L | -P]] group file ..."); "usage: chgrp [-fhvx] [-R [-H | -L | -P]] group file ...");
exit(1); exit(1);
} }