Skip to contentSkip to conversation

Fix nativesdk-intercepts for chown/chgrp

PATCH In review Eilís 'pidge' Ní Fhlannagáin 2 participants 4 messages Sep 7, 2023

lore
Share & tools
lore
#0 lore raw

cover Fix nativesdk-intercepts for chown/chgrp

This set of patches started out with fixing #15023 where building the sdk with api-documentation set would fail out. This patch series fixes both of the main underlying issues.

First, populate_sdk did not the nativesdk chown/chgrp intercepts in $PATH.

The second issue was within the chown/chgrp intercepts which were causing them to fail badly. I'm not entirely sure these ever worked as prior to my fix the args for os.execv were:

./scripts/nativesdk-intercept/chown -R pidge:pidge README.md ['root:root', '-R', 'pidge:pidge', 'README.md']

after (which is correct):

./scripts/nativesdk-intercept/chown -R pidge:pidge README.md ['/usr/bin/chown', '-R', 'root:root', 'README.md']

Eilís 'pidge' Ní Fhlannagáin (2):
populate_sdk_base.bbclass: PATH to nativesdk-intercept chown/chgrp
nativesdk-intercept: Fix bad intercept chgrp/chown logic

 meta/classes-recipe/populate_sdk_base.bbclass | 1 +
 scripts/nativesdk-intercept/chgrp             | 5 ++++-
 scripts/nativesdk-intercept/chown             | 5 ++++-
 3 files changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 populate_sdk_base.bbclass: PATH to nativesdk-intercept chown/chgrp

[YOCTO #15023]

This patch fixes building the sdk with api-documentation enabled by appending PATH with the nativesdk-intercept directory which contains a special version of chown and chgrp.

---
 meta/classes-recipe/populate_sdk_base.bbclass | 1 +
 1 file changed, 1 insertion(+)
meta/classes-recipe/populate_sdk_base.bbclass +1 -0
index b23ea26d409..632266cc162 100644
@@ -17,6 +17,7 @@ COMPLEMENTARY_GLOB[dbg-pkgs] = '*-dbg'
 COMPLEMENTARY_GLOB[src-pkgs] = '*-src'
 COMPLEMENTARY_GLOB[ptest-pkgs] = '*-ptest ${MLPREFIX}ptest-runner'
 COMPLEMENTARY_GLOB[bash-completion-pkgs] = '*-bash-completion'
+PATH:prepend = "${COREBASE}/scripts/nativesdk-intercept:"
 
 def complementary_globs(featurevar, d):
     all_globs = d.getVarFlags('COMPLEMENTARY_GLOB')
Signature · 1 line
2.34.1
#3 lore raw

PATCH 2/2 nativesdk-intercept: Fix bad intercept chgrp/chown logic

In reply to Eilís 'pidge' Ní Fhlannagáin

Running either of these ends up corrupting the os.execv args.

If we run:
./scripts/nativesdk-intercept/chown -R foo:foo bar

The loop here ends up missing the conversion of foo:foo to root:root because it sees sys.argv[0] and assumes that it's the user:group argument and that we should convert that. We end up a os.execv(path, args) that have the following args:

['root:root', '-R', 'foo:foo', 'bar']

As os.execv ignores args[0], we can just populate it with sys.argv[0] and then loop through sys.argv[1:]. As both chgrp and chown would have either flags and USER[:GROUP] next, this fixes the issue.

---
 scripts/nativesdk-intercept/chgrp | 5 ++++-
 scripts/nativesdk-intercept/chown | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
scripts/nativesdk-intercept/chgrp +4 -1
index 30cc417d3ac..f8ae84b8b3f 100755
@@ -14,7 +14,10 @@ real_chgrp = shutil.which('chgrp', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chgrp)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
scripts/nativesdk-intercept/chown +4 -1
index 3914b3e3841..0805ceb70a8 100755
@@ -14,7 +14,10 @@ real_chown = shutil.which('chown', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chown)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
Signature · 1 line
2.34.1
#2 lore raw

Re: [OE-core] [PATCH 1/2] populate_sdk_base.bbclass: PATH to nativesdk-intercept chown/chgrp

In reply to Eilís 'pidge' Ní Fhlannagáin
Quoted 16 lines · Eilís 'pidge' Ní Fhlannagáin

[YOCTO #15023]

This patch fixes building the sdk with api-documentation enabled by appending PATH with the nativesdk-intercept directory which contains a special version of chown and chgrp.

---
 meta/classes-recipe/populate_sdk_base.bbclass | 1 +
 1 file changed, 1 insertion(+)
meta/classes-recipe/populate_sdk_base.bbclass +0 -0
index b23ea26d409..632266cc162 100644

meta/classes-recipe/populate_sdk_base.bbclass COMPLEMENTARY_GLOB[dbg-pkgs] = '*-dbg' · line 23

Quoted 7 lines
meta/classes-recipe/populate_sdk_base.bbclass +1 -0
@@ -17,6 +17,7 @@ COMPLEMENTARY_GLOB[dbg-pkgs] = '*-dbg'
 COMPLEMENTARY_GLOB[src-pkgs] = '*-src'
 COMPLEMENTARY_GLOB[ptest-pkgs] = '*-ptest ${MLPREFIX}ptest-runner'
 COMPLEMENTARY_GLOB[bash-completion-pkgs] = '*-bash-completion'
+PATH:prepend = "${COREBASE}/scripts/nativesdk-intercept:"
 
 def complementary_globs(featurevar, d):
     all_globs = d.getVarFlags('COMPLEMENTARY_GLOB')

Sorry to be the bearer of bad news but that won't work. The class is included for normal rootfs generation as well as sdk generation and so it would add the intercepts for normal rootfs too :(

Cheers,

Richard