summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorkre <kre@NetBSD.org>2023-05-05 04:14:02 +0000
committerkre <kre@NetBSD.org>2023-05-05 04:14:02 +0000
commitd7aca45403ee1b83c90065f31eff4f11405e678f (patch)
tree69f613bd3b36b265894bc91b93a7e80fac23e69f /bin
parentb8c8fa9b4e2bd5ff92b1475a27a0d272b1eb1f64 (diff)
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.
Diffstat (limited to 'bin')
-rw-r--r--bin/chmod/chmod.116
-rw-r--r--bin/chmod/chmod.c26
2 files changed, 26 insertions, 16 deletions
diff --git a/bin/chmod/chmod.1 b/bin/chmod/chmod.1
index c9c11504a34..7e854ce90c9 100644
--- a/bin/chmod/chmod.1
+++ b/bin/chmod/chmod.1
@@ -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
diff --git a/bin/chmod/chmod.c b/bin/chmod/chmod.c
index c10101e5470..d5869233a24 100644
--- a/bin/chmod/chmod.c
+++ b/bin/chmod/chmod.c
@@ -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 */