RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1134681 - Defined macro gets unset when using systemd macros
Summary: Defined macro gets unset when using systemd macros
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: rpm
Version: 7.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Panu Matilainen
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-08-28 05:31 UTC by Michael Stahnke
Modified: 2014-08-29 04:35 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-08-29 04:35:14 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Michael Stahnke 2014-08-28 05:31:52 UTC
Description of problem:

Somehow the usage of %systemd_postun changes the rest of spec file and prevents it from using the %if statement in the %files section. This makes no sense. It *looks* like somehow the usage of any systemd macro is unsetting %xml. 


Version-Release number of selected component (if applicable):

RHEL7 

RPM version 4.11.1
How reproducible:

Always



I have an odd rpm building issue. I ran into this on a much larger spec file, but for simplicity I have reduced it the minimum amount of spec file required to reproduce the bug. I am well aware that if this spec file would build a SRPM, that SRPM would FTBFS. I also know parts of this spec violate Fedora packaging guidelines. Again, this is just an example.

I removed all BR, Requires, %changelog, %prep, patches etc. 


Given the following spec file: 

===
%{!?xml:%define xml 1}

Summary:        An example of a bug
Name:           example
Version:        9.2.7
Release:        11
License:        MIT
Group:          Applications/Databases
Url:            http://www.example.org
# This is a dummy source, just touch example.tar.gz in ~/rpmbuild/SOURCES
Source0:        example.tar.gz

%description
I removed lots of normal stuff just to show this as a bug.

%install
rm -rf %{buildroot}

%postun
%systemd_postun %{name}.service

%files
%defattr(-,root,root)
%if %xml
/opt/lib/example/example.so
%endif
===

This is on EL7.

The goal here is build a SRPM I can build using mock.

I would normally run 

rpmbuild -bs --nodeps example.spec 

to do this.

-bash-4.2$ rpmbuild -bs --nodeps example.spec
error: parse error in expression
error: /home/stahnma/rpmbuild/SPECS/example.spec:24: bad %if condition


If I move %post under the %files section, the SRPM builds.

If I comment out the %systemd_postun line (including commenting out the macro), the SRPM builds. 

If I change the if %xml to if 0%{xml} < 1, the SRPM builds.

If I manually expand the %systemd_postun macro, and literally put that text in the %post stanza, the SRPM builds. 

-bash-4.2$ rpm --eval "%systemd_postun example.service"

/usr/bin/systemctl daemon-reload >/dev/null 2>&1 || :


Somehow the usage of %systemd_postun changes the rest of spec file and prevents it from using the %if statement in the %files section. This makes no sense. It *looks* like somehow the usage of any systemd macro is unsetting %xml. 

Just for fun, I tried other systemd macros. The same failure occurs when using systemd_post, systemd_postun_with_restart, systemd_preun
Also, if I change the %postun stanza to %post, or %pre it also still happens. 

I also, just for fun, renamed %xml to %foo. The exact same behavior occurs.


I can work around this bug using one of the many methods described above, I am just not sure where the bug is. It could be in rpmbuild, it could be in systemd macros.

Comment 2 Panu Matilainen 2014-08-28 06:07:32 UTC
The problem is this line in your spec:

%{!?xml:%define xml 1}

By rpm's macro scoping rules, the xml macro is only defined within the surrounding braces. What makes it confusing is that macros fallen out of scope are not "garbage collected" at the ending brace but ranging from "at process exit" to "next parametrized macro use", systemd macros are of the latter kind.

Change your define to %global and the issue will go away as %global macros are obviously global and wont fall out of scope.

Closing this as NOTABUG, as the actual problem is in the spec. Obviously rpm isn't exactly being helpful but fixing that requires lots of upstream work first, and the changes are not going to be backportable to rhel 7.

Comment 3 Michael Stahnke 2014-08-28 18:14:57 UTC
How is this not a bug if changing a completely different line in the spec file changes the behavior of rpm? Having stuff fly in and out of scope is a bug. All you've done is provide another work-around (which, as I stated, I have several). The root cause here is that RPM is broken.

Comment 4 Panu Matilainen 2014-08-29 04:35:14 UTC
Perhaps you haven't realized but macros are scoped, much like variables in a "normal" programming language. That these scopes aren't enforced is a bug of in the macro "language" certainly, the reason for closing as NOTABUG was that 
enforcing the scoping would not make that "%{!?xml:%define xml 1}" to work, you'd still need to use %global.

WONTFIX if that suites you better, the bottom line is that encoforcing the macro scopes is not fixable in rhel-7.


Note You need to log in before you can comment on or make changes to this bug.