This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 1115483 - RFE: Allow change of personality in rpm-python
RFE: Allow change of personality in rpm-python
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: rpm (Show other bugs)
rawhide
Unspecified Unspecified
medium Severity low
: ---
: ---
Assigned To: packaging-team-maint
Fedora Extras Quality Assurance
: Upstream
Depends On:
Blocks: 1111147
  Show dependency treegraph
 
Reported: 2014-07-02 08:47 EDT by Miroslav Suchý
Modified: 2015-03-28 05:53 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-03-28 05:53:46 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Miroslav Suchý 2014-07-02 08:47:34 EDT
Description of problem:
In 'mock' we change personality of system when we are building i686 package on x86_64 host. But bpersonality is set by 'rpm-python' only once when module is loaded. And can not be changed later. So we must workaround it by lazy import of rpm module.

It would be nice if you can provide some function, which would re-read personality and re-inicialize it.


How reproducible:
Create evil.spec with:
BuildArch i686

And try:
#!/usr/bin/python
import ctypes
# taken from sys/personality.h
PER_LINUX32=0x0008
PER_LINUX=0x0000
personality_defs = {
    'x86_64': PER_LINUX, 'ppc64': PER_LINUX, 'sparc64': PER_LINUX,
    'i386': PER_LINUX32, 'i586': PER_LINUX32, 'i686': PER_LINUX32,
    'ppc': PER_LINUX32, 'sparc': PER_LINUX32, 'sparcv9': PER_LINUX32,
    'ia64' : PER_LINUX, 'alpha' : PER_LINUX,
    's390' : PER_LINUX32, 's390x' : PER_LINUX,
}
_libc = ctypes.cdll.LoadLibrary(None)

#SWAP
_libc.personality(personality_defs['i686'])
import rpm

ts = rpm.ts()
ts.parseSpec('evil.spec')


This will work.
But if you swap those two lines after #SWAP, then if will not work and fail with:

error: No compatible architectures found for build
Traceback (most recent call last):
  File "/tmp/test", line 22, in <module>
    ts.parseSpec('evil.spec') 
  File "/usr/lib64/python2.7/site-packages/rpm/transaction.py", line 41, in parseSpec
    return _rpmb.spec(specfile)
ValueError: can't parse specfile
Comment 1 Panu Matilainen 2014-07-02 09:33:00 EDT
Hmm, I was about to say "just call rpm.reloadConfig()" but that wont work, apparently it doesn't reset *all* the internal hw detection state foobar. Which means its not doing its work properly... I'll have a look.
Comment 2 Panu Matilainen 2014-10-01 08:49:14 EDT
Fixed upstream in the sense that rpm.reloadConfig() does a full reconfigure, previously the default machine data was only calculated on the very first call to rpmReadConfigFiles() which in python case occurs at module import.

You'll still need a manual rpm.reloadConfig() when messing with personalities though, so whether the "official fix" is any better than your workaround ... depends I guess.
Comment 3 Panu Matilainen 2014-10-01 08:50:18 EDT
Oops, forgot to link the fix: http://rpm.org/gitweb?p=rpm.git;a=commitdiff;h=4ff89adb0dcabd86afc0230c4e8ef98c5f7cdc65
Comment 4 Florian Festi 2015-03-28 05:53:46 EDT
Closing. Please reopen if you need this to go into an update.

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