From: Dohyung Kim Date: Mon, 5 Jun 2017 05:49:23 +0000 (+0900) Subject: use registered qemu emulator filename if already registered. X-Git-Tag: accepted/tizen/devbase/tools/20200415.093504~45 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76593d38d8fe75e62100453777c9a9c87b63211b;p=tools%2Fmic.git use registered qemu emulator filename if already registered. 1. preserve-argv[0] flag is enabled copy both qemu-XXX and qemu-XXX-binfmt and use them. 2. flag is disabled and the copied qemu and the registered qemu are different create symlink as the registered qemu emulator filename and use symlink Change-Id: I3f9050a01cc3bd0431b37a2c1e29729ef15ee765 Signed-off-by: Dohyung Kim --- diff --git a/mic/chroot.py b/mic/chroot.py index 85e8ba0..a8a41db 100644 --- a/mic/chroot.py +++ b/mic/chroot.py @@ -304,11 +304,11 @@ def chroot(chrootdir, bindmounts = None, execute = "/bin/bash"): arch = ELF_arch(chrootdir) if arch == "arm": - qemu_emulator = misc.setup_qemu_emulator(chrootdir, "arm") + qemu_emulators = misc.setup_qemu_emulator(chrootdir, "arm") elif arch == "mipsel": - qemu_emulator = misc.setup_qemu_emulator(chrootdir, "mipsel") + qemu_emulators = misc.setup_qemu_emulator(chrootdir, "mipsel") else: - qemu_emulator = None + qemu_emulators = [] savefs_before_chroot(chrootdir, None) @@ -326,5 +326,5 @@ def chroot(chrootdir, bindmounts = None, execute = "/bin/bash"): finally: cleanup_chrootenv(chrootdir, bindmounts, globalmounts) - if qemu_emulator: + for qemu_emulator in qemu_emulators: os.unlink(chrootdir + qemu_emulator) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index e63d1ed..9d61663 100755 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -145,8 +145,8 @@ class BaseImageCreator(object): self.image_format = None - # Save qemu emulator file name in order to clean up it finally - self.qemu_emulator = None + # Save qemu emulator file names in order to clean up it finally + self.qemu_emulators = [] # No ks provided when called by convertor, so skip the dependency check if self.ks: @@ -825,7 +825,7 @@ class BaseImageCreator(object): if self.target_arch and self.target_arch.startswith("arm") or \ self.target_arch == "aarch64": - self.qemu_emulator = misc.setup_qemu_emulator(self._instroot, + self.qemu_emulators = misc.setup_qemu_emulator(self._instroot, self.target_arch) self.get_cachedir(cachedir) @@ -866,8 +866,8 @@ class BaseImageCreator(object): if not os.path.islink(mtab): os.unlink(self._instroot + "/etc/mtab") - if self.qemu_emulator: - os.unlink(self._instroot + self.qemu_emulator) + for qemu_emulator in self.qemu_emulators: + os.unlink(self._instroot + qemu_emulator) except OSError: pass diff --git a/mic/utils/misc.py b/mic/utils/misc.py index 873ebbe..5aa5b16 100755 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -898,6 +898,7 @@ def is_statically_linked(binary): return ", statically linked, " in runner.outs(['file', binary]) def setup_qemu_emulator(rootdir, arch): + qemu_emulators = [] # mount binfmt_misc if it doesn't exist if not os.path.exists("/proc/sys/fs/binfmt_misc"): modprobecmd = find_binary_path("modprobe") @@ -940,6 +941,7 @@ def setup_qemu_emulator(rootdir, arch): if not os.path.exists(rootdir + "/usr/bin"): makedirs(rootdir + "/usr/bin") shutil.copy(qemu_emulator, rootdir + qemu_emulator) + qemu_emulators.append(qemu_emulator) # disable selinux, selinux will block qemu emulator to run if os.path.exists("/usr/sbin/setenforce"): @@ -957,8 +959,26 @@ def setup_qemu_emulator(rootdir, arch): with open("/proc/sys/fs/binfmt_misc/register", "w") as fd: fd.write(qemu_arm_string) - - return qemu_emulator + else: + flags = "" + interpreter = "" + with open(node, "r") as fd: + for line in fd.readlines(): + if line.startswith("flags:"): + flags = line[len("flags:"):].strip() + elif line.startswith("interpreter"): + interpreter = line[len("interpreter"):].strip() + + if flags == "P" and interpreter.endswith("-binfmt"): + # copy binfmt wrapper when preserve-argv[0] flag is enabled + shutil.copy(os.path.realpath(interpreter), rootdir + interpreter) + qemu_emulators.append(interpreter) + elif not flags and interpreter != qemu_emulator: + # create symlink as registered qemu emulator + os.symlink(qemu_emulator, rootdir + interpreter) + qemu_emulators.append(interpreter) + + return qemu_emulators def SrcpkgsDownload(pkgs, repometadata, instroot, cachedir): def get_source_repometadata(repometadata):