Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177562229
D2316.1794733265.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D2316.1794733265.diff
View Options
Index: bin/chflags/chflags.c
===================================================================
--- bin/chflags/chflags.c
+++ bin/chflags/chflags.c
@@ -105,9 +105,9 @@
if (Rflag) {
fts_options = FTS_PHYSICAL;
- if (hflag)
- errx(1, "the -R and -h options "
- "may not be specified together");
+ if (hflag && (Hflag || Lflag))
+ errx(1, "the -R%c and -h options may not be "
+ "specified together", Hflag ? 'H' : 'L');
if (Hflag)
fts_options |= FTS_COMFOLLOW;
if (Lflag) {
Index: bin/chmod/chmod.c
===================================================================
--- bin/chmod/chmod.c
+++ bin/chmod/chmod.c
@@ -62,10 +62,11 @@
FTS *ftsp;
FTSENT *p;
mode_t *set;
- int Hflag, Lflag, Rflag, ch, error, fflag, fts_options, hflag, rval;
+ int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval;
int vflag;
char *mode;
mode_t newmode;
+ int (*change_mode)(const char *, unsigned long);
set = NULL;
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
@@ -127,9 +128,9 @@
if (Rflag) {
fts_options = FTS_PHYSICAL;
- if (hflag)
- errx(1,
- "the -R and -h options may not be specified together.");
+ if (hflag && (Hflag || Lflag))
+ errx(1, "the -R%c and -h options may not be "
+ "specified together", Hflag ? 'H' : 'L');
if (Hflag)
fts_options |= FTS_COMFOLLOW;
if (Lflag) {
@@ -139,6 +140,8 @@
} else
fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
+ change_mode = hflag ? lchmod : chmod;
+
mode = *argv;
if ((set = setmode(mode)) == NULL)
errx(1, "invalid file mode: %s", mode);
@@ -182,32 +185,24 @@
if (may_have_nfs4acl(p, hflag) == 0 &&
(newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS))
continue;
- if (hflag)
- error = lchmod(p->fts_accpath, newmode);
- else
- error = chmod(p->fts_accpath, newmode);
- if (error) {
- if (!fflag) {
- warn("%s", p->fts_path);
- rval = 1;
- }
- } else {
- if (vflag) {
- (void)printf("%s", p->fts_path);
-
- if (vflag > 1) {
- char m1[12], m2[12];
-
- strmode(p->fts_statp->st_mode, m1);
- strmode((p->fts_statp->st_mode &
- S_IFMT) | newmode, m2);
- (void)printf(": 0%o [%s] -> 0%o [%s]",
- p->fts_statp->st_mode, m1,
- (p->fts_statp->st_mode & S_IFMT) |
- newmode, m2);
- }
- (void)printf("\n");
+ if (change_mode(p->fts_accpath, newmode) && !fflag) {
+ warn("%s", p->fts_path);
+ rval = 1;
+ } else if (vflag) {
+ (void)printf("%s", p->fts_path);
+
+ if (vflag > 1) {
+ char m1[12], m2[12];
+
+ strmode(p->fts_statp->st_mode, m1);
+ strmode((p->fts_statp->st_mode &
+ S_IFMT) | newmode, m2);
+ (void)printf(": 0%o [%s] -> 0%o [%s]",
+ p->fts_statp->st_mode, m1,
+ (p->fts_statp->st_mode & S_IFMT) |
+ newmode, m2);
}
+ (void)printf("\n");
}
}
if (errno)
Index: usr.sbin/chown/chown.c
===================================================================
--- usr.sbin/chown/chown.c
+++ usr.sbin/chown/chown.c
@@ -76,6 +76,7 @@
int Hflag, Lflag, Rflag, fflag, hflag, vflag, xflag;
int ch, fts_options, rval;
char *cp;
+ int (*change_owner)(const char *, uid_t, gid_t);
ischown = (strcmp(basename(argv[0]), "chown") == 0);
@@ -131,6 +132,9 @@
}
} else
fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
+
+ change_owner = hflag ? lchown : chown;
+
if (xflag)
fts_options |= FTS_XDEV;
@@ -187,41 +191,37 @@
if ((uid == (uid_t)-1 || uid == p->fts_statp->st_uid) &&
(gid == (gid_t)-1 || gid == p->fts_statp->st_gid))
continue;
- if ((hflag ? lchown : chown)(p->fts_accpath, uid, gid) == -1) {
- if (!fflag) {
- chownerr(p->fts_path);
- rval = 1;
- }
- } else {
- if (vflag) {
- printf("%s", p->fts_path);
- if (vflag > 1) {
- if (ischown) {
- printf(": %ju:%ju -> %ju:%ju",
- (uintmax_t)
- p->fts_statp->st_uid,
- (uintmax_t)
- p->fts_statp->st_gid,
- (uid == (uid_t)-1) ?
- (uintmax_t)
- p->fts_statp->st_uid :
- (uintmax_t)uid,
- (gid == (gid_t)-1) ?
- (uintmax_t)
- p->fts_statp->st_gid :
- (uintmax_t)gid);
- } else {
- printf(": %ju -> %ju",
- (uintmax_t)
- p->fts_statp->st_gid,
- (gid == (gid_t)-1) ?
- (uintmax_t)
- p->fts_statp->st_gid :
- (uintmax_t)gid);
- }
+ if (change_owner(p->fts_accpath, uid, gid) == -1 && !fflag) {
+ chownerr(p->fts_path);
+ rval = 1;
+ } else if (vflag) {
+ printf("%s", p->fts_path);
+ if (vflag > 1) {
+ if (ischown) {
+ printf(": %ju:%ju -> %ju:%ju",
+ (uintmax_t)
+ p->fts_statp->st_uid,
+ (uintmax_t)
+ p->fts_statp->st_gid,
+ (uid == (uid_t)-1) ?
+ (uintmax_t)
+ p->fts_statp->st_uid :
+ (uintmax_t)uid,
+ (gid == (gid_t)-1) ?
+ (uintmax_t)
+ p->fts_statp->st_gid :
+ (uintmax_t)gid);
+ } else {
+ printf(": %ju -> %ju",
+ (uintmax_t)
+ p->fts_statp->st_gid,
+ (gid == (gid_t)-1) ?
+ (uintmax_t)
+ p->fts_statp->st_gid :
+ (uintmax_t)gid);
}
- printf("\n");
}
+ printf("\n");
}
}
if (errno)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 15, 9:01 AM (15 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41725719
Default Alt Text
D2316.1794733265.diff (5 KB)
Attached To
Mode
D2316: Standardise chmod, chflags and chown option processing
Attached
Detach File
Event Timeline