<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>13904</bug_id>
          
          <creation_ts>2020-05-18 21:10:53 +0000</creation_ts>
          <short_desc>do_prepare_recipe_sysroot: postinst-useradd-* does not run in order of dependency and sometimes fails</short_desc>
          <delta_ts>2024-03-12 14:01:23 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>oe-core other</component>
          <version>2.7.4</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>5.0 M3</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jackie Huang">jackie.huang</reporter>
          <assigned_to name="Eilís Ní Fhlannagáin">pidge</assigned_to>
          <cc>ernstp</cc>
    
    <cc>frederic.martinsons</cc>
    
    <cc>louis.rannou</cc>
    
    <cc>ludovic.jozeau+yocto-bug</cc>
    
    <cc>Martin.Jansa</cc>
    
    <cc>p.lobacz</cc>
    
    <cc>pidge</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>steve</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>87238</commentid>
    <comment_count>0</comment_count>
    <who name="Jackie Huang">jackie.huang</who>
    <bug_when>2020-05-18 21:10:53 +0000</bug_when>
    <thetext>This is found in &quot;warrior&quot;, but I think it may also exists in later releases.

Observed error:
=====================
ERROR: stx-metal-1.0.0-r0 do_prepare_recipe_sysroot: Error executing a python function in exec_python_func() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: &apos;exec_python_func() autogenerated&apos;, lineno: 2, function: &lt;module&gt;
     0001:
 *** 0002:extend_recipe_sysroot(d)
     0003:
File: &apos;/ws-stx-i64_20200518/src_layers/poky/meta/classes/staging.bbclass&apos;, lineno: 566, function: extend_recipe_sysroot
     0562:    for f in fixme:
     0563:        staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
     0564:
     0565:    for p in postinsts:
 *** 0566:        subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
     0567:
     0568:    for dep in manifests:
     0569:        c = setscenedeps[dep][0]
     0570:        os.symlink(manifests[dep], depdir + &quot;/&quot; + c + &quot;.complete&quot;)
File: &apos;/usr/lib/python3.6/subprocess.py&apos;, lineno: 356, function: check_output
     0352:        # empty string. That is maintained here for backwards compatibility.
     0353:        kwargs[&apos;input&apos;] = &apos;&apos; if kwargs.get(&apos;universal_newlines&apos;, False) else b&apos;&apos;
     0354:
     0355:    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
 *** 0356:               **kwargs).stdout
     0357:
     0358:
     0359:class CompletedProcess(object):
     0360:    &quot;&quot;&quot;A process that has finished running.
File: &apos;/usr/lib/python3.6/subprocess.py&apos;, lineno: 438, function: run
     0434:            raise
     0435:        retcode = process.poll()
     0436:        if check and retcode:
     0437:            raise CalledProcessError(retcode, process.args,
 *** 0438:                                     output=stdout, stderr=stderr)
     0439:    return CompletedProcess(process.args, retcode, stdout, stderr)
     0440:
     0441:
     0442:def list2cmdline(seq):
Exception: subprocess.CalledProcessError: Command &apos;/ws-stx-i64_20200518/prj_stx/tmp/work/corei7-64-poky-linux/stx-metal/1.0.0-r0/recipe-sysroot/usr/bin/postinst-useradd-fm-mgr&apos; returned non-zero exit status 1.

Subprocess output:
/ws-stx-i64_20200518/prj_stx/tmp/work/corei7-64-poky-linux/stx-metal/1.0.0-r0/recipe-sysroot-native/usr/sbin/useradd
Running groupadd commands...
NOTE: fm-mgr: Performing groupadd with [--root /ws-stx-i64_20200518/prj_stx/tmp/work/corei7-64-poky-linux/stx-metal/1.0.0-r0/recipe-sysroot -r fm]
NOTE: fm-mgr: group fm already exists, not re-creating it
Running useradd commands...
NOTE: fm-mgr: Performing useradd with [--root /ws-stx-i64_20200518/prj_stx/tmp/work/corei7-64-poky-linux/stx-metal/1.0.0-r0/recipe-sysroot -r -g fm -G snmpd -d /var/lib/fm -s /sbin/nologin -c &apos;fm-mgr&apos; fm]
useradd: group &apos;snmpd&apos; does not exist
ERROR: fm-mgr: useradd command did not succeed.



