Bug 1115483 - RFE: Allow change of personality in rpm-python
Summary: RFE: Allow change of personality in rpm-python
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: rpm
Version: rawhide
Hardware: Unspecified
OS: Unspecified
medium
low
Target Milestone: ---
Assignee: Packaging Maintenance Team
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1111147
TreeView+ depends on / blocked
 
Reported: 2014-07-02 12:47 UTC by Miroslav Suchý
Modified: 2015-03-28 09:53 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-03-28 09:53:46 UTC


Attachments (Terms of Use)

Description Miroslav Suchý 2014-07-02 12:47:34 UTC
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 13:33:00 UTC
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 12:49:14 UTC
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 12:50:18 UTC
Oops, forgot to link the fix: http://rpm.org/gitweb?p=rpm.git;a=commitdiff;h=4ff89adb0dcabd86afc0230c4e8ef98c5f7cdc65

Comment 4 Florian Festi 2015-03-28 09:53:46 UTC
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.