]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
useradd.bbclass: Fix order of postinst-useradd-*
authorPiotr Łobacz <p.lobacz@welotec.com>
Fri, 23 Feb 2024 13:25:20 +0000 (13:25 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 24 Feb 2024 16:10:19 +0000 (16:10 +0000)
postinst-useradd-* haven't been running in order of dependency.

This patch is reworked from Piotr Łobacz's patch and fixes:

https://bugzilla.yoctoproject.org/show_bug.cgi?id=15084
https://bugzilla.yoctoproject.org/show_bug.cgi?id=13904

basepasswd_sysroot_postinst in base-passwd can install postinst-useradd-*
scripts with any order. Sometimes this means, for example a useradd postinst
will attempt to run without the corresponding group postinst causing errors.
This patch ensures that we first run groupadd, then useradd and then
group membership.

[RP: Tweaked to avoid removing previous fixes and for whitespace/style issues
     Also ensure the scripts are changed to execute with -e to highlight errors]

Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
Signed-off-by: Piotr Łobacz <p.lobacz@welotec.com>
Signed-off-by: Jan Górski <j.gorski@welotec.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-global/staging.bbclass
meta/classes/useradd.bbclass

index ab3e1d71b520d814d3b19b905d18bab2694945c0..3678a1b4415f02d7c7b97d7aadbf2a81833e2da2 100644 (file)
@@ -245,7 +245,7 @@ def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
                         continue
 
     staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d)
-    for p in postinsts:
+    for p in sorted(postinsts):
         bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
 
 #
@@ -629,7 +629,7 @@ python extend_recipe_sysroot() {
     for f in fixme:
         staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
 
-    for p in postinsts:
+    for p in sorted(postinsts):
         bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
 
     for dep in manifests:
index f0ec080920399b9eac35767339340c225e6d27ce..16a65ac3236e6492c3c54e13520fd2d8bbb900a6 100644 (file)
@@ -103,6 +103,18 @@ fi
 }
 
 useradd_sysroot () {
+       user_group_groupmems_add_sysroot user
+}
+
+groupadd_sysroot () {
+       user_group_groupmems_add_sysroot group
+}
+
+groupmemsadd_sysroot () {
+       user_group_groupmems_add_sysroot groupmems
+}
+
+user_group_groupmems_add_sysroot () {
        # Pseudo may (do_prepare_recipe_sysroot) or may not (do_populate_sysroot_setscene) be running 
        # at this point so we're explicit about the environment so pseudo can load if 
        # not already present.
@@ -131,9 +143,15 @@ useradd_sysroot () {
        fi
 
        # Add groups and users defined for all recipe packages
-       GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
-       USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
-       GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
+       if test "$1" = "group"; then
+               GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
+       elif test "$1" = "user"; then
+               USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
+       elif test "$1" = "groupmems"; then
+               GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
+       elif test "x$1" = "x"; then
+               bbwarn "missing type of passwd db action"
+       fi
 
        # Tell the system to use the environment vars
        UA_SYSROOT=1
@@ -148,29 +166,30 @@ useradd_sysroot () {
 EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO"
 
 python useradd_sysroot_sstate () {
-    scriptfile = None
-    task = d.getVar("BB_CURRENTTASK")
-    if task == "package_setscene":
-        bb.build.exec_func("useradd_sysroot", d)
-    elif task == "prepare_recipe_sysroot":
-        # Used to update this recipe's own sysroot so the user/groups are available to do_install
-
-        # If do_populate_sysroot is triggered and we write the file here, there would be an overlapping
-        # files. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package
-        scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-${PN}-recipedebug")
-
-        bb.build.exec_func("useradd_sysroot", d)
-    elif task == "populate_sysroot":
-        # Used when installed in dependent task sysroots
-        scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-${PN}")
-
-    if scriptfile:
-        bb.utils.mkdirhier(os.path.dirname(scriptfile))
-        with open(scriptfile, 'w') as script:
-            script.write("#!/bin/sh -e\n")
-            bb.data.emit_func("useradd_sysroot", script, d)
-            script.write("useradd_sysroot\n")
-        os.chmod(scriptfile, 0o755)
+    for type, sort_prefix in [("group", "01"), ("user", "02"), ("groupmems", "03")]:
+        scriptfile = None
+        task = d.getVar("BB_CURRENTTASK")
+        if task == "package_setscene":
+            bb.build.exec_func(type + "add_sysroot", d)
+        elif task == "prepare_recipe_sysroot":
+            # Used to update this recipe's own sysroot so the user/groups are available to do_install
+
+            # If do_populate_sysroot is triggered and we write the file here, there would be an overlapping
+            # files. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package
+            scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}-recipedebug")
+
+            bb.build.exec_func(type + "add_sysroot", d)
+        elif task == "populate_sysroot":
+            # Used when installed in dependent task sysroots
+            scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}")
+
+        if scriptfile:
+            bb.utils.mkdirhier(os.path.dirname(scriptfile))
+            with open(scriptfile, 'w') as script:
+                script.write("#!/bin/sh -e\n")
+                bb.data.emit_func(type + "add_sysroot", script, d)
+                script.write(type + "add_sysroot\n")
+            os.chmod(scriptfile, 0o755)
 }
 
 do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}"