diff options
| author | Piotr Łobacz <p.lobacz@welotec.com> | 2024-02-23 13:25:20 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-02-24 16:10:22 +0000 |
| commit | f6daeba2e97e47550e959fb85d4639ef81d268e7 (patch) | |
| tree | 6b6a19eeee05e76416689e18c1973fbec43241f3 | |
| parent | 0e3bcc51037aa8e1f7992756f7476a879625b114 (diff) | |
| download | poky-f6daeba2e97e47550e959fb85d4639ef81d268e7.tar.gz | |
useradd.bbclass: Fix order of postinst-useradd-*
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]
(From OE-Core rev: 322ef726132a47d977d2c6ee41de5358f1e85994)
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>
| -rw-r--r-- | meta/classes-global/staging.bbclass | 4 | ||||
| -rw-r--r-- | meta/classes/useradd.bbclass | 71 |
2 files changed, 47 insertions, 28 deletions
diff --git a/meta/classes-global/staging.bbclass b/meta/classes-global/staging.bbclass index ab3e1d71b5..3678a1b441 100644 --- a/meta/classes-global/staging.bbclass +++ b/meta/classes-global/staging.bbclass | |||
| @@ -245,7 +245,7 @@ def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d): | |||
| 245 | continue | 245 | continue |
| 246 | 246 | ||
| 247 | staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d) | 247 | staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d) |
| 248 | for p in postinsts: | 248 | for p in sorted(postinsts): |
| 249 | bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT))) | 249 | bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT))) |
| 250 | 250 | ||
| 251 | # | 251 | # |
| @@ -629,7 +629,7 @@ python extend_recipe_sysroot() { | |||
| 629 | for f in fixme: | 629 | for f in fixme: |
| 630 | staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d) | 630 | staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d) |
| 631 | 631 | ||
| 632 | for p in postinsts: | 632 | for p in sorted(postinsts): |
| 633 | bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT))) | 633 | bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT))) |
| 634 | 634 | ||
| 635 | for dep in manifests: | 635 | for dep in manifests: |
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass index f0ec080920..16a65ac323 100644 --- a/meta/classes/useradd.bbclass +++ b/meta/classes/useradd.bbclass | |||
| @@ -103,6 +103,18 @@ fi | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | useradd_sysroot () { | 105 | useradd_sysroot () { |
| 106 | user_group_groupmems_add_sysroot user | ||
| 107 | } | ||
| 108 | |||
| 109 | groupadd_sysroot () { | ||
| 110 | user_group_groupmems_add_sysroot group | ||
| 111 | } | ||
| 112 | |||
| 113 | groupmemsadd_sysroot () { | ||
| 114 | user_group_groupmems_add_sysroot groupmems | ||
| 115 | } | ||
| 116 | |||
| 117 | user_group_groupmems_add_sysroot () { | ||
| 106 | # Pseudo may (do_prepare_recipe_sysroot) or may not (do_populate_sysroot_setscene) be running | 118 | # Pseudo may (do_prepare_recipe_sysroot) or may not (do_populate_sysroot_setscene) be running |
| 107 | # at this point so we're explicit about the environment so pseudo can load if | 119 | # at this point so we're explicit about the environment so pseudo can load if |
| 108 | # not already present. | 120 | # not already present. |
| @@ -131,9 +143,15 @@ useradd_sysroot () { | |||
| 131 | fi | 143 | fi |
| 132 | 144 | ||
| 133 | # Add groups and users defined for all recipe packages | 145 | # Add groups and users defined for all recipe packages |
| 134 | GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" | 146 | if test "$1" = "group"; then |
| 135 | USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" | 147 | GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" |
| 136 | GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}" | 148 | elif test "$1" = "user"; then |
| 149 | USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" | ||
| 150 | elif test "$1" = "groupmems"; then | ||
| 151 | GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}" | ||
| 152 | elif test "x$1" = "x"; then | ||
| 153 | bbwarn "missing type of passwd db action" | ||
| 154 | fi | ||
| 137 | 155 | ||
| 138 | # Tell the system to use the environment vars | 156 | # Tell the system to use the environment vars |
| 139 | UA_SYSROOT=1 | 157 | UA_SYSROOT=1 |
| @@ -148,29 +166,30 @@ useradd_sysroot () { | |||
| 148 | EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO" | 166 | EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO" |
| 149 | 167 | ||
| 150 | python useradd_sysroot_sstate () { | 168 | python useradd_sysroot_sstate () { |
| 151 | scriptfile = None | 169 | for type, sort_prefix in [("group", "01"), ("user", "02"), ("groupmems", "03")]: |
| 152 | task = d.getVar("BB_CURRENTTASK") | 170 | scriptfile = None |
| 153 | if task == "package_setscene": | 171 | task = d.getVar("BB_CURRENTTASK") |
| 154 | bb.build.exec_func("useradd_sysroot", d) | 172 | if task == "package_setscene": |
| 155 | elif task == "prepare_recipe_sysroot": | 173 | bb.build.exec_func(type + "add_sysroot", d) |
| 156 | # Used to update this recipe's own sysroot so the user/groups are available to do_install | 174 | elif task == "prepare_recipe_sysroot": |
| 157 | 175 | # Used to update this recipe's own sysroot so the user/groups are available to do_install | |
| 158 | # If do_populate_sysroot is triggered and we write the file here, there would be an overlapping | 176 | |
| 159 | # files. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package | 177 | # If do_populate_sysroot is triggered and we write the file here, there would be an overlapping |
| 160 | scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-${PN}-recipedebug") | 178 | # files. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package |
| 161 | 179 | scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}-recipedebug") | |
| 162 | bb.build.exec_func("useradd_sysroot", d) | 180 | |
| 163 | elif task == "populate_sysroot": | 181 | bb.build.exec_func(type + "add_sysroot", d) |
| 164 | # Used when installed in dependent task sysroots | 182 | elif task == "populate_sysroot": |
| 165 | scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-${PN}") | 183 | # Used when installed in dependent task sysroots |
| 166 | 184 | scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}") | |
| 167 | if scriptfile: | 185 | |
| 168 | bb.utils.mkdirhier(os.path.dirname(scriptfile)) | 186 | if scriptfile: |
| 169 | with open(scriptfile, 'w') as script: | 187 | bb.utils.mkdirhier(os.path.dirname(scriptfile)) |
| 170 | script.write("#!/bin/sh -e\n") | 188 | with open(scriptfile, 'w') as script: |
| 171 | bb.data.emit_func("useradd_sysroot", script, d) | 189 | script.write("#!/bin/sh -e\n") |
| 172 | script.write("useradd_sysroot\n") | 190 | bb.data.emit_func(type + "add_sysroot", script, d) |
| 173 | os.chmod(scriptfile, 0o755) | 191 | script.write(type + "add_sysroot\n") |
| 192 | os.chmod(scriptfile, 0o755) | ||
| 174 | } | 193 | } |
| 175 | 194 | ||
| 176 | do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}" | 195 | do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}" |
