diff mbox series

[1/3] useradd.bbclass: Fix order of postinst-useradd-*

Message ID 5eb199fe11d71f598726b75808b3330cd3efd2e5.1708613381.git.pidge@baylibre.com
State Accepted, archived
Commit 322ef726132a47d977d2c6ee41de5358f1e85994
Headers show
Series Useradd postinstall fixes and tests | expand

Commit Message

Eilís 'pidge' Ní Fhlannagáin Feb. 22, 2024, 2:53 p.m. UTC
From: Piotr Łobacz <p.lobacz@welotec.com>

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

It ensures that groups, users and groupmems are all run in the correct order.

Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
---
 meta/classes-global/staging.bbclass |  7 +--
 meta/classes/useradd.bbclass        | 72 ++++++++++++++++++-----------
 2 files changed, 49 insertions(+), 30 deletions(-)

Comments

Richard Purdie Feb. 22, 2024, 3:02 p.m. UTC | #1
On Thu, 2024-02-22 at 14:53 +0000, Eilís 'pidge' Ní Fhlannagáin wrote:
> From: Piotr Łobacz <p.lobacz@welotec.com>
> 
> 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
> 
> It ensures that groups, users and groupmems are all run in the correct order.

I think this needs a little bit more explanation in the commit message.
What is the issue, why do we need to solve it like this etc.

> 
> Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
> ---
>  meta/classes-global/staging.bbclass |  7 +--
>  meta/classes/useradd.bbclass        | 72 ++++++++++++++++++-----------
>  2 files changed, 49 insertions(+), 30 deletions(-)
> 
> diff --git a/meta/classes-global/staging.bbclass b/meta/classes-global/staging.bbclass
> index ab3e1d71b5..6c21510377 100644
> --- a/meta/classes-global/staging.bbclass
> +++ b/meta/classes-global/staging.bbclass
> @@ -245,8 +245,9 @@ def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
>                          continue
>  
>      staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d)
> -    for p in postinsts:
> -        bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))


> +    bb.warn(sorted(postinsts))

Come on, please! :)


