<?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>10264</bug_id>
          
          <creation_ts>2016-09-13 01:55:00 +0000</creation_ts>
          <short_desc>On-target postinstall failure results in a wrong state of an rpm package</short_desc>
          <delta_ts>2016-09-30 02:55:27 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>11</classification_id>
          <classification>Runtime</classification>
          <product>General Runtime</product>
          <component>General Runtime</component>
          <version>2.2</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>NOTABUG</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.2 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Chen Qi">Qi.Chen</reporter>
          <assigned_to name="Stephano Cetola">stephano</assigned_to>
          <cc>anibal.limon</cc>
    
    <cc>leonardo.sandoval.gonzalez</cc>
    
    <cc>liezhi.yang</cc>
    
    <cc>markus.lehtonen</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>66068</commentid>
    <comment_count>0</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2016-09-13 01:55:00 +0000</bug_when>
    <thetext>If we install an rpm package on target and its postinstall script fails to run successfully. The files of the rpm package are installed on target but the rpm package is not considered installed.

Please see the console output below for an example.

root@qemux86-64:~# rpm -q pulseaudio-server
pulseaudio-server-9.0-r0.core2_64
root@qemux86-64:~# rpm -e pulseaudio-server
Failed to connect to bus: No such file or directory
Removed /etc/systemd/user/sockets.target.wants/pulseaudio.socket.
Removed /etc/systemd/user/default.target.wants/pulseaudio.service.
root@qemux86-64:~# rpm -q pulseaudio-server
package pulseaudio-server is not installed
root@qemux86-64:~# rpm -i pulseaudio-server-9.0-r0.core2_64.rpm 
Running groupadd commands...
NOTE: pulseaudio: Performing groupadd with [ pulse]
NOTE: pulseaudio: group pulse already exists, not re-creating it
Running useradd commands...
NOTE: pulseaudio: Performing useradd with [ --system --home /var/run/pulse                               --no-create-home --shell /bin/false                               --groups audio,pulse --gid pulse pulse]
NOTE: pulseaudio: user pulse already exists, not re-creating it
Created symlink /etc/systemd/user/default.target.wants/pulseaudio.service → /usr/lib/systemd/user/pulseaudio.service.
Created symlink /etc/systemd/user/sockets.target.wants/pulseaudio.socket → /usr/lib/systemd/user/pulseaudio.socket.
Failed to connect to bus: No such file or directory
error: %post(pulseaudio-server-9.0-r0.core2_64) scriptlet failed, exit status 1
root@qemux86-64:~# echo $?
1
root@qemux86-64:~# rpm -q pulseaudio-server
package pulseaudio-server is not installed
root@qemux86-64:~# ls /usr/lib/systemd/user/pulseaudio.s*
/usr/lib/systemd/user/pulseaudio.service  /usr/lib/systemd/user/pulseaudio.socket</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66660</commentid>
    <comment_count>1</comment_count>
    <who name="Stephano Cetola">stephano</who>
    <bug_when>2016-09-27 23:25:49 +0000</bug_when>
    <thetext>I can&apos;t seem to reproduce this error. What does your image install look like? 

I&apos;ve got systemd and pulseaudio-server running and here&apos;s my output:

root@qemux86-64:~# rpm -e pulseaudio-server
root@qemux86-64:~# rpm -q pulseaudio-server
package pulseaudio-server is not installed
root@qemux86-64:~# rpm -i pulseaudio-server-9.0-r0.0.core2_64.rpm 
Running groupadd commands...
NOTE: pulseaudio: Performing groupadd with [ pulse]
NOTE: pulseaudio: group pulse already exists, not re-creating it
Running useradd commands...
NOTE: pulseaudio: Performing useradd with [ --system --home /var/run/pulse                               --no-create-home --shell /bin/false                               --groups audio,pulse --gid pulse pulse]
NOTE: pulseaudio: user pulse already exists, not re-creating it
root@qemux86-64:~# echo $?
0
root@qemux86-64:~# rpm -q pulseaudio-server
pulseaudio-server-9.0-r0.0.core2_64</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66709</commentid>
    <comment_count>2</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2016-09-29 03:30:13 +0000</bug_when>
    <thetext>You need to make the postinstall fail deliberately.
You can do modifications like below.


diff --git a/meta/recipes-multimedia/pulseaudio/pulseaudio.inc b/meta/recipes-multimedia/pulseaudio/pulseaudio.inc
index 7e54ad4..e8ba040 100644
--- a/meta/recipes-multimedia/pulseaudio/pulseaudio.inc
+++ b/meta/recipes-multimedia/pulseaudio/pulseaudio.inc
@@ -145,6 +145,9 @@ pkg_postinst_${PN}-server() {
         if [ -z &quot;$D&quot; ] &amp;&amp; [ -e ${sysconfdir}/init.d/populate-volatile.sh ] ; then
             ${sysconfdir}/init.d/populate-volatile.sh update
         fi
+       if [ -z &quot;$D&quot; ]; then
+           exit 1
+       fi
 }


