bin/112827: [PATCH]: chmod-like -f & -v options to chflags(1)

Ighighi ighighi at gmail.com
Mon May 21 06:00:12 UTC 2007


>Number:         112827
>Category:       bin
>Synopsis:       [PATCH]: chmod-like -f & -v options to chflags(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 21 06:00:11 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Ighighi
>Release:        6.2-STABLE
>Organization:
>Environment:
>Description:
Maybe I'm not the only one missing the -f & -v options in chflags(1)...
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- bin/chflags/chflags.c.orig	Sat May 14 19:23:10 2005
+++ bin/chflags/chflags.c	Sun May 20 03:35:08 2007
@@ -62,12 +62,12 @@
 	FTSENT *p;
 	u_long clear, set;
 	long val;
-	int Hflag, Lflag, Rflag, hflag, ch, fts_options, oct, rval;
+	int Hflag, Lflag, Rflag, fflag, hflag, vflag, ch, fts_options, oct, rval;
 	char *flags, *ep;
 	int (*change_flags)(const char *, unsigned long);
 
-	Hflag = Lflag = Rflag = hflag = 0;
-	while ((ch = getopt(argc, argv, "HLPRh")) != -1)
+	Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
+	while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
 		switch (ch) {
 		case 'H':
 			Hflag = 1;
@@ -83,9 +83,15 @@
 		case 'R':
 			Rflag = 1;
 			break;
+		case 'f':
+			fflag = 1;
+			break;
 		case 'h':
 			hflag = 1;
 			break;
+		case 'v':
+			vflag = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -167,17 +173,25 @@
 			break;
 		}
 		if (oct) {
-			if (!(*change_flags)(p->fts_accpath, set))
+			if (!(*change_flags)(p->fts_accpath, set)) {
+				if (vflag)
+					printf("%s\n", p->fts_path);
 				continue;
+			}
 		} else {
 			p->fts_statp->st_flags |= set;
 			p->fts_statp->st_flags &= clear;
 			if (!(*change_flags)(p->fts_accpath,
-				    (u_long)p->fts_statp->st_flags))
+				    (u_long)p->fts_statp->st_flags)) {
+				if (vflag)
+					printf("%s\n", p->fts_path);
 				continue;
+			}
+		}
+		if (!fflag) {
+			warn("%s", p->fts_path);
+			rval = 1;
 		}
-		warn("%s", p->fts_path);
-		rval = 1;
 	}
 	if (errno)
 		err(1, "fts_read");
@@ -188,6 +202,6 @@
 usage(void)
 {
 	(void)fprintf(stderr,
-	    "usage: chflags [-h] [-R [-H | -L | -P]] flags file ...\n");
+	    "usage: chflags [-fhv] [-R [-H | -L | -P]] flags file ...\n");
 	exit(1);
 }
--- bin/chflags/chflags.1.orig	Tue Sep 26 20:21:37 2006
+++ bin/chflags/chflags.1	Sun May 20 01:33:41 2007
@@ -32,7 +32,7 @@
 .\"	@(#)chflags.1	8.4 (Berkeley) 5/2/95
 .\" $FreeBSD: src/bin/chflags/chflags.1,v 1.25.2.1 2006/05/17 13:20:21 trhodes Exp $
 .\"
-.Dd March 3, 2006
+.Dd May 20, 2007
 .Dt CHFLAGS 1
 .Os
 .Sh NAME
@@ -40,7 +40,7 @@
 .Nd change file flags
 .Sh SYNOPSIS
 .Nm
-.Op Fl h
+.Op Fl fhv
 .Oo
 .Fl R
 .Op Fl H | Fl L | Fl P
@@ -57,6 +57,12 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl f
+Do not display a diagnostic message if
+.Nm
+could not modify the flags for
+.Va file ,
+nor modify the exit status to reflect such failures.
 .It Fl H
 If the
 .Fl R
@@ -79,6 +85,10 @@
 .It Fl R
 Change the file flags for the file hierarchies rooted
 in the files instead of just the files themselves.
+.It Fl v
+Cause
+.Nm
+to be verbose, showing filenames as the flags are modified.
 .El
 .Pp
 The flags are specified as an octal number or a comma separated list

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list