From 664b5dc0f725e7f03b8a64d5c468349306c5d1fe Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Mon, 18 Nov 2013 21:25:32 -0500 Subject: [PATCH] internal setarch according to bootstrap environment when using 'uname -m' in bootstrap, it always shows the arch from the physical host. but what needs is the internal arch, so mic needs detect the binary arch first, then setarch properly Change-Id: I907f5442b11690dc624c7d3ae23c858804c802f0 Signed-off-by: Gui Chen --- mic/rt_util.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/mic/rt_util.py b/mic/rt_util.py index 33b8ccc..c5a0c5c 100644 --- a/mic/rt_util.py +++ b/mic/rt_util.py @@ -22,15 +22,42 @@ import glob import re import shutil import subprocess +import ctypes from mic import bootstrap, msger from mic.conf import configmgr from mic.utils import errors, proxy from mic.utils.fs_related import find_binary_path, makedirs -from mic.chroot import setup_chrootenv, cleanup_chrootenv +from mic.chroot import setup_chrootenv, cleanup_chrootenv, ELF_arch + +_libc = ctypes.cdll.LoadLibrary(None) +_errno = ctypes.c_int.in_dll(_libc, "errno") +_libc.personality.argtypes = [ctypes.c_ulong] +_libc.personality.restype = ctypes.c_int +_libc.unshare.argtypes = [ctypes.c_int,] +_libc.unshare.restype = ctypes.c_int expath = lambda p: os.path.abspath(os.path.expanduser(p)) +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, +} + +def condPersonality(per=None): + if per is None or per in ('noarch',): + return + if personality_defs.get(per, None) is None: + return + res = _libc.personality(personality_defs[per]) + if res == -1: + raise OSError(_errno.value, os.strerror(_errno.value)) + def inbootstrap(): if os.path.exists(os.path.join("/", ".chroot.lock")): return True @@ -84,6 +111,9 @@ def bootstrap_mic(argv=None): safecopy(configmgr._ksconf, rootdir) msger.info("Start mic in bootstrap: %s\n" % rootdir) + bsarch = ELF_arch(rootdir) + if bsarch in personality_defs: + condPersonality(bsarch) bindmounts = get_bindmounts(cropts) ret = bsenv.run(argv, cwd, rootdir, bindmounts) -- 2.7.4