> +    for p in sorted(postinsts):
> +        bb.warn("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
>  
>  #
>  # Manifests here are complicated. The main sysroot area has the unpacked sstate
> @@ -629,7 +630,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:
> diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
> index a58f8287c9..924eeadf9c 100644
> --- a/meta/classes/useradd.bbclass
> +++ b/meta/classes/useradd.bbclass
> @@ -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.
> @@ -130,10 +142,19 @@ useradd_sysroot () {
>  		exit 0
>  	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')}"
> + 	# Add groups and users defined for all recipe packages
> +	if test "x$1" = "xgroup"; then
> +		GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
> +	fi
> +	if test "x$1" = "xuser"; then
> +		USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
> +	fi
> +	if test "x$1" = "xgroupmems"; then
> +		GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
> +	fi
> +	if test "x$1" = "x"; then
> +		bbwarn "missing type of passwd db action"
> +    fi		

whitespace...



Cheers,

Richard
Piotr Łobacz Feb. 22, 2024, 3:05 p.m. UTC | #2
Dnia czwartek, 22 lutego 2024 16:02:47 CET Richard Purdie pisze:
> On Thu, 2024-02-22 at 14:53 +0000, Eilís 'pidge' Ní Fhlannagáin wrote:
> > From: Piotr Łobacz <p.lobacz@welotec.com>
> > 
> > postinst-useradd-* haven't been running in order of dependency.
> > 
> > This patch is reworked from Piotr Łobacz's patch and fixes:
> > 
> > https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla
> > .yoctoproject.org%2Fshow_bug.cgi%3Fid%3D15084&data=05%7C02%7Cp.lobacz%40we
> > lotec.com%7C71e58402c2f2409f56bb08dc33b755b3%7C25111a7f1d5a4c51a4ca7f8e440
> > 11b39%7C0%7C0%7C638442109731703010%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA
> > wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2B
> > U2cg6Esme3QhxIwjKW417DMncM%2FwWjEChZwrBNullA%3D&reserved=0
> > https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzill
> > a.yoctoproject.org%2Fshow_bug.cgi%3Fid%3D13904&data=05%7C02%7Cp.lobacz%40w
> > elotec.com%7C71e58402c2f2409f56bb08dc33b755b3%7C25111a7f1d5a4c51a4ca7f8e44
> > 011b39%7C0%7C0%7C638442109731710513%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
> > AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=s3
> > %2B9l0f1cr7JKjcg9R9arzZHAnBPOzOtecWUGj1vBF4%3D&reserved=0
> > 
> > It ensures that groups, users and groupmems are all run in the correct
> > order.
> I think this needs a little bit more explanation in the commit message.
> What is the issue, why do we need to solve it like this etc.

Acctualy, the issue was discovered by me and the patch given by me was created 
by Jan so I think he can put his comments on that. That would be the best I 
think.

> > Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
> > ---
> >  meta/classes-global/staging.bbclass |  7 +--
> >  meta/classes/useradd.bbclass        | 72 ++++++++++++++++++-----------
> >  2 files changed, 49 insertions(+), 30 deletions(-)
> > 
> > diff --git a/meta/classes-global/staging.bbclass
> > b/meta/classes-global/staging.bbclass index ab3e1d71b5..6c21510377 100644
> > --- a/meta/classes-global/staging.bbclass
> > +++ b/meta/classes-global/staging.bbclass
> > @@ -245,8 +245,9 @@ def staging_populate_sysroot_dir(targetsysroot,
> > nativesysroot, native, d): continue
> >  
> >      staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot,
> > d) -    for p in postinsts:
> > -        bb.note("Running postinst {}, output:\n{}".format(p,
> > subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
> > 
> > 
> > +    bb.warn(sorted(postinsts))
> 
> Come on, please! :)
> 
> > +    for p in sorted(postinsts):
> > +        bb.warn("Running postinst {}, output:\n{}".format(p,
> > subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT))) 
> >  #
> >  # Manifests here are complicated. The main sysroot area has the unpacked
> > sstate @@ -629,7 +630,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:
> > diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
> > index a58f8287c9..924eeadf9c 100644
> > --- a/meta/classes/useradd.bbclass
> > +++ b/meta/classes/useradd.bbclass
> > @@ -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.
> > @@ -130,10 +142,19 @@ useradd_sysroot () {
> >  		exit 0
> >  	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')}"
> > + 	# Add groups and users defined for all recipe packages
> > +	if test "x$1" = "xgroup"; then
> > +		GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
> > +	fi
> > +	if test "x$1" = "xuser"; then
> > +		USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
> > +	fi
> > +	if test "x$1" = "xgroupmems"; then
> > +		GROUPMEMS_PARAM="${@get_all_cmd_params(d, 
'groupmems')}"
> > +	fi
> > +	if test "x$1" = "x"; then
> > +		bbwarn "missing type of passwd db action"
> > +    fi
> 
> whitespace...
> 
> 
> 
> Cheers,
> 
> Richard

BR
Piotr
Jermain Horsman Feb. 23, 2024, 9:10 a.m. UTC | #3
Although I did notice the rest of the file uses this syntax,
and I do not believe there are any guidelines specific to this (that I am aware of),
I did want to comment on this.

> +	if test "x$1" = "xgroup"; then

> +	if test "x$1" = "xuser"; then

> +	if test "x$1" = "xgroupmems"; then

As these are quotes variables the added 'x' doesn't really add anything here.

> +	if test "x$1" = "x"; then

Same here, but this could just test for a zero length variable instead using 'test -z "$1"'.

Sincerely,

Jermain Horsman
ChenQi Feb. 23, 2024, 9:36 a.m. UTC | #4
1. I can see what this patch mainly does is ensuring groups first, then 
user, then groupmems. But the current useradd_preinst, which is called 
by useradd_sysroot has already ensured this. Is that not working?

2. You're using bb.warn as a method of outputting debugging information, 
which I don't think is appropriate.

Regards,
Qi

