Patchwork [5/5] package.bbclass: fixup_perms - symlink bug fix

login
register
mail settings
Submitter Richard Purdie
Date July 25, 2011, 1:47 p.m.
Message ID <586cbf5404ff76795c3d967266e7338b01e47c8b.1311601422.git.richard.purdie@linuxfoundation.org>
Download mbox | patch
Permalink /patch/8439/
State New, archived
Headers show

Comments

Richard Purdie - July 25, 2011, 1:47 p.m.
From: Mark Hatle <mark.hatle@windriver.com>

We don't want to change the owner/mode of symlinks, as this may
affect the target of the link.  Also broken links will fail as well.

Change to checking if the file is a link, and ignoring it.

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
---
 meta/classes/package.bbclass |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Phil Blundell - July 25, 2011, 2:05 p.m.
On Mon, 2011-07-25 at 14:47 +0100, Richard Purdie wrote:
> From: Mark Hatle <mark.hatle@windriver.com>
> 
> We don't want to change the owner/mode of symlinks, as this may
> affect the target of the link.  Also broken links will fail as well.

This seems like it will cause links themselves to end up getting shipped
under the UID/GID that was used for building, which was the whole thing
that fixup_perms was trying to avoid in the first place.  Surely you do
want to fix their ownership, it's just the mode that you oughtn't to be
trying to change.

Also, unrelated to the technical details, the subject line of this patch
is not especially illuminating.  It would be better to say something
like "package.bbclass: don't change mode/owner of symlinks" rather than
like "symlink bug fix".

p.
Enrico Scholz - July 25, 2011, 2:14 p.m.
Phil Blundell <philb-mXXj517/zsQ@public.gmane.org> writes:

>> We don't want to change the owner/mode of symlinks, as this may
>> affect the target of the link.  Also broken links will fail as well.
>
> This seems like it will cause links themselves to end up getting shipped
> under the UID/GID that was used for building

there should be used 'os.lchown()' instead of 'os.chown()' in fix_perms()
and the 'os.chmod()' call must be omitted for links.



Enrico
Phil Blundell - July 25, 2011, 2:15 p.m.
On Mon, 2011-07-25 at 16:14 +0200, Enrico Scholz wrote:
> Phil Blundell <philb-mXXj517/zsQ@public.gmane.org> writes:
> 
> >> We don't want to change the owner/mode of symlinks, as this may
> >> affect the target of the link.  Also broken links will fail as well.
> >
> > This seems like it will cause links themselves to end up getting shipped
> > under the UID/GID that was used for building
> 
> there should be used 'os.lchown()' instead of 'os.chown()' in fix_perms()
> and the 'os.chmod()' call must be omitted for links.

Right, exactly.  I think that would be a much better change.

p.
Mark Hatle - July 25, 2011, 7:08 p.m.
On 7/25/11 9:05 AM, Phil Blundell wrote:
> On Mon, 2011-07-25 at 14:47 +0100, Richard Purdie wrote:
>> From: Mark Hatle <mark.hatle@windriver.com>
>>
>> We don't want to change the owner/mode of symlinks, as this may
>> affect the target of the link.  Also broken links will fail as well.
> 
> This seems like it will cause links themselves to end up getting shipped
> under the UID/GID that was used for building, which was the whole thing
> that fixup_perms was trying to avoid in the first place.  Surely you do
> want to fix their ownership, it's just the mode that you oughtn't to be
> trying to change.

symlinks do not have an ownership/group on most filesystems.  They automatically
inherit the uid/gid of the target.  (I also believe this is the same for
permissions.)

How do you change the mode of the link itself?  As far as I understood this
can't be done on most filesystems.  I'd be happy to attempt to change the
owner/group (and mode) of symlinks if there is a way not to follow the link.

> Also, unrelated to the technical details, the subject line of this patch
> is not especially illuminating.  It would be better to say something
> like "package.bbclass: don't change mode/owner of symlinks" rather than
> like "symlink bug fix".

This was discovered when I had a package that contained broken symlinks.  The
fixup_perms broke on me.  Thus the short description... [it can certainly be
changed]

--Mark

> p.
> 
> 
> 
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core
Phil Blundell - July 25, 2011, 7:42 p.m.
On Mon, 2011-07-25 at 14:08 -0500, Mark Hatle wrote:
> symlinks do not have an ownership/group on most filesystems.  They automatically
> inherit the uid/gid of the target.  (I also believe this is the same for
> permissions.)

I'm not sure about "most" filesystems, but as far as I know all the
standard Linux filesystems do support UIDs and GIDs for symlinks.

> How do you change the mode of the link itself?  As far as I understood this
> can't be done on most filesystems.  I'd be happy to attempt to change the
> owner/group (and mode) of symlinks if there is a way not to follow the link.

You can't (in POSIX) change the mode of the link but, as someone else
already noted, you can change the ownership via lchown(2).  See:

http://pubs.opengroup.org/onlinepubs/009695399/functions/lchown.html

p.

Patch

diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index f2950e2..0ca7509 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -637,7 +637,8 @@  python fixup_perms () {
 					fix_perms(each_dir, fs_perms_table[dir].mode, fs_perms_table[dir].uid, fs_perms_table[dir].gid, dir)
 				for f in files:
 					each_file = os.path.join(root, f)
-					fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir)
+					if not os.path.islink(each_file):
+						fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir)
 }
 
 python split_and_strip_files () {