Bug 1577161

Summary: dubious shell logic in macros.pesign, kernel rpmbuild fails for non-bash /bin/sh
Product: Red Hat Enterprise Linux 7 Reporter: Petr Benes <petrben>
Component: pesignAssignee: Peter Jones <pjones>
Status: CLOSED WONTFIX QA Contact: Erico Nunes <ernunes>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.7-AltCC: petrben
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-02-15 07:38:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Petr Benes 2018-05-11 11:16:07 UTC
When testing whether kernel could be build from its SRPM if one sets
/bin/sh to ksh I've found that it doesn't work.

The process ends up with:

+ mkdir -p
/home/builder/rpmbuild/BUILDROOT/kernel-uek-4.14.32-1.el7uek.aarch64/usr/lib/d
ebug/boot
+ mkdir -p
/home/builder/rpmbuild/BUILDROOT/kernel-uek-4.14.32-1.el7uek.aarch64/usr/lib/d
ebug/boot
+ mkdir -p
/home/builder/rpmbuild/BUILDROOT/kernel-uek-4.14.32-1.el7uek.aarch64/boot
+ install -m 644 .config
/home/builder/rpmbuild/BUILDROOT/kernel-uek-4.14.32-1.el7uek.aarch64/boot/conf
ig-4.14.32-1.el7uek.aarch64.debug
+ install -m 644 System.map
/home/builder/rpmbuild/BUILDROOT/kernel-uek-4.14.32-1.el7uek.aarch64/boot/Syst
em.map-4.14.32-1.el7uek.aarch64.debug
+ touch
/home/builder/rpmbuild/BUILDROOT/kernel-uek-4.14.32-1.el7uek.aarch64/boot/init
ramfs-4.14.32-1.el7uek.aarch64.debug.img
+ [ -f arch/arm64/boot/zImage.stub ]
+ [ -x /usr/bin/pesign ]
+ [ aarch64 '==' x86_64 -o aarch64 '==' aarch64 ]
+ [ 07 -ge 7 -a -f /usr/bin/rpm-sign ]
+ [ -S /var/run/pesign/socket ]
+ /usr/bin/pesign -c 'Oracle Linux Test Certificate' -i arch/arm64/boot/Image
-o arch/arm64/boot/Image.signed -s
+ [ ! -s -o arch/arm64/boot/Image.signed ]
+ [ -e arch/arm64/boot/Image.signed ]
+ rm -f arch/arm64/boot/Image.signed
+ exit 1
error: Bad exit status from /var/tmp/rpm-tmp.2u96Jp (%build)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.2u96Jp (%build)

Inspecting where the construct [ ! -s -o arch/arm64/boot/Image.signed ] comes
from points to /etc/rpm/macros.pesign and this snippet of the macro's code:

  if [ ! -s %{-o} ]; then \
    if [ -e "%{-o*}" ]; then \
      rm -f %{-o*} \
    fi \
    exit 1 \
  fi ;

Perhaps the author wanted to verify there is a non-zero length output file.
Otherwise remove it if it exists with zero length and fail. Unfortunately
%{-o} expands to the full flag not only the value. That is it produced
[ ! -s -o arch/arm64/boot/Image.signed ] that is wrong and moreover behaves
differently in bash and ksh:

[builder@g0 ~]$ echo "xxxx" > /tmp/a
[builder@g0 ~]$ [ ! -s -o /tmp/a ] ; echo $?
1
[builder@g0 ~]$ ksh
$ [ ! -s -o /tmp/a ] ; echo $?
0

The correction is to use "%{-o*}".

Comment 4 RHEL Program Management 2021-02-15 07:38:50 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.