On 2/22/24 22:53, Eilís 'pidge' Ní Fhlannagáin wrote:
> From: Piotr Łobacz <p.lobacz@welotec.com>
>
> 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
>
> It ensures that groups, users and groupmems are all run in the correct order.
>
> Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
> ---
>   meta/classes-global/staging.bbclass |  7 +--
>   meta/classes/useradd.bbclass        | 72 ++++++++++++++++++-----------
>   2 files changed, 49 insertions(+), 30 deletions(-)
>
> diff --git a/meta/classes-global/staging.bbclass b/meta/classes-global/staging.bbclass
> index ab3e1d71b5..6c21510377 100644
> --- a/meta/classes-global/staging.bbclass
> +++ b/meta/classes-global/staging.bbclass
> @@ -245,8 +245,9 @@ def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
>                           continue
>   
>       staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d)
> -    for p in postinsts:
> -        bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
> +    bb.warn(sorted(postinsts))
> +    for p in sorted(postinsts):
> +        bb.warn("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
>   
>   #
>   # Manifests here are complicated. The main sysroot area has the unpacked sstate
> @@ -629,7 +630,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:
> diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
> index a58f8287c9..924eeadf9c 100644
> --- a/meta/classes/useradd.bbclass
> +++ b/meta/classes/useradd.bbclass
> @@ -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.
> @@ -130,10 +142,19 @@ useradd_sysroot () {
>   		exit 0
>   	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')}"
> + 	# Add groups and users defined for all recipe packages
> +	if test "x$1" = "xgroup"; then
> +		GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
> +	fi
> +	if test "x$1" = "xuser"; then
> +		USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
> +	fi
> +	if test "x$1" = "xgroupmems"; then
> +		GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
> +	fi
> +	if 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 +169,26 @@ 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(f"{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
> +            scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/" f"postinst-useradd-{sort_prefix}{type}" "-${PN}")
> +            bb.build.exec_func(f"{type}add_sysroot", d)
> +        elif task == "populate_sysroot":
> +            # Used when installed in dependent task sysroots
> +            scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/" f"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\n")
> +                bb.data.emit_func(f"{type}add_sysroot", script, d)
> +                script.write(f"{type}add_sysroot\n")
> +            os.chmod(scriptfile, 0o755)
>   }
>   
>   do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}"
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#196031): https://lists.openembedded.org/g/openembedded-core/message/196031
> Mute This Topic: https://lists.openembedded.org/mt/104509398/7304865
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [Qi.Chen@eng.windriver.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Piotr Łobacz Feb. 23, 2024, 9:57 a.m. UTC | #5
Dnia piątek, 23 lutego 2024 10:36:27 CET Chen Qi via lists.openembedded.org 
pisze:
> 1. I can see what this patch mainly does is ensuring groups first, then
> user, then groupmems. But the current useradd_preinst, which is called
> by useradd_sysroot has already ensured this. Is that not working?

It is working but all postinst scripts are being called alphabetically which 
in some corner cases is causing the failures...

> 2. You're using bb.warn as a method of outputting debugging information,
> which I don't think is appropriate.

> Regards,
> Qi
> 
> On 2/22/24 22:53, Eilís 'pidge' Ní Fhlannagáin wrote:
> > From: Piotr Łobacz <p.lobacz@welotec.com>
> > 
> > postinst-useradd-* haven't been running in order of dependency.
> > 
> > This patch is reworked from Piotr Łobacz's patch and fixes:
> > 
> > https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla
> > .yoctoproject.org%2Fshow_bug.cgi%3Fid%3D15084&data=05%7C02%7Cp.lobacz%40we
> > lotec.com%7C4b378de2bbf8442903fe08dc3452f110%7C25111a7f1d5a4c51a4ca7f8e440
> > 11b39%7C0%7C0%7C638442778043567095%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA
> > wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=NtJ
> > L1zoUYxbKRErJ9GBH6cx%2F2UMoSFAT53LLQ8XBzYk%3D&reserved=0
> > https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzill
> > a.yoctoproject.org%2Fshow_bug.cgi%3Fid%3D13904&data=05%7C02%7Cp.lobacz%40w
> > elotec.com%7C4b378de2bbf8442903fe08dc3452f110%7C25111a7f1d5a4c51a4ca7f8e44
> > 011b39%7C0%7C0%7C638442778043575031%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
> > AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=wY
> > jvmpaXqsu8GzyGrYJflJA8oNxniQXkDKZ8GxKRnXY%3D&reserved=0
> > 
> > It ensures that groups, users and groupmems are all run in the correct
> > order.
> > 
> > Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
> > ---
> > 
> >   meta/classes-global/staging.bbclass |  7 +--
> >   meta/classes/useradd.bbclass        | 72 ++++++++++++++++++-----------
> >   2 files changed, 49 insertions(+), 30 deletions(-)
> > 
> > diff --git a/meta/classes-global/staging.bbclass
> > b/meta/classes-global/staging.bbclass index ab3e1d71b5..6c21510377 100644
> > --- a/meta/classes-global/staging.bbclass
> > +++ b/meta/classes-global/staging.bbclass
> > 
> > @@ -245,8 +245,9 @@ def staging_populate_sysroot_dir(targetsysroot, 
nativesysroot, native, d):
> >                           continue
> >       
> >       staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot,
> >       d)
> > 
> > -    for p in postinsts:
> > -        bb.note("Running postinst {}, output:\n{}".format(p,
> > subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT))) +   
> > bb.warn(sorted(postinsts))
> > +    for p in sorted(postinsts):
> > +        bb.warn("Running postinst {}, output:\n{}".format(p,
> > subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))> 
> >   #
> >   # Manifests here are complicated. The main sysroot area has the unpacked
> >   sstate> 
> > @@ -629,7 +630,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:
> > diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
> > index a58f8287c9..924eeadf9c 100644
> > --- a/meta/classes/useradd.bbclass
> > +++ b/meta/classes/useradd.bbclass
> > @@ -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.
> > 
> > @@ -130,10 +142,19 @@ useradd_sysroot () {
> > 
> >   		exit 0
> >   	
> >   	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')}"
> > + 	# Add groups and users defined for all recipe packages
> > +	if test "x$1" = "xgroup"; then
> > +		GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
> > +	fi
> > +	if test "x$1" = "xuser"; then
> > +		USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
> > +	fi
> > +	if test "x$1" = "xgroupmems"; then
> > +		GROUPMEMS_PARAM="${@get_all_cmd_params(d, 
'groupmems')}"
> > +	fi
> > +	if 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 +169,26 @@ 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(f"{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 +            scriptfile =
> > d.expand("${RECIPE_SYSROOT}${bindir}/"
> > f"postinst-useradd-{sort_prefix}{type}" "-${PN}") +           
> > bb.build.exec_func(f"{type}add_sysroot", d)
> > +        elif task == "populate_sysroot":
> > +            # Used when installed in dependent task sysroots
> > +            scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/"
> > f"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\n")
> > +                bb.data.emit_func(f"{type}add_sysroot", script, d)
> > +                script.write(f"{type}add_sysroot\n")
> > +            os.chmod(scriptfile, 0o755)
> > 
> >   }
> >   
> >   do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}"

