[Midnightbsd-cvs] src [11352] trunk/bin/chflags: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Jul 6 08:03:50 EDT 2018


Revision: 11352
          http://svnweb.midnightbsd.org/src/?rev=11352
Author:   laffer1
Date:     2018-07-06 08:03:50 -0400 (Fri, 06 Jul 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/bin/chflags/Makefile
    trunk/bin/chflags/chflags.1
    trunk/bin/chflags/chflags.c

Added Paths:
-----------
    trunk/bin/chflags/tests/
    trunk/bin/chflags/tests/Makefile
    trunk/bin/chflags/tests/chflags_test.sh

Property Changed:
----------------
    trunk/bin/chflags/chflags.1

Modified: trunk/bin/chflags/Makefile
===================================================================
--- trunk/bin/chflags/Makefile	2018-07-06 12:02:48 UTC (rev 11351)
+++ trunk/bin/chflags/Makefile	2018-07-06 12:03:50 UTC (rev 11352)
@@ -1,7 +1,13 @@
+# $MidnightBSD$
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $FreeBSD: src/bin/chflags/Makefile,v 1.19 2005/01/27 13:23:05 delphij Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/bin/chflags/Makefile 326332 2017-11-28 18:18:39Z asomers $
 
+.include <bsd.own.mk>
+
+PACKAGE=runtime
 PROG=	chflags
 
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
 .include <bsd.prog.mk>

Modified: trunk/bin/chflags/chflags.1
===================================================================
--- trunk/bin/chflags/chflags.1	2018-07-06 12:02:48 UTC (rev 11351)
+++ trunk/bin/chflags/chflags.1	2018-07-06 12:03:50 UTC (rev 11352)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"-
 .\" Copyright (c) 1989, 1990, 1993, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -30,10 +31,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)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 $
-.\" $MidnightBSD: src/bin/chflags/chflags.1,v 1.4 2008/06/30 01:16:47 laffer1 Exp $
+.\" $FreeBSD: stable/10/bin/chflags/chflags.1 283875 2015-06-01 09:04:57Z smh $
 .\"
-.Dd June 29, 2008
+.Dd April 20, 2015
 .Dt CHFLAGS 1
 .Os
 .Sh NAME
@@ -67,8 +67,9 @@
 .It Fl H
 If the
 .Fl R
-option is specified, symbolic links on the command line are followed.
-(Symbolic links encountered in the tree traversal are not followed.)
+option is specified, symbolic links on the command line are followed
+and hence unaffected by the command.
+(Symbolic links encountered during traversal are not followed.)
 .It Fl h
 If the
 .Ar file
@@ -84,8 +85,12 @@
 option is specified, no symbolic links are followed.
 This is the default.
 .It Fl R
-Change the file flags for the file hierarchies rooted
-in the files instead of just the files themselves.
+Change the file flags of the file hierarchies rooted in the files,
+instead of just the files themselves.
+Beware of unintentionally matching the
+.Dq Pa ".."
+hard link to the parent directory when using wildcards like
+.Dq Li ".*" .
 .It Fl v
 Cause
 .Nm
@@ -102,20 +107,36 @@
 .Bl -tag -offset indent -width ".Cm opaque"
 .It Cm arch , archived
 set the archived flag (super-user only)
+.It Cm nodump
+set the nodump flag (owner or super-user only)
 .It Cm opaque
 set the opaque flag (owner or super-user only)
-.It Cm nodump
-set the nodump flag (owner or super-user only)
 .It Cm sappnd , sappend
 set the system append-only flag (super-user only)
 .It Cm schg , schange , simmutable
 set the system immutable flag (super-user only)
+.It Cm snapshot
+set the snapshot flag (filesystems do not allow changing this flag)
 .It Cm sunlnk , sunlink
 set the system undeletable flag (super-user only)
 .It Cm uappnd , uappend
 set the user append-only flag (owner or super-user only)
+.It Cm uarch , uarchive
+set the archive flag (owner or super-user only)
 .It Cm uchg , uchange , uimmutable
 set the user immutable flag (owner or super-user only)
+.It Cm uhidden , hidden
+set the hidden file attribute (owner or super-user only)
+.It Cm uoffline , offline
+set the offline file attribute (owner or super-user only)
+.It Cm urdonly , rdonly , readonly
+set the DOS, Windows and CIFS readonly flag (owner or super-user only)
+.It Cm usparse , sparse
+set the sparse file attribute (owner or super-user only)
+.It Cm usystem , system
+set the DOS, Windows and CIFS system flag (owner or super-user only)
+.It Cm ureparse , reparse
+set the Windows reparse point file attribute (owner or super-user only)
 .It Cm uunlnk , uunlink
 set the user undeletable flag (owner or super-user only)
 .El


Property changes on: trunk/bin/chflags/chflags.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/bin/chflags/chflags.c
===================================================================
--- trunk/bin/chflags/chflags.c	2018-07-06 12:02:48 UTC (rev 11351)
+++ trunk/bin/chflags/chflags.c	2018-07-06 12:03:50 UTC (rev 11352)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -25,9 +26,6 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * $MidnightBSD: src/bin/chflags/chflags.c,v 1.5 2012/03/09 04:54:42 laffer1 Exp $
- * $FreeBSD: src/bin/chflags/chflags.c,v 1.23 2005/05/14 23:23:10 dd Exp$
  */
 
 #if 0
@@ -43,6 +41,7 @@
 #endif
 
 #include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/bin/chflags/chflags.c 283875 2015-06-01 09:04:57Z smh $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -49,6 +48,7 @@
 
 #include <err.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <fts.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -67,7 +67,6 @@
 	int Hflag, Lflag, Rflag, fflag, hflag, vflag;
 	int ch, fts_options, oct, rval;
 	char *flags, *ep;
-	int (*change_flags)(const char *, unsigned long);
 
 	Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
 	while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
@@ -106,25 +105,24 @@
 		usage();
 
 	if (Rflag) {
-		fts_options = FTS_PHYSICAL;
 		if (hflag)
-			errx(1, "the -R and -h options "
-			        "may not be specified together");
-		if (Hflag)
-			fts_options |= FTS_COMFOLLOW;
+			errx(1, "the -R and -h options may not be "
+			    "specified together.");
 		if (Lflag) {
-			fts_options &= ~FTS_PHYSICAL;
-			fts_options |= FTS_LOGICAL;
+			fts_options = FTS_LOGICAL;
+		} else {
+			fts_options = FTS_PHYSICAL;
+
+			if (Hflag) {
+				fts_options |= FTS_COMFOLLOW;
+			}
 		}
-	} else
-		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
+	} else if (hflag) {
+		fts_options = FTS_PHYSICAL;
+	} else {
+		fts_options = FTS_LOGICAL;
+	}
 
