<?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>10478</bug_id>
          
          <creation_ts>2016-10-21 14:19:25 +0000</creation_ts>
          <short_desc>run-postinsts doesn&apos;t update package manager database on target device</short_desc>
          <delta_ts>2016-12-14 21:23:26 +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>devtools / tool chain</component>
          <version>2.1.2</version>
          <rep_platform>Other</rep_platform>
          <op_sys>arm</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>Backport to YP 2.2.1 and 2.1.2</status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.3 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Niko Mauno">niko.mauno</reporter>
          <assigned_to name="Jussi Kukkonen">jku</assigned_to>
          <cc>jose.perez.carranza</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>ross.burton</cc>
          
          <qa_contact name="Juan Ramos">juan.fernandox.ramos.frayle</qa_contact>
          <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>67452</commentid>
    <comment_count>0</comment_count>
    <who name="Niko Mauno">niko.mauno</who>
    <bug_when>2016-10-21 14:19:25 +0000</bug_when>
    <thetext>The /usr/sbin/run-postinsts script, installed by meta/recipes-devtools/run-postinsts/run-postinsts_1.0.bb recipe, does not seem to update target device package manager database when it executes postinst scriptlets from under /etc/*-postinst/ during first boot to pristine root filesystem.

In our use case the rootfs contains an opkg package manager database (under /var/lib/opkg) as well as several &quot;delayed postinst&quot; scriptlets under /etc/ipk-postinsts/ (apparently created by actions in meta/lib/oe/rootfs.py).

If an user then runs &apos;opkg update&apos; and &apos;opkg install somepackage&apos; on the target device, the pending postinst actions (from opkg database&apos;s point of view) are executed again, in addition to &apos;somepackage&apos;&apos;s postinst actions. Ie. this triggers superfluous execution of &quot;delayed postinst&quot; actions (which can involve eg. downing of network interfaces, ssh server, and so on, via update-rc.d calls included in the pending postinst actions).

Following modifications seemed to fix the issue in our opkg use case:

--- a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
+++ b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
@@ -13,6 +13,9 @@ backend_list=&quot;rpm deb ipk&quot;
 
 pm_installed=false
 
+dpkg_statusfile=&quot;#LOCALSTATEDIR#/lib/dpkg/status&quot;
+opkg_statusfile=&quot;#LOCALSTATEDIR#/lib/opkg/status&quot;
+
 for pm in $backend_list; do
        pi_dir=&quot;#SYSCONFDIR#/$pm-postinsts&quot;
 
@@ -20,14 +23,14 @@ for pm in $backend_list; do
 
        case $pm in
                &quot;deb&quot;)
-                       if [ -s &quot;#LOCALSTATEDIR#/lib/dpkg/status&quot; ]; then
+                       if [ -s &quot;$dpkg_statusfile&quot; ]; then
                                pm_installed=true
                                break
                        fi
                        ;;
 
                &quot;ipk&quot;)
-                       if [ -s &quot;/var/lib/opkg/status&quot; ]; then
+                       if [ -s &quot;$opkg_statusfile&quot; ]; then
                                pm_installed=true
                                break
                        fi
@@ -59,7 +62,13 @@ exec_postinst_scriptlets() {
                echo &quot;Running postinst $i...&quot;
                [ &quot;$POSTINST_LOGGING&quot; = &quot;1&quot; ] &amp;&amp; eval echo &quot;Running postinst $i...&quot; $append_log
                if [ -x $i ]; then
-                       eval sh -c $i $append_log
+                       if [ &quot;$pm&quot; = &quot;ipk&quot; -a -s &quot;$opkg_statusfile&quot; ]; then
+                               eval opkg configure $(basename $i | cut -d- -f2-) $append_log
+                       elif [ &quot;$pm&quot; = &quot;deb&quot; -a -s &quot;$dpkg_statusfile&quot; ]; then
+                               eval dpkg --configure $(basename $i | cut -d- -f2-) $append_log
+                       else
+                               eval sh -c $i $append_log
+                       fi
                        rm $i
                else
                        echo &quot;ERROR: postinst $i failed.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67775</commentid>
    <comment_count>1</comment_count>
    <who name="Jussi Kukkonen">jku</who>
    <bug_when>2016-10-31 10:06:23 +0000</bug_when>
    <thetext>(In reply to comment #0)

Hi Niko, 

I&apos;ll do some tests myself but if you can clear the confusion I have that would be great:

* The hard coded path looks like a real bug (but I understood this wasn&apos;t your problem as you mentioned /var/lib/opkg path)

* The exec_postinst_scriplets changes I do not understand: run-postinsts seems to already contain similar functionality even in krogoth (2.1) branch:

| if $pm_installed; then
|         case $pm in
|                 &quot;ipk&quot;)
|                         eval opkg configure $append_log
|                         ;;
| 
|                 &quot;deb&quot;)
|                         eval dpkg --configure -a $append_log
|                         ;;
|         esac
| else
|         exec_postinst_scriptlets
| fi


So exec_postinst_scriplets should only ever get called if $pm_installed is false. It&apos;s entirely possible that there&apos;s a problem with e.g. how we call opkg configure, but I don&apos;t see how the patch could help as the code path modified in the patch can never end up executed when $pm_installed = &quot;true&quot; as far as I can tell...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67783</commentid>
    <comment_count>2</comment_count>
    <who name="Niko Mauno">niko.mauno</who>
    <bug_when>2016-10-31 15:28:39 +0000</bug_when>
    <thetext>Hi Jussi,

Thanks for asking. I hope You will find the following additional details helpful:

 - In our case this problem manifests on a rootfs which was generated by an image recipe which inherits image.bbclass.
 - Before 1st boot occurs, an /etc/ipk-postinsts directory with several &apos;00*-&lt;packagename&gt;&apos; scriptlets exists on the generated rootfs.
 - When 1st boot occurs, during S runlevel /etc/init.d/run-postinsts script is executed, which effectively calls /usr/sbin/run-postinsts
   &lt;http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts?h=krogoth&gt;
    - Line 14 sets pm_installed as &apos;false&apos;
    - Line 17 sets pi_dir as &apos;/etc/ipk-postinsts&apos; (when for-loop has iterated to the 3rd element of backend_list)
    - Line 19 tests for existence of pi_dir, succeeds and breaks the for-loop (this occurs before pm_installed would have been set as &apos;true&apos; on line 31 in the same for-loop)
    - Line 73 if-statement translates as &apos;false&apos;, which leads to the exec_postinst_scriptlets call. 

Also in the patch I provided, I tried to carefully maintain the order of scriptlet execution, as commit message of b2c9e7347acdfd0efe1c3dabb853d609233b61b6 mentions about adding postinst script execution order mindfulness. I checked that in our case calling just &apos;opkg configure&apos; did execute the postinst actions in different order than exec_postinst_scriptlets(), so I decided to rather call &apos;opkg configure &lt;packagename&gt;&apos; one at a time in the existing exec_postinst_scripts() loop to retain the execution order dictated by Yocto rootfs facility.

Furthermore, I tried to keep the effective changes relatively contained, as the &apos;run-postinsts&apos; script looks like it might use a more fundamental rewrite.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67785</commentid>
    <comment_count>3</comment_count>
    <who name="Jussi Kukkonen">jku</who>
    <bug_when>2016-10-31 16:34:18 +0000</bug_when>
    <thetext>Thanks, I had indeed missed the early break in the first for-loop.

I&apos;ll so some tests and talk to Anibal about the postinst execution order and whether we can trust opkg and dpkg to do the right thing on their own ...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67815</commentid>
    <comment_count>4</comment_count>
      <attachid>3516</attachid>
    <who name="Jussi Kukkonen">jku</who>
    <bug_when>2016-11-01 12:08:32 +0000</bug_when>
    <thetext>Created attachment 3516
run-postinsts: Use opkg/dpkg to configure when possible

I think the early break is buggy. The already existing code for package manager configures seems fine to me, it&apos;s just not being used. I&apos;m attaching a patch to modify the behaviour in the first loop -- normally I&apos;d just send it to mailing list but this is somewhat difficult to test (I wish we had some tests for this).

I believe calling opkg or dpkg just once is enough: the package managers do take care of proper dependency chains and _should_ run the configures in a correct order.

Niko, if you have a possibility of testing this, please do. I&apos;ll run some more tests myself and if no problems appear will send the patch to mailing list.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67816</commentid>
    <comment_count>5</comment_count>
    <who name="Niko Mauno">niko.mauno</who>
    <bug_when>2016-11-01 13:30:13 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; Created attachment 3516 [details]
&gt; run-postinsts: Use opkg/dpkg to configure when possible
&gt; 
&gt; I think the early break is buggy. The already existing code for package
&gt; manager configures seems fine to me, it&apos;s just not being used. I&apos;m attaching
&gt; a patch to modify the behaviour in the first loop -- normally I&apos;d just send
&gt; it to mailing list but this is somewhat difficult to test (I wish we had
&gt; some tests for this).
&gt; 
&gt; I believe calling opkg or dpkg just once is enough: the package managers do
&gt; take care of proper dependency chains and _should_ run the configures in a
&gt; correct order.

Being unaware of pkg_postinst_${PN} permutations outside our companys&apos; and Yocto upstreams&apos; meta layers, I thought sticking to the Yocto rootfs facility dictated order would presumably err to the safe side. In my mind as well, the order arbitrated by the actual package manager should be favored. My earlier tests showed already that forcing just single &apos;opkg configure&apos; call instead of exec_postinst_scriptlets() fixed the problem in our case.

&gt; Niko, if you have a possibility of testing this, please do. I&apos;ll run some
&gt; more tests myself and if no problems appear will send the patch to mailing
&gt; list.

I tried the patch you provided and it seems to do the trick in our case, ie. running &apos;opkg configure&apos; after 1st boot to pristine rootfs no longer triggers any pending configure actions. (Please consider including the replacement of &apos;/var&apos; with &apos;#LOCALSTATEDIR#&apos; on line 30 of the original run-postinsts file).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68907</commentid>
    <comment_count>6</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2016-12-07 16:56:30 +0000</bug_when>
    <thetext>Merged in oe-core b645919f173512f9e75aeb26348d60b63dcdc53c.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>3516</attachid>
            <date>2016-11-01 12:08:32 +0000</date>
            <delta_ts>2016-11-01 12:08:32 +0000</delta_ts>
            <desc>run-postinsts: Use opkg/dpkg to configure when possible</desc>
            <filename>0001-run-postinsts-Use-opkg-dpkg-to-configure-when-possib.patch</filename>
            <type>text/plain</type>
            <size>1558</size>
            <attacher name="Jussi Kukkonen">jku</attacher>
            
              <data encoding="base64">RnJvbSAzNzJlNDE3NDJlYjY1MDNlNGIwMzJiZDIxYjViZTk4ZTM4ZmUyYjkwIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBKdXNzaSBLdWtrb25lbiA8anVzc2kua3Vra29uZW5AaW50ZWwu
Y29tPgpEYXRlOiBUdWUsIDEgTm92IDIwMTYgMTE6MzY6MTcgKzAyMDAKU3ViamVjdDogW1BBVENI
XSBydW4tcG9zdGluc3RzOiBVc2Ugb3BrZy9kcGtnIHRvIGNvbmZpZ3VyZSB3aGVuIHBvc3NpYmxl
CgpDdXJyZW50bHkgcnVuLXBvc3RpbnN0cyBzY3JpcHQgaGFzIGNvZGUgdG8gcnVuIHBvc3RpbnN0
IHNjcmlwdHMKdmlhIG9wa2cvZHBrZyBjb25maWd1cmUgYnV0IHRoYXQgY29kZSBpcyBuZXZlciB1
c2VkLiBUaGUgYWR2YW50YWdlCm9mIHVzaW5nIHBhY2thZ2UgbWFuYWdlcnMgaW5zdGVhZCBvZiBq
dXN0IGV4ZWN1dGluZyB0aGUgc2NyaXB0cyBpcwp0byBrZWVwIHRoZSBwYWNrYWdlIG1hbmFnZXIg
REIgdXBkYXRlZC4KCkZpeCB0aGUgc2NyaXB0IHNvIHRoYXQgdGhlIHBhY2thZ2UgbWFuYWdlcnMg
YXJlIHVzZWQgd2hlbiBhcHByb3ByaWF0ZS4KClNpZ25lZC1vZmYtYnk6IEp1c3NpIEt1a2tvbmVu
IDxqdXNzaS5rdWtrb25lb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