And below are the results.

qemux86-64 login: root
root@qemux86-64:~# rpm -q pulseaudio-server
pulseaudio-server-9.0-r0.core2_64
root@qemux86-64:~# rpm -e pulseaudio-server
root@qemux86-64:~# ls
pulseaudio-server-9.0-r0.core2_64.rpm
root@qemux86-64:~# ls /usr/lib/systemd/user
basic.target          busnames.target       exit.target           printer.target        smartcard.target      sound.target          timers.target
bluetooth.target      default.target        paths.target          shutdown.target       sockets.target        systemd-exit.service
root@qemux86-64:~# rpm -i pulseaudio-server-9.0-r0.core2_64.rpm 
Running groupadd commands...
NOTE: pulseaudio: Performing groupadd with [ pulse]
NOTE: pulseaudio: group pulse already exists, not re-creating it
Running useradd commands...
NOTE: pulseaudio: Performing useradd with [ --system --home /var/run/pulse                               --no-create-home --shell /bin/false                               --groups audio,pulse --gid pulse pulse]
NOTE: pulseaudio: user pulse already exists, not re-creating it
error: %post(pulseaudio-server-9.0-r0.core2_64) scriptlet failed, exit status 1
root@qemux86-64:~# echo $?
1
root@qemux86-64:~# ls /usr/lib/systemd/user
basic.target          busnames.target       exit.target           printer.target        pulseaudio.socket     smartcard.target      sound.target          timers.target
bluetooth.target      default.target        paths.target          pulseaudio.service    shutdown.target       sockets.target        systemd-exit.service
root@qemux86-64:~# ls /usr/lib/systemd/user/pulseaudio.service 
/usr/lib/systemd/user/pulseaudio.service
root@qemux86-64:~# rpm -q pulseaudio-server
package pulseaudio-server is not installed
root@qemux86-64:~#</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66738</commentid>
    <comment_count>3</comment_count>
    <who name="Stephano Cetola">stephano</who>
    <bug_when>2016-09-30 02:00:10 +0000</bug_when>
    <thetext>As far as I can tell, this is the way that RPM is designed to work. Per Jeff Johnson:


[T]he %post script needs to be written &quot;robustly&quot; so that the exit code is always 0. If you need/want to tell whether some specific operation &quot;worked&quot;, then write a test after rpm has run for that specific operation. Another approach would be to have the %post script register its state somewhere in /var so that you can easily test whether the script &quot;worked&quot; or not.
...
I&apos;d have to know more about what is implied by a %post success/failure in order to suggest some other approach.


In Yocto, we allow the postinstall return code to be != 0 at build time so that those postinstall scripts can be re-run on the host, as documented here:

http://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#new-recipe-post-installation-scripts

However, this does not seem to be the case in RPM. Looking at the RPM code, when the package state machine encounters a non-zero exit status, it simply exits. No cleanup is attempted.

What are you trying to accomplish here by having a postinstall script fail on the host? We may be able to add a feature to accommodate your goals, but it looks like RPM postinstall scripts are not an option.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66739</commentid>
    <comment_count>4</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2016-09-30 02:18:00 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; As far as I can tell, this is the way that RPM is designed to work. Per Jeff
&gt; Johnson:
&gt; 
&gt; 
&gt; [T]he %post script needs to be written &quot;robustly&quot; so that the exit code is
&gt; always 0. If you need/want to tell whether some specific operation &quot;worked&quot;,
&gt; then write a test after rpm has run for that specific operation. Another
&gt; approach would be to have the %post script register its state somewhere in
&gt; /var so that you can easily test whether the script &quot;worked&quot; or not.
&gt; ...
&gt; I&apos;d have to know more about what is implied by a %post success/failure in
&gt; order to suggest some other approach.
&gt; 
&gt; 
&gt; In Yocto, we allow the postinstall return code to be != 0 at build time so
&gt; that those postinstall scripts can be re-run on the host, as documented here:
&gt; 
&gt; http://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#new-
&gt; recipe-post-installation-scripts
&gt; 
&gt; However, this does not seem to be the case in RPM. Looking at the RPM code,
&gt; when the package state machine encounters a non-zero exit status, it simply
&gt; exits. No cleanup is attempted.
&gt; 
&gt; What are you trying to accomplish here by having a postinstall script fail
&gt; on the host? We may be able to add a feature to accommodate your goals, but
&gt; it looks like RPM postinstall scripts are not an option.

