path: root/meta/recipes-core/base-passwd
diff options
authorRichard Purdie <>2017-04-12 18:29:09 +0100
committerRichard Purdie <>2017-04-13 23:57:37 +0100
commit1b5afaf437f7a1107d4edca8eeb668b9618a5488 (patch)
tree02cb063bb3c443f86ef3bed4f1311c89227bbea3 /meta/recipes-core/base-passwd
parent334020a800434d20e7c3312890a2baca295c41c7 (diff)
base-passwd/useradd: Various improvements to useradd with RSS
Currently there are multiple issues with useradd: * If base-passwd rebuilds, it wipes out recipe specific user/group additions to sysroots and causes errors * If recipe A adds a user and recipe B depends on A, it can't see any of the users/groups A adds. This patch changes base-passwd so it always works as a postinst script within the sysroot and copies in the master files, then runs any postinst-useradd-* scripts afterwards to add additional user/groups. The postinst-useradd-* scripts are tweaked so that if /etc/passwd doesn't exist they just exit, knowning they'll be executed later. We also add a dummy entry to the dummy passwd file from pseudo so we can avoid this too. There is a problem where if recipe A adds a user and recipe B depends on A but doesn't care about users, it may not have a dependency on the useradd/groupadd tools which would therefore not be available in B's sysroot. We therefore also tweak postinst-useradd-* scripts so that if the tools aren't present we simply don't add users. If you need the users, you add a dependency on the tools in the recipe and they'll be added. We add postinst-* to SSTATE_SCAN_FILES since almost any postinst script of this kind is going to need relocation help. We also ensure that the postinst-useradd script is written into the sstate object as the current script was only being added in a recipe local way. Thanks to Peter Kjellerstedt <> and Patrick Ohly for some pieces of this patch. [Yocto #11124] Signed-off-by: Richard Purdie <>
Diffstat (limited to 'meta/recipes-core/base-passwd')
1 files changed, 22 insertions, 6 deletions
diff --git a/meta/recipes-core/base-passwd/ b/meta/recipes-core/base-passwd/
index e43bc0a007..c6be1c1d08 100644
--- a/meta/recipes-core/base-passwd/
+++ b/meta/recipes-core/base-passwd/
@@ -43,16 +43,32 @@ do_install () {
install -p -m 644 ${S}/debian/copyright ${D}${docdir}/${BPN}/
+basepasswd_sysroot_postinst() {
+# Install passwd.master and group.master to sysconfdir
+install -d -m 755 ${STAGING_DIR_TARGET}${sysconfdir}
+for i in passwd group; do
+ install -p -m 644 ${STAGING_DIR_TARGET}${datadir}/base-passwd/\$i.master \
+ ${STAGING_DIR_TARGET}${sysconfdir}/\$i
+# Run any useradd postinsts
+for script in ${STAGING_DIR_TARGET}${bindir}/postinst-useradd-*; do
+ if [ -f \$script ]; then
+ \$script
+ fi
SYSROOT_DIRS += "${sysconfdir}"
SYSROOT_PREPROCESS_FUNCS += "base_passwd_tweaksysroot"
base_passwd_tweaksysroot () {
- # Install passwd.master and group.master to sysconfdir
- install -d -m 755 ${SYSROOT_DESTDIR}${sysconfdir}
- for i in passwd group; do
- install -p -m 644 ${SYSROOT_DESTDIR}${datadir}/base-passwd/$i.master \
- ${SYSROOT_DESTDIR}${sysconfdir}/$i
- done
+ mkdir -p ${SYSROOT_DESTDIR}${bindir}
+ dest=${SYSROOT_DESTDIR}${bindir}/postinst-${PN}
+ echo "${basepasswd_sysroot_postinst}" > $dest
+ chmod 0755 $dest
python populate_packages_prepend() {