From owner-svn-src-head@FreeBSD.ORG Mon Aug 31 20:42:08 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 449361065670; Mon, 31 Aug 2009 20:42:08 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1A7F28FC1C; Mon, 31 Aug 2009 20:42:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n7VKg7Nh038432; Mon, 31 Aug 2009 20:42:07 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n7VKg7eV038430; Mon, 31 Aug 2009 20:42:07 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <200908312042.n7VKg7eV038430@svn.freebsd.org> From: Edward Tomasz Napierala Date: Mon, 31 Aug 2009 20:42:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r196711 - head/bin/chmod X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Aug 2009 20:42:08 -0000 Author: trasz Date: Mon Aug 31 20:42:07 2009 New Revision: 196711 URL: http://svn.freebsd.org/changeset/base/196711 Log: Make the code more readable and fix chmod(1) on symlinks with NFSv4 enabled. Modified: head/bin/chmod/chmod.c Modified: head/bin/chmod/chmod.c ============================================================================== --- head/bin/chmod/chmod.c Mon Aug 31 20:11:35 2009 (r196710) +++ head/bin/chmod/chmod.c Mon Aug 31 20:42:07 2009 (r196711) @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)chmod.c 8.8 __FBSDID("$FreeBSD$"); #include +#include #include #include @@ -54,7 +55,7 @@ __FBSDID("$FreeBSD$"); #include static void usage(void); -static int may_have_nfs4acl(const FTSENT *ent); +static int may_have_nfs4acl(const FTSENT *ent, int hflag); int main(int argc, char *argv[]) @@ -62,11 +63,10 @@ main(int argc, char *argv[]) FTS *ftsp; FTSENT *p; mode_t *set; - int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval; + int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval, error; int vflag; char *mode; mode_t newmode; - int (*change_mode)(const char *, mode_t); set = NULL; Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; @@ -140,11 +140,6 @@ done: argv += optind; } else fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL; - if (hflag) - change_mode = lchmod; - else - change_mode = chmod; - mode = *argv; if ((set = setmode(mode)) == NULL) errx(1, "invalid file mode: %s", mode); @@ -186,10 +181,14 @@ done: argv += optind; * identical to the one computed from an ACL will change * that ACL. */ - if (may_have_nfs4acl(p) == 0 && + if (may_have_nfs4acl(p, hflag) == 0 && (newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS)) continue; - if ((*change_mode)(p->fts_accpath, newmode) && !fflag) { + if (hflag) + error = lchmod(p->fts_accpath, newmode); + else + error = chmod(p->fts_accpath, newmode); + if (error && !fflag) { warn("%s", p->fts_path); rval = 1; } else { @@ -228,17 +227,20 @@ usage(void) } static int -may_have_nfs4acl(const FTSENT *ent) +may_have_nfs4acl(const FTSENT *ent, int hflag) { int ret; - static dev_t previous_dev = (dev_t)-1; + static dev_t previous_dev = NODEV; static int supports_acls = -1; if (previous_dev != ent->fts_statp->st_dev) { previous_dev = ent->fts_statp->st_dev; supports_acls = 0; - ret = pathconf(ent->fts_accpath, _PC_ACL_NFS4); + if (hflag) + ret = lpathconf(ent->fts_accpath, _PC_ACL_NFS4); + else + ret = pathconf(ent->fts_accpath, _PC_ACL_NFS4); if (ret > 0) supports_acls = 1; else if (ret < 0 && errno != EINVAL)