use registered qemu emulator filename if already registered. 98/129398/4
authorDohyung Kim <dohyung2.kim@samsung.com>
Mon, 5 Jun 2017 05:49:23 +0000 (14:49 +0900)
committerDohyung Kim <dohyung2.kim@samsung.com>
Mon, 30 Oct 2017 07:58:38 +0000 (16:58 +0900)
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 <dohyung2.kim@samsung.com>
mic/chroot.py
mic/imager/baseimager.py
mic/utils/misc.py

index 85e8ba0f2e01b1323c2fa76802129b9ebf5ceada..a8a41db2d8a3f6f6f8a5c31b9ee3c68bf7524116 100644 (file)
@@ -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)
index e63d1edc313087879272fdde95f010d479e93879..9d61663da5a283037b5d1e54a48b77fe8629cc91 100755 (executable)
@@ -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
 
index 873ebbef1ffcec5631dde5b088483df167d35fdd..5aa5b160685ebfd65b0b8944c568d3e13db81dab 100755 (executable)
@@ -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):