How to reproduce:
=====================
I need add user/group &quot;fm&quot; in my recipe fm-mgr and user/group &quot;snmpd&quot; in recipe net-snmp,
and user &quot;fm&quot; needs to be added in group &quot;snmpd&quot;, so what I did includes:

1. Add user/group in recipe net-snmp:

inherit useradd

USERADD_PACKAGES = &quot;net-snmp-server-snmpd&quot;
USERADD_PARAM_net-snmp-server-snmpd = &quot;-r -g snmpd -d /usr/share/snmp -s /sbin/nologin -c &apos;net-snmp&apos; snmpd&quot;
GROUPADD_PARAM_net-snmp-server-snmpd = &quot;-r snmpd&quot;

2. Add user/group in recipe fm-mgr, and add RDEPENDS on &quot;net-snmp-server-snmpd&quot; since &quot;-G snmpd&quot; is used in useradd parameter:

inherit useradd

USERADD_PACKAGES = &quot;fm-mgr&quot;
USERADD_PARAM_fm-mgr = &quot;-r -g fm -G snmpd -d /var/lib/fm -s /sbin/nologin -c &apos;fm-mgr&apos; fm&quot;
GROUPADD_PARAM_fm-mgr = &quot;-r fm&quot;

RDEPENDS_fm-mgr += &quot;net-snmp-server-snmpd&quot;


This always work fine in do_rootfs since the dependency ensure the postinst script of &quot;net-snmp-server-snmpd&quot; is run before the one of &quot;fm-mgr&quot;, but in do_prepare_recipe_sysroot of recipe that depends on fm-mgr(e.g. stx-metal in this case), postinst-useradd-net-snmp and postinst-useradd-fm-mgr do not run in the order that respect the dependency, so it fails when postinst-useradd-fm-mgr is run before postinst-useradd-net-snmp.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87283</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2020-05-21 07:37:14 +0000</bug_when>
    <thetext>Are able to reproduce this on the master branch?
There may be similar useradd bugs in bugzilla already such as perhaps #13279 but we don&apos;t have time to check during triage.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87284</commentid>
    <comment_count>2</comment_count>
    <who name="Jackie Huang">jackie.huang</who>
    <bug_when>2020-05-21 07:40:40 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Are able to reproduce this on the master branch?
&gt; There may be similar useradd bugs in bugzilla already such as perhaps #13279
&gt; but we don&apos;t have time to check during triage.

Not sure since I haven&apos;t had time to try on the master branch yet</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87540</commentid>
    <comment_count>3</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2020-06-22 17:49:18 +0000</bug_when>
    <thetext>Jackie, Are you able to work on this defect for M2 or early M3?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87541</commentid>
    <comment_count>4</comment_count>
    <who name="Jackie Huang">jackie.huang</who>
    <bug_when>2020-06-22 17:56:59 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; Jackie, Are you able to work on this defect for M2 or early M3?

I&apos;m afraid not, so it&apos;s better to have someone else to work on this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88364</commentid>
    <comment_count>5</comment_count>
    <who name="Martin Jansa">Martin.Jansa</who>
    <bug_when>2020-10-10 06:49:52 +0000</bug_when>
    <thetext>I have seen similar (if not the same) issue in dunfell based build and added test recipe for it here:

https://patchwork.openembedded.org/series/26477/
https://lists.openembedded.org/g/openembedded-core/message/143163

But here it happens very rarely and I wasn&apos;t able to reliably reproduce it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88535</commentid>
    <comment_count>6</comment_count>
    <who name="Ernst Persson">ernstp</who>
    <bug_when>2020-11-02 03:52:06 +0000</bug_when>
    <thetext>It seems to happen once every month or so for me too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90478</commentid>
    <comment_count>7</comment_count>
    <who name="Ernst Persson">ernstp</who>
    <bug_when>2021-05-25 12:55:39 +0000</bug_when>
    <thetext>This is the only random error I&apos;m seeing regularly (but not that often) in Yocto right now.

