misc/131999: chflags: unable to unset flags on symlinks when
link target exists
Bruce Evans
brde at optusnet.com.au
Tue Feb 24 02:00:12 PST 2009
The following reply was made to PR bin/131999; it has been noted by GNATS.
From: Bruce Evans <brde at optusnet.com.au>
To: Deomid Ryabkov <myself at rojer.pp.ru>
Cc: freebsd-gnats-submit at freebsd.org, freebsd-bugs at 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
More information about the freebsd-bugs
mailing list