diff mbox series

[1/2] build-sysroots: Serialize native and target sysroot population

Message ID 20260130075333.940897-2-adrian.freihofer@siemens.com
State New
Headers show
Series fix bug 16135 - useradd/groupadd debug output includes PATH | expand

Commit Message

AdrianF Jan. 30, 2026, 7:52 a.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Calling (what devtool ide-sdk --mode shared does internally):
  bitbake meta-ide-support:do_build cmake-example:do_populate_sysroot
  bitbake build-sysroots:do_build_target_sysroot \
          build-sysroots:do_build_native_sysroot

can fail with errors like:
  Exception: subprocess.CalledProcessError:
  Command '.../tmp/sysroots/qemux86-64/usr/bin/postinst-base-passwd'
  returned non-zero exit status 1.

  Subprocess output:
  .../tmp/sysroots/x86_64/usr/sbin/useradd
  Running groupadd commands...
  NOTE: cmake-example: Performing groupadd with
    [--root ../tmp/sysroots/qemux86-64 --system cmake-example]
  awk: error while loading shared libraries: libtinfo.so.5: cannot open
       shared object file: No such file or directory
  ERROR: cmake-example: groupadd command did not succeed.

The root cause is a race condition between do_build_target_sysroot and
do_build_native_sysroot. When run in parallel, do_build_target_sysroot
executes postinstall scripts (e.g., useradd) that invoke awk, while
do_build_native_sysroot is concurrently installing gawk-native into the
shared native sysroot (which is in PATH for do_build_target_sysroot).

Since sstate artifact installation is not atomic, awk binaries can be
installed before their dependent libraries. If do_build_target_sysroot
picks up the newly installed but incomplete awk, it fails with missing
library errors.

The situation is created by a mix of:
- gawk-native in ASSUME_PROVIDED (use host awk)
- glibc depending on gawk-replacement-native (builds gawk-native)
- Both tasks populating the same shared native sysroot directory

Fix this by adding a lockfile to both tasks, ensuring they cannot run
concurrently and avoiding the race condition where partially installed
native tools are accessed. While lockfiles are generally avoided in
BitBake due to performance concerns, this is acceptable here since these
tasks are not on a critical performance path.

[YOCTO #16135]

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/recipes-core/meta/build-sysroots.bb | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/meta/recipes-core/meta/build-sysroots.bb b/meta/recipes-core/meta/build-sysroots.bb
index b0b8fb3c79..3ee9565862 100644
--- a/meta/recipes-core/meta/build-sysroots.bb
+++ b/meta/recipes-core/meta/build-sysroots.bb
@@ -36,6 +36,7 @@  python do_build_native_sysroot () {
 }
 do_build_native_sysroot[cleandirs] = "${STANDALONE_SYSROOT_NATIVE}"
 do_build_native_sysroot[nostamp] = "1"
+do_build_native_sysroot[lockfiles] = "${WORKDIR}/build-sysroots.lock"
 addtask do_build_native_sysroot
 
 python do_build_target_sysroot () {
@@ -47,6 +48,7 @@  python do_build_target_sysroot () {
 }
 do_build_target_sysroot[cleandirs] = "${STANDALONE_SYSROOT}"
 do_build_target_sysroot[nostamp] = "1"
+do_build_target_sysroot[lockfiles] = "${WORKDIR}/build-sysroots.lock"
 addtask do_build_target_sysroot
 
 do_clean[cleandirs] += "${STANDALONE_SYSROOT} ${STANDALONE_SYSROOT_NATIVE}"