-	/* XXX: Why don't chflags and lchflags have compatible prototypes? */
-	if (hflag)
-		change_flags = (int (*)(const char *, unsigned long))lchflags;
-	else
-		change_flags = chflags;
-
 	flags = *argv;
 	if (*flags >= '0' && *flags <= '7') {
 		errno = 0;
@@ -148,12 +146,21 @@
 		err(1, NULL);
 
 	for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
+		int atflag;
+
+		if ((fts_options & FTS_LOGICAL) ||
+		    ((fts_options & FTS_COMFOLLOW) &&
+		    p->fts_level == FTS_ROOTLEVEL))
+			atflag = 0;
+		else
+			atflag = AT_SYMLINK_NOFOLLOW;
+
 		switch (p->fts_info) {
 		case FTS_D:	/* Change it at FTS_DP if we're recursive. */
 			if (!Rflag)
 				fts_set(ftsp, p, FTS_SKIP);
 			continue;
-		case FTS_DNR:			/* Warn, chflag, continue. */
+		case FTS_DNR:			/* Warn, chflags. */
 			warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
 			rval = 1;
 			break;
@@ -162,16 +169,6 @@
 			warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
 			rval = 1;
 			continue;
-		case FTS_SL:			/* Ignore. */
-		case FTS_SLNONE:
-			/*
-			 * The only symlinks that end up here are ones that
-			 * don't point to anything and ones that we found
-			 * doing a physical walk.
-			 */
-			if (!hflag)
-				continue;
-			/* FALLTHROUGH */
 		default:
 			break;
 		}
@@ -181,7 +178,8 @@
 			newflags = (p->fts_statp->st_flags | set) & clear;
 		if (newflags == p->fts_statp->st_flags)
 			continue;
-		if ((*change_flags)(p->fts_accpath, newflags) && !fflag) {
+		if (chflagsat(AT_FDCWD, p->fts_accpath, newflags,
+		    atflag) == -1 && !fflag) {
 			warn("%s", p->fts_path);
 			rval = 1;
 		} else if (vflag) {

Added: trunk/bin/chflags/tests/Makefile
===================================================================
--- trunk/bin/chflags/tests/Makefile	                        (rev 0)
+++ trunk/bin/chflags/tests/Makefile	2018-07-06 12:03:50 UTC (rev 11352)
@@ -0,0 +1,6 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/bin/chflags/tests/Makefile 323275 2017-09-07 16:54:47Z asomers $
+
+ATF_TESTS_SH+=  chflags_test
+
+.include <bsd.test.mk>


Property changes on: trunk/bin/chflags/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/bin/chflags/tests/chflags_test.sh
===================================================================
--- trunk/bin/chflags/tests/chflags_test.sh	                        (rev 0)
+++ trunk/bin/chflags/tests/chflags_test.sh	2018-07-06 12:03:50 UTC (rev 11352)
@@ -0,0 +1,63 @@
+#
+# Copyright 2017 Shivansh Rai
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD: stable/10/bin/chflags/tests/chflags_test.sh 323275 2017-09-07 16:54:47Z asomers $
+# $MidnightBSD$
+
+usage_output='usage: chflags'
+
+atf_test_case invalid_usage
+invalid_usage_head()
+{
+	atf_set "descr" "Verify that an invalid usage with a supported option produces a valid error message"
+}
+
+invalid_usage_body()
+{
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -f
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -H
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -h
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -L
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -P
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -R
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags -v
+}
+
+atf_test_case no_arguments
+no_arguments_head()
+{
+	atf_set "descr" "Verify that chflags(1) fails and generates a valid usage message when no arguments are supplied"
+}
+
+no_arguments_body()
+{
+	atf_check -s not-exit:0 -e match:"$usage_output" chflags
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case invalid_usage
+	atf_add_test_case no_arguments
+}


Property changes on: trunk/bin/chflags/tests/chflags_test.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list