<?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>4262</bug_id>
          
          <creation_ts>2013-04-11 16:16:59 +0000</creation_ts>
          <short_desc>Rework implementation of postinst logging</short_desc>
          <delta_ts>2013-08-01 07:23:15 +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>core</component>
          <version>1.4</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>1.5 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Paul Eggleton">bluelightning</reporter>
          <assigned_to name="Chen Qi">Qi.Chen</assigned_to>
          <cc>Martin.Jansa</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>Qi.Chen</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>yi.zhao</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>---</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>31992</commentid>
    <comment_count>0</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2013-04-11 16:16:59 +0000</bug_when>
    <thetext>The postinstall script logging tapping into each postinstall script recipe and depending on the value of debug-tweaks in IMAGE_FEATURES isn&apos;t quite right, and resulted in bug 4246. In 1.5 we need to rework the implementation so the info is gathered in a more appropriate manner.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32371</commentid>
    <comment_count>1</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2013-04-19 02:25:10 +0000</bug_when>
    <thetext>The implementation might be different, but I think the key problem here is under which condition should we enable postinst logging.

&apos;debug-tweaks&apos;, in my point of view, seems to be a good sign.
After all, we usually enable postinst logging for debugging purpose.

//Chen Qi</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32484</commentid>
    <comment_count>2</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2013-04-22 16:54:48 +0000</bug_when>
    <thetext>As far as logging on the host goes, we typically log almost everything, so it should always be logged there. For the target, you may be right, debug-tweaks is probably the preferred way to do this; however the postinstall scripts themselves should not be changed dependent on whether or not debug-tweaks is in IMAGE_FEATURES. Either it should be handled through the package manager, or the scripts should check for the presence of a file/config option within the image which would be set at image post-processing time dependent on whether or not debug-tweaks is in IMAGE_FEATURES.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33074</commentid>
    <comment_count>3</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2013-05-14 03:39:59 +0000</bug_when>
    <thetext>Design

Goal:
1. Enable postinst logging if &apos;debug-tweaks&apos; is in IMAGE_FEATURES
2. Make rpm, opk and dpkg not dependent on IMAGE_FEATURES and POSTLOG

Implementation:
1. The run-postinst scripts will log outputs and errors if /etc/.enable_postinst_logging is present.
2. The log location is always /var/log/postinstall.log. Do not allow configuration, because this is mainly for debugging purpose and /var/log/postinstall.log is a good place. Making it configurable is not necessary.

Proof-of-concept patch
[For rpm package backend, others are similar]
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 2b42e12..fc5e23c 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -175,6 +175,8 @@ MACHINE_POSTPROCESS_COMMAND ?= &quot;&quot;
 ROOTFS_POSTPROCESS_COMMAND_prepend = &quot;run_intercept_scriptlets; &quot;
 # Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is enabled
 ROOTFS_POSTPROCESS_COMMAND += &apos;${@base_contains(&quot;IMAGE_FEATURES&quot;, &quot;debug-tweaks&quot;, &quot;ssh_allow_empty_password; &quot;, &quot;&quot;,d)}&apos;
+# Enable postinst logging if debug-tweaks is enabled
+ROOTFS_POSTPROCESS_COMMAND += &apos;${@base_contains(&quot;IMAGE_FEATURES&quot;, &quot;debug-tweaks&quot;, &quot;postinst_enable_logging; &quot;, &quot;&quot;,d)}&apos;
 
 # some default locales
 IMAGE_LINGUAS ?= &quot;de-de fr-fr en-gb&quot;
@@ -484,6 +486,11 @@ ssh_allow_empty_password () {
        fi
 }
 
+# Enable postinst logging if debug-tweaks is enabled
+postinst_enable_logging () {
+       touch ${IMAGE_ROOTFS}/etc/.enable_postinst_logging
+}
+
 # Turn any symbolic /sbin/init link into a file
 remove_init_link () {
        if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
diff --git a/meta/recipes-devtools/rpm/rpm-postinsts.bb b/meta/recipes-devtools/rpm/rpm-postinsts.bb
index 3d2d05d..ae0e37e 100644
--- a/meta/recipes-devtools/rpm/rpm-postinsts.bb
+++ b/meta/recipes-devtools/rpm/rpm-postinsts.bb
@@ -11,10 +11,6 @@ inherit allarch
 #
 POSTINSTALL_INITPOSITION ?= &quot;98&quot;
 
-POSTLOG ?= &quot;/var/log/postinstall.log&quot;
-REDIRECT_CMD = &quot;${@base_contains(&apos;IMAGE_FEATURES&apos;, &apos;debug-tweaks&apos;, &apos;&gt;&gt;${POSTLOG} 2&gt;&amp;1&apos;, &apos;&apos;, d)}&quot;
-REDIRECT_CMD[vardepsexclude] += &quot;IMAGE_FEATURES POSTLOG&quot;
-
 do_fetch() {
        :
 }
@@ -40,7 +36,12 @@ if [ &quot;x$D&quot; != &quot;x&quot; ] &amp;&amp; [ -f $D/var/lib/rpm/Packages ]; then
 [ -d /etc/rpm-postinsts ] &amp;&amp; for i in `ls /etc/rpm-postinsts/`; do
        i=/etc/rpm-postinsts/$i
        echo &quot;Running postinst $i...&quot;
-       if [ -f $i ] &amp;&amp; $i ${REDIRECT_CMD}; then
+       if [ -x $i ]; then
+               if [ -e /etc/.enable_postinst_logging ]; then
+                       $i &gt;/var/log/postinstall.log 2&amp;&gt;1
+               else
+                       $i
+               fi
                rm $i
        else
                echo &quot;ERROR: postinst $i failed.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33322</commentid>
    <comment_count>4</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2013-05-28 05:31:56 +0000</bug_when>
    <thetext>merged into poky/master: f7b639e527a65f9ce77aef07651ac5ec1e094e52</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34776</commentid>
    <comment_count>5</comment_count>
    <who name="Yi Zhao">yi.zhao</who>
    <bug_when>2013-07-23 08:48:17 +0000</bug_when>
    <thetext>Verified with master/31e6eee860b5f9f4ac9ef0889bcff5648de6e3f9</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35250</commentid>
    <comment_count>6</comment_count>
    <who name="Yi Zhao">yi.zhao</who>
    <bug_when>2013-08-01 07:23:15 +0000</bug_when>
    <thetext>Test case:

Steps:
1. Add the following lines to a .bb file. For expample, man_1.6g.bb:

pkg_postinst_${PN} () {
       #!/bin/sh -e
       if [ x&quot;$D&quot; = &quot;x&quot; ]; then
       echo &quot;List directory to check the output log&quot;
       ls /
       echo &quot;List nonexist directory to check the stderr redirection log&quot;
       ls /nonexist
       else
       exit 1
       fi
}

2. Add the following line in conf/local.conf to make sure this package is installed in the rootfs:

CORE_IMAGE_EXTRA_INSTALL += &quot;man&quot;

Make sure the feature &quot;debug-tweaks&quot; is added in conf/local.conf

3. Build a image.

4. Boot up the image and check the /var/log/postinstall.log

Expected results:
The /var/log/postinstall.log should exist in the first boot. The content of this log is like below:

Running postinst /etc/rpm-postinsts/man...
List directory to check the output log
bin
boot
dev
etc
home
lib
lost+found
media
mnt
proc
run
sbin
sys
tmp
usr
var
List nonexist directory to check the stderr redirection log
ls: /nonexist: No such file or directory</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>