BR
Piotr
diff mbox series

Patch

diff --git a/meta/classes-global/staging.bbclass b/meta/classes-global/staging.bbclass
index ab3e1d71b5..6c21510377 100644
--- a/meta/classes-global/staging.bbclass
+++ b/meta/classes-global/staging.bbclass
@@ -245,8 +245,9 @@  def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
                         continue
 
     staging_processfixme(fixme, targetdir, targetsysroot, nativesysroot, d)
-    for p in postinsts:
-        bb.note("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
+    bb.warn(sorted(postinsts))
+    for p in sorted(postinsts):
+        bb.warn("Running postinst {}, output:\n{}".format(p, subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)))
 
 #
 # Manifests here are complicated. The main sysroot area has the unpacked sstate
@@ -629,7 +630,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:
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index a58f8287c9..924eeadf9c 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -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.
@@ -130,10 +142,19 @@  useradd_sysroot () {
 		exit 0
 	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')}"
+ 	# Add groups and users defined for all recipe packages
+	if test "x$1" = "xgroup"; then
+		GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
+	fi
+	if test "x$1" = "xuser"; then
+		USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
+	fi
+	if test "x$1" = "xgroupmems"; then
+		GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
+	fi
+	if 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 +169,26 @@  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(f"{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
+            scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/" f"postinst-useradd-{sort_prefix}{type}" "-${PN}")
+            bb.build.exec_func(f"{type}add_sysroot", d)
+        elif task == "populate_sysroot":
+            # Used when installed in dependent task sysroots
+            scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/" f"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\n")
+                bb.data.emit_func(f"{type}add_sysroot", script, d)
+                script.write(f"{type}add_sysroot\n")
+            os.chmod(scriptfile, 0o755)
 }
 
 do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}"