Is it related to having useradd-staticids ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92862</commentid>
    <comment_count>8</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2022-03-24 16:02:56 +0000</bug_when>
    <thetext>Is anyone still seeing this bug? Sakib have you tested this recently?

Is this more likely to happen with or without sstate-cache ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92870</commentid>
    <comment_count>9</comment_count>
    <who name="Ernst Persson">ernstp</who>
    <bug_when>2022-03-25 08:56:21 +0000</bug_when>
    <thetext>This is happening to me every other week or so on Dunfell still. I don&apos;t have a good way to reproduce it unfortunately and not building on master.
I think you need sstate-cache to reproduce this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93298</commentid>
    <comment_count>10</comment_count>
    <who name="Ernst Persson">ernstp</who>
    <bug_when>2022-05-23 06:46:11 +0000</bug_when>
    <thetext>I&apos;ve now worked around this by adding extra GROUPADD on depended on groups in the dependant recipe. I can do this since I have staticids. The workaround finally gets rid of the intermittent errors and seems very reliable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95213</commentid>
    <comment_count>11</comment_count>
    <who name="Piotr Łobacz">p.lobacz</who>
    <bug_when>2023-03-29 15:22:25 +0000</bug_when>
    <thetext>Hi all I have exactly the same issue which I have described here https://bugzilla.yoctoproject.org/show_bug.cgi?id=15084 and yes I&apos;m using sstate_cache</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95215</commentid>
    <comment_count>12</comment_count>
    <who name="Piotr Łobacz">p.lobacz</who>
    <bug_when>2023-03-30 07:44:24 +0000</bug_when>
    <thetext>(In reply to Ernst Sjöstrand from comment #10)
&gt; I&apos;ve now worked around this by adding extra GROUPADD on depended on groups
&gt; in the dependant recipe. I can do this since I have staticids. The
&gt; workaround finally gets rid of the intermittent errors and seems very
&gt; reliable.

I have workaround this exactly the same and it works but it is ugly :P BTW. Thx Ernst</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95245</commentid>
    <comment_count>13</comment_count>
    <who name="Piotr Łobacz">p.lobacz</who>
    <bug_when>2023-03-30 19:10:35 +0000</bug_when>
    <thetext>I think I have found the root cause of the issue. Namely there is this base-passwd recipe and in inside it there is this bash script creation:

basepasswd_sysroot_postinst() {
#!/bin/sh

# 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
done

# Run any useradd postinsts
for script in ${STAGING_DIR_TARGET}${bindir}/postinst-useradd-*; do
        echo \$script
        if [ -f \$script ]; then
                \$script
        fi
done
}

which is running all postinst-useradd-* scripts. Now I haven&apos;t verified it yet but I have suspicions that these scripts are launched without an order. Why do I think this way? Because when I had the error that user is missing, a quick workaround for this was just to add missing groups and user to recipe-sysroot/etc/passwd and recipe-sysroot/etc/group files. Another thing is that the same code for user and group add was working for me from recipe which was in alphabetic order and in non-alphabetic it was not... This is still something which I need to confirm.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95251</commentid>
    <comment_count>14</comment_count>
    <who name="Piotr Łobacz">p.lobacz</who>
    <bug_when>2023-03-31 08:58:07 +0000</bug_when>
    <thetext>OK I have made a verification with outputting the status of all the post-inst scripts which are being run and it has turned out that the order of calling them is needed, otherwise an ERROR is occurring e.g.:

/work/build/tmp-glibc/work/core2-64-WelotecGmbH-linux/aziotctl/1.4.3.AUTOINC+cfa39b58ec-r0/recipe-sysroot-native/usr/sbin/useradd
Running groupadd commands...
NOTE: iotedge: Performing groupadd with [--root /work/build/tmp-glibc/work/core2-64-WelotecGmbH-linux/aziotctl/1.4.3.AUTOINC+cfa39b58ec-r0/recipe-sysroot --gid 15580 --system iotedge]
Running useradd commands...
NOTE: iotedge: Performing useradd with [--root /work/build/tmp-glibc/work/core2-64-WelotecGmbH-linux/aziotctl/1.4.3.AUTOINC+cfa39b58ec-r0/recipe-sysroot --comment &apos;iotedge user&apos; --home-dir /var/lib/aziot/edged --gid 15580 --groups docker,systemd-journal,aziotcs,aziotks,aziottpm,aziotid --system --shell /sbin/nologin --uid 15580 iotedge]
ERROR: iotedge: useradd command did not succeed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95461</commentid>
    <comment_count>15</comment_count>
    <who name="Frédéric Martinsons">frederic.martinsons</who>
    <bug_when>2023-04-26 15:22:58 +0000</bug_when>
    <thetext>Hello, 

I came across the exact same issue on dunfell (oe-core: 9aefb4e46cf4fbf14b46f9adaf3771854553e7f3)

It is just to add another acknowledgement to the issue (I have no fix to suggest) and mention that the workaround &quot;adding extra group in GROUPADD&quot; do the job (at least it seems so, since the problem is pretty random)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95821</commentid>
    <comment_count>16</comment_count>
    <who name="Louis Rannou">louis.rannou</who>
    <bug_when>2023-06-23 13:50:10 +0000</bug_when>
    <thetext>Hello,

If you also add :
  DEPENDS += &quot;net-snmp&quot;
or
  DEPENDS:append = &quot; net-snmp &quot;
the issue is not raised.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96622</commentid>
    <comment_count>17</comment_count>
    <who name="Martin Jansa">Martin.Jansa</who>
    <bug_when>2023-10-05 14:47:21 +0000</bug_when>
    <thetext>https://bugzilla.yoctoproject.org/show_bug.cgi?id=13419 seems to be related</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96630</commentid>
    <comment_count>18</comment_count>
    <who name="Louis Rannou">louis.rannou</who>
    <bug_when>2023-10-05 15:14:05 +0000</bug_when>
    <thetext>In my opinion, there are three options:

1. the recipe should specify the dependency (with DEPENDS) to the recipe supposed to create the group
2. useradd tasks should depend on runtime dependencies
3. the recipe should add all required groups to GROUPADD_PARAM

1 and 3 are only documentation but 3 might produce some warning.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96631</commentid>
    <comment_count>19</comment_count>
    <who name="Piotr Łobacz">p.lobacz</who>
    <bug_when>2023-10-05 16:15:35 +0000</bug_when>
    <thetext>Actually, we already have a solution to this problem https://bugzilla.yoctoproject.org/show_bug.cgi?id=15084 but Jan needs to make some slight modifications for this patch which he has not done yet...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96632</commentid>
    <comment_count>20</comment_count>
    <who name="Piotr Łobacz">p.lobacz</who>
    <bug_when>2023-10-05 16:16:20 +0000</bug_when>
    <thetext>(In reply to Piotr Łobacz from comment #19)
&gt; Actually, we already have a solution to this problem
&gt; https://bugzilla.yoctoproject.org/show_bug.cgi?id=15084 but Jan needs to
&gt; make some slight modifications for this patch which he has not done yet...

But please you can test it and check if it works for you as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98460</commentid>
    <comment_count>21</comment_count>
    <who name="Eilís Ní Fhlannagáin">pidge</who>
    <bug_when>2024-03-12 13:52:38 +0000</bug_when>
    <thetext>Fixed at https://git.yoctoproject.org/poky/commit/?id=f6daeba2e97e47550e959fb85d4639ef81d268e7</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98462</commentid>
    <comment_count>22</comment_count>
    <who name="Ernst Persson">ernstp</who>
    <bug_when>2024-03-12 13:56:19 +0000</bug_when>
    <thetext>Easy to backport?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98463</commentid>
    <comment_count>23</comment_count>
    <who name="Steve Sakoman">steve</who>
    <bug_when>2024-03-12 14:01:23 +0000</bug_when>
    <thetext>No idea whether it would be easy or not for any of the stable releases, but please give it a try and submit to the list if you are successful!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>