packaging: rpm scriptlet cleanup, handle -p /sbin/ldconfig 44/251144/2
authorDariusz Michaluk <d.michaluk@samsung.com>
Fri, 8 Jan 2021 13:52:19 +0000 (14:52 +0100)
committerDariusz Michaluk <d.michaluk@samsung.com>
Fri, 8 Jan 2021 15:55:59 +0000 (16:55 +0100)
commitb24b99857d61e92f680768291d7c0836461d97db
tree58245fbc162557253f387947410f74279d6fd351
parentf8f77aa1a76f0c308ece4a88da6af7125508f466
packaging: rpm scriptlet cleanup, handle -p /sbin/ldconfig

The RPM documention indicates that during an rpm install or erase, the
script(lets): %post, %preun, and %postun (and %pre, %build, %install,
etc.) are copied to a temp file, and then the temp file is run as a
(/bin/sh or bash) script.

Unfortunately the documentation is not clear about how rpmbuild and/or
rpm determine where the end of any scriptlet is when it is copied to
the file.

Most things in the key-manager.spec work correctly as is. These are the
%preun, %post, and %postun scriptlets that are "closed" by a following
%preun, %post, and %postun, or potentially another scriptlet, e.g.
%file.

The ones that don't work correctly (only one actually) are those where
there is a comment in the spec file before it is closed by another
scriptlet. Further complicating things is that the type of scriptlet
affects what rpm does and what `rpm -qp --scripts ...` shows.

The specific one that didn't work was the
"postun -n libkey-manager-client -p /sbin/ldconfig" scriptlet.
It is followed by a comment before being "closed" by the %files section (or
scriptlet). It can be written two ways:
"%postun -n libkey-manager-client\n/sbin/ldconfig"
or "%postun -n libkey-manager-client -p /sbin/ldconfig".
Either way it's written, `rpm -qp --scripts libkey-manager-client...`
will include the comment lines between the %postun line and the following %files line.

But the way rpm executes these depends on how they're written. If
written as "%postun -n libkey-manager-client\n/sbin/ldconfig" rpm will simply run
/sbin/ldconfig with no command line options, i.e.
  execve ("/sbin/ldconfig", [ "/sbin/ldconfig" ], [ ]);

But when written as "%postun -n libkey-manager-client -p /sbin/ldconfig",
it will copy the comment lines to a temp file, and pass the temp file name and "1"
 as (command line) parameters, i.e.
  execve ("/sbin/ldconfig", [ "/sbin/ldconfig", "/tmp/tmpXXXXXX", "1" ],
          [ ]);

Which results in ldconfig exiting with an error. (Remember, both ways show
the comment in `rpm -qp --scripts ...`)

Problematic comment line was removed and whole file comments style was adjusted.
Additionally some cleanup was performed.

Change-Id: I966f0930d7a7b46b401f399aaf2e5c748edc0a1f
packaging/key-manager.spec