Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Apr 2002 20:20:02 -0700 (PDT)
From:      Joshua Goodall <joshua@roughtrade.net>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/36473: Overdue MFC's in chmod/chown/chflags
Message-ID:  <200204160320.g3G3K2L41987@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/36473; it has been noted by GNATS.

From: Joshua Goodall <joshua@roughtrade.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/36473: Overdue MFC's in chmod/chown/chflags
Date: Tue, 16 Apr 2002 13:15:35 +1000

 On Fri, Mar 29, 2002 at 01:25:28AM -0800, Joshua Goodall wrote:
 > The following are now very overdue MFC's:
 [snip]
 
 This is a (tested) diff against -stable:
 
 
 Index: src/bin/chmod/chmod.c
 ===================================================================
 RCS file: /cvs/src/bin/chmod/chmod.c,v
 retrieving revision 1.16.2.3
 diff -u -r1.16.2.3 chmod.c
 --- src/bin/chmod/chmod.c	1 Aug 2001 01:21:09 -0000	1.16.2.3
 +++ src/bin/chmod/chmod.c	15 Apr 2002 15:13:10 -0000
 @@ -74,11 +74,12 @@
  	int vflag;
  	char *ep, *mode;
  	int newmode;
 +	int (*change_mode) __P((const char *, mode_t));
  
  	set = NULL;
  	omode = 0;
  	Hflag = Lflag = Pflag = Rflag = fflag = hflag = vflag = 0;
 -	while ((ch = getopt(argc, argv, "HLPRXfgorstuvwx")) != -1)
 +	while ((ch = getopt(argc, argv, "HLPRXfghorstuvwx")) != -1)
  		switch (ch) {
  		case 'H':
  			Hflag = 1;
 @@ -102,9 +103,10 @@
  			/*
  			 * In System V (and probably POSIX.2) the -h option
  			 * causes chmod to change the mode of the symbolic
 -			 * link.  4.4BSD's symbolic links don't have modes,
 -			 * so it's an undocumented noop.  Do syntax checking,
 -			 * though.
 +			 * link.  4.4BSD's symbolic links didn't have modes,
 +			 * so it was an undocumented noop.  In FreeBSD 3.0,
 +			 * lchmod(2) is introduced and this option does real
 +			 * work.
  			 */
  			hflag = 1;
  			break;
 @@ -134,8 +136,8 @@
  	if (argc < 2)
  		usage();
  
 -	fts_options = FTS_PHYSICAL;
  	if (Rflag) {
 +		fts_options = FTS_PHYSICAL;
  		if (hflag)
  			errx(1,
  		"the -R and -h options may not be specified together.");
 @@ -145,7 +147,13 @@
  			fts_options &= ~FTS_PHYSICAL;
  			fts_options |= FTS_LOGICAL;
  		}
 -	}
 +	} else
 +		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
 +
 +	if (hflag)
 +		change_mode = lchmod;
 +	else
 +		change_mode = chmod;
  
  	mode = *argv;
  	if (*mode >= '0' && *mode <= '7') {
 @@ -189,14 +197,17 @@
  			 * don't point to anything and ones that we found
  			 * doing a physical walk.
  			 */
 -			continue;
 +			if (!hflag)
 +				continue;
 +			/* else */
 +			/* FALLTHROUGH */
  		default:
  			break;
  		}
  		newmode = oct ? omode : getmode(set, p->fts_statp->st_mode);
  		if ((newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS))
  			continue;
 -		if (chmod(p->fts_accpath, newmode) && !fflag) {
 +		if ((*change_mode)(p->fts_accpath, newmode) && !fflag) {
  			warn("%s", p->fts_path);
  			rval = 1;
  		} else {
 @@ -214,6 +225,6 @@
  usage()
  {
  	(void)fprintf(stderr,
 -	    "usage: chmod [-fv] [-R [-H | -L | -P]] mode file ...\n");
 +	    "usage: chmod [-fhv] [-R [-H | -L | -P]] mode file ...\n");
  	exit(1);
  }
 Index: src/usr.bin/chflags/chflags.c
 ===================================================================
 RCS file: /cvs/src/usr.bin/chflags/chflags.c,v
 retrieving revision 1.7.2.3
 diff -u -r1.7.2.3 chflags.c
 --- src/usr.bin/chflags/chflags.c	1 Aug 2001 23:09:18 -0000	1.7.2.3
 +++ src/usr.bin/chflags/chflags.c	15 Apr 2002 15:03:40 -0000
 @@ -99,15 +99,16 @@
  	if (argc < 2)
  		usage();
  
 -	fts_options = FTS_PHYSICAL;
  	if (Rflag) {
 +		fts_options = FTS_PHYSICAL;
  		if (Hflag)
  			fts_options |= FTS_COMFOLLOW;
  		if (Lflag) {
  			fts_options &= ~FTS_PHYSICAL;
  			fts_options |= FTS_LOGICAL;
  		}
 -	}
 +	} else
 +		fts_options = FTS_LOGICAL;
  
  	flags = *argv;
  	if (*flags >= '0' && *flags <= '7') {
 Index: src/usr.sbin/chown/chown.c
 ===================================================================
 RCS file: /cvs/src/usr.sbin/chown/chown.c,v
 retrieving revision 1.15.2.1
 diff -u -r1.15.2.1 chown.c
 --- src/usr.sbin/chown/chown.c	7 Aug 2000 02:03:09 -0000	1.15.2.1
 +++ src/usr.sbin/chown/chown.c	15 Apr 2002 15:07:45 -0000
 @@ -122,8 +122,8 @@
  	if (argc < 2)
  		usage();
  
 -	fts_options = FTS_PHYSICAL;
  	if (Rflag) {
 +		fts_options = FTS_PHYSICAL;
  		if (hflag && (Lflag || Hflag))
  			errx(1, "the -R and -h options may not be specified together");
  		if (Hflag)
 @@ -132,7 +132,8 @@
  			fts_options &= ~FTS_PHYSICAL;
  			fts_options |= FTS_LOGICAL;
  		}
 -	}
 +	} else
 +		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
  
  	uid = gid = -1;
  	if (ischown) {

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204160320.g3G3K2L41987>