Thanks for you investigation and information. I didn&apos;t know that it&apos;s deliberately designed to behave like that.

I&apos;m trying to accomplish something by making a postinstall script fail. I brought up this problem because I think some postinstall script might fail, resulting in a broken state of an rpm package.

If a non-zero exit status for postinstall script of an rpm package is not allowed, and we are going to change this behaviour, how about we do some documentation and just close this bug?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66740</commentid>
    <comment_count>5</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2016-09-30 02:20:11 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; As far as I can tell, this is the way that RPM is designed to work. Per Jeff
&gt; Johnson:
&gt; 
&gt; 
&gt; [T]he %post script needs to be written &quot;robustly&quot; so that the exit code is
&gt; always 0. If you need/want to tell whether some specific operation &quot;worked&quot;,
&gt; then write a test after rpm has run for that specific operation. Another
&gt; approach would be to have the %post script register its state somewhere in
&gt; /var so that you can easily test whether the script &quot;worked&quot; or not.
&gt; ...
&gt; I&apos;d have to know more about what is implied by a %post success/failure in
&gt; order to suggest some other approach.
&gt; 
&gt; 
&gt; In Yocto, we allow the postinstall return code to be != 0 at build time so
&gt; that those postinstall scripts can be re-run on the host, as documented here:
&gt; 
&gt; http://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#new-
&gt; recipe-post-installation-scripts
&gt; 
&gt; However, this does not seem to be the case in RPM. Looking at the RPM code,
&gt; when the package state machine encounters a non-zero exit status, it simply
&gt; exits. No cleanup is attempted.
&gt; 
&gt; What are you trying to accomplish here by having a postinstall script fail
&gt; on the host? We may be able to add a feature to accommodate your goals, but
&gt; it looks like RPM postinstall scripts are not an option.

Thanks for you investigation and information. I didn&apos;t know that it&apos;s deliberately designed to behave like that.

I&apos;m not trying to accomplish something by making a postinstall script fail. I brought up this problem because I think some postinstall script might fail, resulting in a broken state of an rpm package.

If a non-zero exit status for postinstall script of an rpm package is not allowed, and we are not going to change this behaviour, how about we do some documentation and just close this bug?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66743</commentid>
    <comment_count>6</comment_count>
    <who name="Stephano Cetola">stephano</who>
    <bug_when>2016-09-30 02:55:27 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #3)
&gt; &gt; As far as I can tell, this is the way that RPM is designed to work. Per Jeff
&gt; &gt; Johnson:
&gt; &gt; 
&gt; &gt; 
&gt; &gt; [T]he %post script needs to be written &quot;robustly&quot; so that the exit code is
&gt; &gt; always 0. If you need/want to tell whether some specific operation &quot;worked&quot;,
&gt; &gt; then write a test after rpm has run for that specific operation. Another
&gt; &gt; approach would be to have the %post script register its state somewhere in
&gt; &gt; /var so that you can easily test whether the script &quot;worked&quot; or not.
&gt; &gt; ...
&gt; &gt; I&apos;d have to know more about what is implied by a %post success/failure in
&gt; &gt; order to suggest some other approach.
&gt; &gt; 
&gt; &gt; 
&gt; &gt; In Yocto, we allow the postinstall return code to be != 0 at build time so
&gt; &gt; that those postinstall scripts can be re-run on the host, as documented here:
&gt; &gt; 
&gt; &gt; http://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#new-
&gt; &gt; recipe-post-installation-scripts
&gt; &gt; 
&gt; &gt; However, this does not seem to be the case in RPM. Looking at the RPM code,
&gt; &gt; when the package state machine encounters a non-zero exit status, it simply
&gt; &gt; exits. No cleanup is attempted.
&gt; &gt; 
&gt; &gt; What are you trying to accomplish here by having a postinstall script fail
&gt; &gt; on the host? We may be able to add a feature to accommodate your goals, but
&gt; &gt; it looks like RPM postinstall scripts are not an option.
&gt; 
&gt; Thanks for you investigation and information. I didn&apos;t know that it&apos;s
&gt; deliberately designed to behave like that.
&gt; 
&gt; I&apos;m not trying to accomplish something by making a postinstall script fail.
&gt; I brought up this problem because I think some postinstall script might
&gt; fail, resulting in a broken state of an rpm package.
&gt; 
&gt; If a non-zero exit status for postinstall script of an rpm package is not
&gt; allowed, and we are not going to change this behaviour, how about we do some
&gt; documentation and just close this bug?

Sounds like a good plan. I added Bug 10351 and CC&apos;d you on it. I will close this bug and work off that one going forward.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>