Module Name: src
Committed By: kre
Date: Fri May 5 04:14:02 UTC 2023
Modified Files:
src/bin/chmod: chmod.1 chmod.c
src/usr.bin/chflags: chflags.1 chflags.c
Log Message:
If chown and chgrp can grow -d flags to suppress performing the
operation when it will have no effect (other than changing the
inode's ctime value) then chmod and chflags should also have -d
flags for the same purpose. Make it so.
To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/bin/chmod/chmod.1
cvs rdiff -u -r1.38 -r1.39 src/bin/chmod/chmod.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/chflags/chflags.1
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/chflags/chflags.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/chmod/chmod.1
diff -u src/bin/chmod/chmod.1:1.28 src/bin/chmod/chmod.1:1.29
--- src/bin/chmod/chmod.1:1.28 Tue Jul 4 06:47:27 2017
+++ src/bin/chmod/chmod.1 Fri May 5 04:14:02 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: chmod.1,v 1.28 2017/07/04 06:47:27 wiz Exp $
+.\" $NetBSD: chmod.1,v 1.29 2023/05/05 04:14:02 kre Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -44,7 +44,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
-.Op Fl fh
+.Op Fl dfh
.Ar mode
.Ar
.Nm
@@ -52,7 +52,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
-.Op Fl fh
+.Op Fl dfh
.Fl Fl reference=rfile
.Ar
.Sh DESCRIPTION
@@ -84,12 +84,18 @@ If the
.Fl R
option is specified, no symbolic links are followed.
.It Fl R
-Change the modes of the file hierarchies rooted in the files
+Change the modes of the file hierarchies rooted in the
+.Ar file Ns s
instead of just the files themselves.
+.It Fl d
+Do not attempt to change the mode of a
+.Ar file
+if its mode is already as requested.
.It Fl f
Do not display a diagnostic message or modify the exit status if
.Nm
-fails to change the mode of a file.
+fails to change the mode of a
+.Ar file .
.It Fl h
If
.Ar file
Index: src/bin/chmod/chmod.c
diff -u src/bin/chmod/chmod.c:1.38 src/bin/chmod/chmod.c:1.39
--- src/bin/chmod/chmod.c:1.38 Mon Oct 22 18:00:46 2012
+++ src/bin/chmod/chmod.c Fri May 5 04:14:02 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: chmod.c,v 1.38 2012/10/22 18:00:46 christos Exp $ */
+/* $NetBSD: chmod.c,v 1.39 2023/05/05 04:14:02 kre Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -40,7 +40,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)chmod.c 8.8 (Berkeley) 4/1/94";
#else
-__RCSID("$NetBSD: chmod.c,v 1.38 2012/10/22 18:00:46 christos Exp $");
+__RCSID("$NetBSD: chmod.c,v 1.39 2023/05/05 04:14:02 kre Exp $");
#endif
#endif /* not lint */
@@ -74,17 +74,17 @@ main(int argc, char *argv[])
FTS *ftsp;
FTSENT *p;
void *set;
- mode_t mval;
- int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval;
+ mode_t mval, nval;
+ int Hflag, Lflag, Rflag, ch, dflag, fflag, fts_options, hflag, rval;
char *mode, *reference;
int (*change_mode)(const char *, mode_t);
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
- Hflag = Lflag = Rflag = fflag = hflag = 0;
+ Hflag = Lflag = Rflag = dflag = fflag = hflag = 0;
reference = NULL;
- while ((ch = getopt_long(argc, argv, "HLPRXfghorstuwx",
+ while ((ch = getopt_long(argc, argv, "HLPRXdfghorstuwx",
chmod_longopts, NULL)) != -1)
switch (ch) {
case 1:
@@ -104,6 +104,9 @@ main(int argc, char *argv[])
case 'R':
Rflag = 1;
break;
+ case 'd':
+ dflag = 1;
+ break;
case 'f':
fflag = 1;
break;
@@ -212,9 +215,10 @@ done: argv += optind;
default:
break;
}
- if ((*change_mode)(p->fts_accpath,
- set ? getmode(set, p->fts_statp->st_mode) : mval)
- && !fflag) {
+ nval = set ? getmode(set, p->fts_statp->st_mode) : mval;
+ if (dflag && nval == p->fts_statp->st_mode)
+ continue;
+ if ((*change_mode)(p->fts_accpath, nval) && !fflag) {
warn("%s", p->fts_path);
rval = 1;
}
@@ -231,8 +235,8 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [-R [-H | -L | -P]] [-fh] mode file ...\n"
- "\t%s [-R [-H | -L | -P]] [-fh] --reference=rfile file ...\n",
+ "Usage: %s [-R [-H | -L | -P]] [-dfh] mode file ...\n"
+ "\t%s [-R [-H | -L | -P]] [-dfh] --reference=rfile file ...\n",
getprogname(), getprogname());
exit(1);
/* NOTREACHED */
Index: src/usr.bin/chflags/chflags.1
diff -u src/usr.bin/chflags/chflags.1:1.24 src/usr.bin/chflags/chflags.1:1.25
--- src/usr.bin/chflags/chflags.1:1.24 Tue Dec 17 09:54:08 2013
+++ src/usr.bin/chflags/chflags.1 Fri May 5 04:14:02 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: chflags.1,v 1.24 2013/12/17 09:54:08 apb Exp $
+.\" $NetBSD: chflags.1,v 1.25 2023/05/05 04:14:02 kre Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -44,6 +44,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
+.Op Fl d
.Op Fl h
.Ar flags
.Ar
@@ -57,6 +58,11 @@ operand.
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl d
+If the change requested would not alter the
+flags currently set for
+.Ar file
+then attempt no change operation.
.It Fl H
If the
.Fl R
Index: src/usr.bin/chflags/chflags.c
diff -u src/usr.bin/chflags/chflags.c:1.17 src/usr.bin/chflags/chflags.c:1.18
--- src/usr.bin/chflags/chflags.c:1.17 Fri Apr 28 22:23:45 2023
+++ src/usr.bin/chflags/chflags.c Fri May 5 04:14:02 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: chflags.c,v 1.17 2023/04/28 22:23:45 andvar Exp $ */
+/* $NetBSD: chflags.c,v 1.18 2023/05/05 04:14:02 kre Exp $ */
/*
* Copyright (c) 1992, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19
#if 0
static char sccsid[] = "from: @(#)chflags.c 8.5 (Berkeley) 4/1/94";
#else
-__RCSID("$NetBSD: chflags.c,v 1.17 2023/04/28 22:23:45 andvar Exp $");
+__RCSID("$NetBSD: chflags.c,v 1.18 2023/05/05 04:14:02 kre Exp $");
#endif
#endif /* not lint */
@@ -64,12 +64,12 @@ main(int argc, char *argv[])
FTSENT *p;
u_long clear, set, newflags;
long val;
- int Hflag, Lflag, Rflag, ch, fts_options, hflag, oct, rval;
+ int Hflag, Lflag, Rflag, ch, fts_options, dflag, hflag, oct, rval;
char *flags, *ep;
int (*change_flags)(const char *, u_long);
- Hflag = Lflag = Rflag = hflag = 0;
- while ((ch = getopt(argc, argv, "HLPRh")) != -1)
+ Hflag = Lflag = Rflag = dflag = hflag = 0;
+ while ((ch = getopt(argc, argv, "HLPRdh")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -85,6 +85,9 @@ main(int argc, char *argv[])
case 'R':
Rflag = 1;
break;
+ case 'd':
+ dflag = 1;
+ break;
case 'h':
hflag = 1;
break;
@@ -181,6 +184,8 @@ main(int argc, char *argv[])
newflags |= set;
newflags &= clear;
}
+ if (dflag && newflags == p->fts_statp->st_flags)
+ continue;
if ((*change_flags)(p->fts_accpath, newflags)) {
warn("%s", p->fts_path);
rval = 1;
@@ -196,6 +201,6 @@ usage(void)
{
(void)fprintf(stderr,
- "usage: chflags [-R [-H | -L | -P]] [-h] flags file ...\n");
+ "usage: chflags [-R [-H | -L | -P]] [-dh] flags file ...\n");
exit(1);
}