useradd.bbclass: remove user/group created by the package in clean* task
PATCH v2 1/1 useradd.bbclass: remove user/group created by the package in clean* task
At present, if a recipe is built which creates users/groups via useradd.bbclass, those users/groups are not removed (at least from sysroot) when the recipe/package is cleaned using clean/cleansstate/cleanall.
The "userdel_sysroot_sstate()" provides that functionality.
[YOCTO #9262]
--- meta/classes/sstate.bbclass | 6 ++++++ meta/classes/useradd.bbclass | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
meta/classes/sstate.bbclass +6 -0
@@ -51,6 +51,7 @@ SSTATEPREINSTFUNCS = "" SSTATEPOSTUNPACKFUNCS = "sstate_hardcode_path_unpack" SSTATEPOSTINSTFUNCS = "" EXTRA_STAGING_FIXMES ?= "" +SSTATECLEANFUNCS = "" SIGGEN_LOCKEDSIGS_CHECK_LEVEL ?= 'error'
@@ -444,6 +445,11 @@ def sstate_clean(ss, d): stfile.endswith(rm_nohash): oe.path.remove(stfile) + # Remove the users/groups created by the package + for cleanfunc in (d.getVar('SSTATECLEANFUNCS', True) or '').split(): + if d.getVar('BB_CURRENTTASK', True) in ['configure', 'clean']: + bb.build.exec_func(cleanfunc, d) + sstate_clean[vardepsexclude] = "SSTATE_MANFILEPREFIX" CLEANFUNCS += "sstate_cleanall"
meta/classes/useradd.bbclass +26 -0
@@ -127,6 +127,32 @@ useradd_sysroot_sstate () { fi } +userdel_sysroot_sstate () { +if test "x${STAGING_DIR_TARGET}" != "x"; then + export PSEUDO="${FAKEROOTENV} PSEUDO_LOCALSTATEDIR=${STAGING_DIR_TARGET}${localstatedir}/pseudo ${STAGING_DIR_NATIVE}${bindir}/pseudo" + OPT="--root ${STAGING_DIR_TARGET}" + + # Remove groups and users defined for package + GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" + USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" + + if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x"; then + user=`echo "$USERADD_PARAM" | cut -d ';' -f 1 | awk '{ print $NF }'` + perform_userdel "${STAGING_DIR_TARGET}" "$OPT $user" + fi + + if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x"; then + group=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1 | awk '{ print $NF }'` + perform_groupdel "${STAGING_DIR_TARGET}" "$OPT $group" + fi +fi +} + +SSTATECLEANFUNCS = "userdel_sysroot_sstate" +SSTATECLEANFUNCS_class-cross = "" +SSTATECLEANFUNCS_class-native = "" +SSTATECLEANFUNCS_class-nativesdk = "" + do_install[prefuncs] += "${SYSROOTFUNC}" SYSROOTFUNC = "useradd_sysroot" SYSROOTFUNC_class-cross = ""
Signature · 1 line
2.4.0
Quoted 4 lines · Maxin B. John
At present, if a recipe is built which creates users/groups via useradd.bbclass,
those users/groups are not removed (at least from sysroot) when the recipe/package is cleaned using clean/cleansstate/cleanall.
need to add "or when a recipe is rebuild and 'unstaged' from the the sysroot".
Quoted 32 lines
The "
userdel_sysroot_sstate()" provides that functionality.[YOCTO #9262]
Signed-off-by Maxin B. John <[email protected]>--- meta/classes/sstate.bbclass | 6 ++++++ meta/classes/useradd.bbclass | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)meta/classes/sstate.bbclass +3
-0@@ -51,6 +51,7 @@ SSTATEPREINSTFUNCS = "" SSTATEPOSTUNPACKFUNCS = "sstate_hardcode_path_unpack" SSTATEPOSTINSTFUNCS = "" EXTRA_STAGING_FIXMES ?= "" +SSTATECLEANFUNCS = "" SIGGEN_LOCKEDSIGS_CHECK_LEVEL ?= 'error'@@ -444,6 +445,11 @@ def sstate_clean(ss, d): stfile.endswith(rm_nohash): oe.path.remove(stfile) + # Remove the users/groups created by the package + for cleanfunc in (d.getVar('SSTATECLEANFUNCS', True) or'').split():
+ ifd.getVar('BB_CURRENTTASK', True)in ['configure',
'clean']:
meta/classes/sstate.bbclass def sstate_clean(ss, d): · line 452
Quoted 2 lines
meta/classes/sstate.bbclass +2
-0+ bb.build.exec_func(cleanfunc, d) +
The hook needs to be generic so the BB_CURRENTTASK check needs to move to userdel_sysroot_sstate itself.
Otherwise looks good though, thanks.
Cheers,
Richard
Quoted 50 lines
sstate_clean[vardepsexclude] = "
SSTATE_MANFILEPREFIX"CLEANFUNCS += "
sstate_cleanall"meta/classes/useradd.bbclass +3
-0@@ -127,6 +127,32 @@ useradd_sysroot_sstate () { fi } +userdel_sysroot_sstate () { +if test "x${STAGING_DIR_TARGET}" != "x"; then + export PSEUDO="${FAKEROOTENV}PSEUDO_LOCALSTATEDIR=${STAGING_DIR_TARGET}${localstatedir}/pseudo ${STAGING_DIR_NATIVE}${bindir}/pseudo"
meta/classes/useradd.bbclass +7
-0+ OPT="--root ${STAGING_DIR_TARGET}" + + # Remove groups and users defined for package + GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" + USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" + + if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x";then
+ user=`echo "$USERADD_PARAM" | cut -d ';' -f 1 | awk '{ print
$NF }'`meta/classes/useradd.bbclass +4
-0+ perform_userdel "${STAGING_DIR_TARGET}" "$OPT $user" + fi + + if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x";then
+ group=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1 | awk '{
print $NF }'`meta/classes/useradd.bbclass +10
-0+ perform_groupdel "${STAGING_DIR_TARGET}" "$OPT $group" + fi +fi +} + +SSTATECLEANFUNCS = "userdel_sysroot_sstate" +SSTATECLEANFUNCS_class-cross = "" +SSTATECLEANFUNCS_class-native = "" +SSTATECLEANFUNCS_class-nativesdk = "" + do_install[prefuncs] += "${SYSROOTFUNC}" SYSROOTFUNC = "useradd_sysroot" SYSROOTFUNC_class-cross = ""Signature · 1 line
2.4.0
Hi,
Quoted 8 lines · Richard Purdie
Quoted 4 lines · Maxin B. John
At present, if a recipe is built which creates users/groups via useradd.bbclass,
those users/groups are not removed (at least from sysroot) when the recipe/package is cleaned using clean/cleansstate/cleanall.need to add "or when a recipe is rebuild and 'unstaged' from the the sysroot".
Thanks for pointing it out. I will update the commit message and send v3 soon.
Quoted 85 lines
Quoted 32 lines
The "
userdel_sysroot_sstate()" provides that functionality.[YOCTO #9262]
Signed-off-by Maxin B. John <[email protected]>--- meta/classes/sstate.bbclass | 6 ++++++ meta/classes/useradd.bbclass | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)meta/classes/sstate.bbclass +3
-0@@ -51,6 +51,7 @@ SSTATEPREINSTFUNCS = "" SSTATEPOSTUNPACKFUNCS = "sstate_hardcode_path_unpack" SSTATEPOSTINSTFUNCS = "" EXTRA_STAGING_FIXMES ?= "" +SSTATECLEANFUNCS = "" SIGGEN_LOCKEDSIGS_CHECK_LEVEL ?= 'error'@@ -444,6 +445,11 @@ def sstate_clean(ss, d): stfile.endswith(rm_nohash): oe.path.remove(stfile) + # Remove the users/groups created by the package + for cleanfunc in (d.getVar('SSTATECLEANFUNCS', True) or'').split():
+ ifd.getVar('BB_CURRENTTASK', True)in ['configure',
'clean']:meta/classes/sstate.bbclass def sstate_clean(ss, d): · line 452
Quoted 2 lines
meta/classes/sstate.bbclass +2
-0+ bb.build.exec_func(cleanfunc, d) +The hook needs to be generic so the
BB_CURRENTTASKcheck needs to move touserdel_sysroot_sstateitself.Otherwise looks good though, thanks.
Cheers,
Richard
Quoted 41 lines
sstate_clean[vardepsexclude] = "
SSTATE_MANFILEPREFIX"CLEANFUNCS += "
sstate_cleanall"meta/classes/useradd.bbclass +3
-0@@ -127,6 +127,32 @@ useradd_sysroot_sstate () { fi } +userdel_sysroot_sstate () { +if test "x${STAGING_DIR_TARGET}" != "x"; then + export PSEUDO="${FAKEROOTENV}PSEUDO_LOCALSTATEDIR=${STAGING_DIR_TARGET}${localstatedir}/pseudo ${STAGING_DIR_NATIVE}${bindir}/pseudo"
meta/classes/useradd.bbclass +7
-0+ OPT="--root ${STAGING_DIR_TARGET}" + + # Remove groups and users defined for package + GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" + USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" + + if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x";then
+ user=`echo "$USERADD_PARAM" | cut -d ';' -f 1 | awk '{ print
$NF }'`meta/classes/useradd.bbclass +4
-0+ perform_userdel "${STAGING_DIR_TARGET}" "$OPT $user" + fi + + if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x";then
+ group=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1 | awk '{
print $NF }'`meta/classes/useradd.bbclass +7
-0+ perform_groupdel "${STAGING_DIR_TARGET}" "$OPT $group" + fi +fi +} + +SSTATECLEANFUNCS = "userdel_sysroot_sstate" +SSTATECLEANFUNCS_class-cross = ""
Quoted 8 lines
Quoted 8 lines
meta/classes/useradd.bbclass +3
-0+SSTATECLEANFUNCS_class-native = "" +SSTATECLEANFUNCS_class-nativesdk = "" + do_install[prefuncs] += "${SYSROOTFUNC}" SYSROOTFUNC = "useradd_sysroot" SYSROOTFUNC_class-cross = ""Signature · 1 line
2.4.0
Best Regards,
Maxin