From: Gui Chen Date: Tue, 21 Aug 2012 06:28:04 +0000 (+0800) Subject: clean mounts in bootstrap.cleanup X-Git-Tag: 0.15~64^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eb54d225ee27e0e8003cdc7909a70f23d37addf1;p=tools%2Fmic.git clean mounts in bootstrap.cleanup Signed-off-by: Gui Chen --- diff --git a/mic/bootstrap.py b/mic/bootstrap.py index 8679be1..2916870 100644 --- a/mic/bootstrap.py +++ b/mic/bootstrap.py @@ -25,7 +25,7 @@ import rpm from mic import msger from mic.utils import errors, proxy, misc from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback -from mic.chroot import setup_chrootenv, cleanup_chrootenv +from mic.chroot import cleanup_mounts, setup_chrootenv, cleanup_chrootenv RPMTRANS_FLAGS = [rpm.RPMTRANS_FLAG_ALLFILES, rpm.RPMTRANS_FLAG_NOSCRIPTS, @@ -206,6 +206,8 @@ class Bootstrap(object): def cleanup(self): try: + # clean mounts + cleanup_mounts(self.rootdir) # remove rootdir shutil.rmtree(self.rootdir, ignore_errors=True) except: diff --git a/mic/chroot.py b/mic/chroot.py index 12ffa2f..f4f5942 100644 --- a/mic/chroot.py +++ b/mic/chroot.py @@ -81,27 +81,20 @@ def check_bind_mounts(chrootdir, bindmounts): def cleanup_mounts(chrootdir): umountcmd = misc.find_binary_path("umount") - for point in BIND_MOUNTS: - args = [ umountcmd, "-l", chrootdir + point ] - runner.quiet(args) - point = '/parentroot' - args = [ umountcmd, "-l", chrootdir + point ] - runner.quiet(args) - abs_chrootdir = os.path.abspath(chrootdir) - with open('/proc/mounts') as f: - for line in f: - if abs_chrootdir in line: - point = line.split()[1] + mounts = open('/proc/mounts').readlines() + for line in reversed(mounts): + if abs_chrootdir not in line: + continue - if abs_chrootdir == point: - continue + point = line.split()[1] - args = [ umountcmd, "-l", point ] - ret = runner.quiet(args) - if ret != 0: - msger.warning("failed to unmount %s" % point) - return ret + # '/' to avoid common name prefix + if abs_chrootdir == point or point.startswith(abs_chrootdir + '/'): + args = [ umountcmd, "-l", point ] + ret = runner.quiet(args) + if ret != 0: + msger.warning("failed to unmount %s" % point) return 0