<?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>13266</bug_id>
          
          <creation_ts>2019-04-04 23:17:13 +0000</creation_ts>
          <short_desc>run-postinst fails to fully execute scripts</short_desc>
          <delta_ts>2019-05-30 15:17:20 +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>unspecified</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>2.7 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alejandro Hernandez">alejandr</reporter>
          <assigned_to name="Alejandro Hernandez">alejandr</assigned_to>
          <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>richard.purdie</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>83455</commentid>
    <comment_count>0</comment_count>
    <who name="Alejandro Hernandez">alejandr</who>
    <bug_when>2019-04-04 23:17:13 +0000</bug_when>
    <thetext>run-postinsts runs a given set of scripts during the first boot of the device,
when one of these scripts prints something to stdout, since stdout is
not available at that time, the script execution immediately returns with
an error (exit_group()), this error causes the script to terminate all threads within the process, causing undesired behavior since the script might still had to execute some other code.

There could be a case where the script to be run performs several commands, e.g. 
script_ran_at_boot:
cmda
cmdb
cmdc

Now, lets say that cmda echoes something to stdout.
stdout does not exist at this point, this is what produces the error and terminates execution (according to strace), hence cmdb and cmdc are never run, (its worth noting that cmda does get executed so if it was a single command, this would not be a big issue).

The reason why we have not seen this before (I believe) is because most or all of the scripts being run, either dont print anything to stdout or are one single command, also, this is only reproducible when debug-tweaks isn&apos;t enabled and since we have it enabled by default, we dont see this error, and that is because the following line in the run-postinsts script uses a file for logging purposes:

eval sh -c $i $append_log

but, the variable $append_log is obtained when sourcing the file:

[ -e #SYSCONFDIR#/default/postinst ] &amp;&amp; . #SYSCONFDIR#/default/postinst

if [ &quot;$POSTINST_LOGGING&quot; = &quot;1&quot; ]; then
	rm -f $LOGFILE
	append_log=&quot;&gt;&gt;$LOGFILE 2&gt;&amp;1&quot;
fi


and we can see that from the class:

https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/rootfs-postcommands.bbclass#n12

postinst_enable_logging () {
  mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
  echo &quot;POSTINST_LOGGING=1&quot; &gt;&gt; ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
  echo &quot;LOGFILE=${POSTINST_LOGFILE}&quot; &gt;&gt; ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
}

We need to be able to make this work even when debug-tweaks isn&apos;t enabled, I believe a single and harmless fix would be to always pass 2&gt;&amp;1 even when POSTINST_LOGGING isn&apos;t enabled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84013</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2019-05-30 15:17:20 +0000</bug_when>
    <thetext>http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=9f1b36f41deb5cc660856f52d74b54053f488d0a</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>