From owner-freebsd-bugs@FreeBSD.ORG Tue Feb 24 10:00:12 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40CCB1065672 for ; Tue, 24 Feb 2009 10:00:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 1CDA68FC23 for ; Tue, 24 Feb 2009 10:00:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n1OA0BAm037545 for ; Tue, 24 Feb 2009 10:00:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n1OA0B2h037544; Tue, 24 Feb 2009 10:00:11 GMT (envelope-from gnats) Date: Tue, 24 Feb 2009 10:00:11 GMT Message-Id: <200902241000.n1OA0B2h037544@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Cc: Subject: Re: misc/131999: chflags: unable to unset flags on symlinks when link target exists X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Feb 2009 10:00:12 -0000 The following reply was made to PR bin/131999; it has been noted by GNATS. From: Bruce Evans To: Deomid Ryabkov Cc: freebsd-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org Subject: Re: misc/131999: chflags: unable to unset flags on symlinks when link target exists Date: Tue, 24 Feb 2009 17:19:17 +1100 (EST) On Mon, 23 Feb 2009, Deomid Ryabkov wrote: >> Synopsis: chflags: unable to unset flags on symlinks when link target exists Also, setting only works accidentally in some cases. > truss of chflags reveals the problem: usage of stat() where lstat() should have been used. > > # truss chflags -h noschg logs > [...] > stat("logs",{ mode=drwxr-x--- ,inode=22303757,size=512,blksize=4096 }) = 0 (0x0) > process exit, rval = 0 > > this way, lchflags(2) is never actually called because chflags(3) doesn't think it is necessary. And for chflags -h schg logs, lchflags() is only called because the wrong flags returned by stat() happen to have their schg bit clear. If the schg bit were set in the symlink target, then this chflags would do nothing too. >> Fix: > i had a glance at bin/chflags/chflags.c and it seems to be using fts_* functions to traverse the tree. somehow those need to be told to use lstat to return information, when appropriate. Setting FTS_PHYSICAL seems to fix it: % Index: chflags.c % =================================================================== % RCS file: /home/ncvs/src/bin/chflags/chflags.c,v % retrieving revision 1.24 % diff -u -2 -r1.24 chflags.c % --- chflags.c 9 Mar 2008 12:10:24 -0000 1.24 % +++ chflags.c 24 Feb 2009 06:13:00 -0000 % @@ -115,5 +115,7 @@ % fts_options |= FTS_LOGICAL; % } % - } else % + } else if (hflag) % + fts_options = FTS_PHYSICAL; % + else % fts_options = FTS_LOGICAL; % Bruce